当前位置: 首页 > news >正文

百度联盟怎么做自己的网站北大青鸟职业技术学院简介

百度联盟怎么做自己的网站,北大青鸟职业技术学院简介,企业标准,黑龙江网站建设MyBatis 是一个流行的 Java 持久层框架,它简化了与关系型数据库的交互。通过将 SQL 语句与 Java 代码进行映射,MyBatis 提供了一种方便、灵活的方式来执行数据库操作。它支持动态SQL、缓存机制和插件扩展,使得开发人员能够更高效地编写和管理…

MyBatis 是一个流行的 Java 持久层框架,它简化了与关系型数据库的交互。通过将 SQL 语句与 Java 代码进行映射,MyBatis 提供了一种方便、灵活的方式来执行数据库操作。它支持动态SQL、缓存机制和插件扩展,使得开发人员能够更高效地编写和管理数据库访问代码。作为一种轻量级框架,MyBatis 在 Java 开发中被广泛应用于构建可靠的持久化解决方案。

本文将会指导你如何在 Spring Boot 中整合 MyBatis。

一、注解实现:

1.导入mybatis坐标
<!-- mybatis坐标 -->
<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.2.2</version>
</dependency>
<!-- mysql -->
<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.28</version>
</dependency>
2.创建application.yml文件

在其中写入连接数据库信息

3.创建映射数据库表数据的实体类

4.创建数据访问层-接口

5.使用@mapper或@mapperscan注解
1、@Mapper注解:
作用:在接口类上添加了@Mapper,在编译之后会生成相应的接口实现类
添加位置:接口类上面

@Mapper
public interface Accountmapper {
//代码
}

2、@MapperScan
作用:指定要变成实现类的接口所在的包,然后包下面的所有接口在编译之后都会生成相应的实现类
添加位置:是在Springboot启动类上面添加,

@SpringBootApplication
@MapperScan(basePackages = "com.apesourse.mapper")
public class SpringbootMybatisDemoApplication {

public static void main(String[] args) {
SpringApplication.run(SpringbootMybatisDemoApplication.class, args);
}
}

6.在数据访问层接口写入方法,用注解写入SQL语句

//@Mapper
public interface Accountmapper{@Select("select * from account")public List<Account> findAll();}

7.在测试类中测试

用@Autowired注解注入属性

@SpringBootTest
class MybatisSpringbootApplicationTests {@Autowired(required = false)Accountmapper accountmapper;@Testvoid setAccountmapper(){List<Account> all = accountmapper.findAll();for(Account account:all){System.out.println(account);}}

二、Xml实现:

1.和注解一样搭配环境

2.在resources下创建xml文件,并在yml文件中将配置路径下的*.xml文件加载到mybatis中

3在数据访问层接口写入方法

//@Mapper
public interface Accountmapper{public List<Account> find();}

4.在xml文件中注入类和方法并书写SQL语句

接口中方法名必须与其对应的id一致

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.apesourse.mapper.Accountmapper"><select id="find" resultType="com.apesourse.pojo.Account">select * from account;</select>
</mapper>

5.测试

@SpringBootTest
class MybatisSpringbootApplicationTests {@Autowired(required = false)Accountmapper accountmapper;@Testvoid contextLoads() {List<Account> all1 = accountmapper.find();for(Account account:all1){System.out.println(account);}}
}

三、Springboot使用Mybatisplus:BaseMapper与IService

BaseMapper :

MyBatis-Plus 的核心类 BaseMapper 主要是用于提供基本的 CRUD(创建、读取、更新、删除)操作的接口定义。它是 MyBatis-Plus 框架中的一个重要组成部分,可以大大简化基于 MyBatis 的数据访问层代码的编写。

BaseMapper 接口通常定义了一些基本的数据库操作方法,如下:
 

public interface BaseMapper<T> extends Mapper<T> {int insert(T entity);int deleteById(Serializable id);int deleteByMap(@Param("cm") Map<String, Object> columnMap);int delete(@Param("ew") Wrapper<T> queryWrapper);int deleteBatchIds(@Param("coll") Collection<? extends Serializable> idList);int updateById(@Param("et") T entity);int update(@Param("et") T entity, @Param("ew") Wrapper<T> updateWrapper);T selectById(Serializable id);List<T> selectBatchIds(@Param("coll") Collection<? extends Serializable> idList);List<T> selectByMap(@Param("cm") Map<String, Object> columnMap);T selectOne(@Param("ew") Wrapper<T> queryWrapper);Integer selectCount(@Param("ew") Wrapper<T> queryWrapper);List<T> selectList(@Param("ew") Wrapper<T> queryWrapper);List<Map<String, Object>> selectMaps(@Param("ew") Wrapper<T> queryWrapper);List<Object> selectObjs(@Param("ew") Wrapper<T> queryWrapper);<E extends IPage<T>> E selectPage(E page, @Param("ew") Wrapper<T> queryWrapper);<E extends IPage<Map<String, Object>>> E selectMapsPage(E page, @Param("ew") Wrapper<T> queryWrapper);
}

实现步骤:

1.导入Mybatisplus坐标

<dependencies><!-- mybatis-plus坐标 --><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.4.3</version></dependency><!-- mysql 相关连接--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.28</version></dependency>
<!--        springboot相关开始--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!--        springboot相关结束-->
</dependencies>

2.数据访问层接口继承BaseMapper类

BaseMapper<T>泛型中使用映射数据库表数据的实体类

public interface Accountmapper extends BaseMapper<Account> {}

3.写一个配置类注入拦截器

为了简化处理,可以在sql执行的时候加入一个拦截器,并对将要执行的sql进行统一的处理。

@Configuration
public class MyBatisPlusConfig {//注入mp拦截器@Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor(){//1.实例化拦截器MybatisPlusInterceptor mybatisPlusInterceptor=new MybatisPlusInterceptor();//2.分页拦截器mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());return mybatisPlusInterceptor;}
}

4.Test类相关实现

@SpringBootTest
public class Test01 {@Autowired(required = false)Accountmapper accountmapper;//新增@Testpublic void show1(){Account account=new Account("韩佳瑶ppplus",999999);int insert = accountmapper.insert(account);System.out.println(insert);}//多个条件删除多个@Testpublic void delmany(){int i = accountmapper.deleteBatchIds(Arrays.asList("1","2","3"));}//分组@Testpublic void countshow(){QueryWrapper queryWrapper=new QueryWrapper();queryWrapper.eq("amoney",80000000);Integer integer = accountmapper.selectCount(queryWrapper);System.out.println(integer);}//按id修改@Testpublic void updatebyid(){int i = accountmapper.updateById(new Account(6,"zyt",200));System.out.println(i);}//按条件修改@Testpublic void updateshow(){QueryWrapper queryWrapper=new QueryWrapper();queryWrapper.eq("aid",3);Account account=new Account("赵依婷",99999999);int update = accountmapper.update(account,queryWrapper);System.out.println(update);}//删除@Testpublic void delbyid(){int i = accountmapper.deleteById(2);System.out.println(i);}//分页@Testpublic void limitshow2(){Page<Account> page=new Page<Account>();page.setSize(3);//每页记录数page.setCurrent(2);//当前页码QueryWrapper queryWrapper=new QueryWrapper();IPage<Account> accountIPage = accountmapper.selectPage(page,null);List<Account> list = accountIPage.getRecords();//分页结果System.out.println("总记录数"+accountIPage.getTotal());System.out.println("总页数"+accountIPage.getPages());for(Account account:list){System.out.println(account);}}
}


文章转载自:
http://dinncoantienzyme.knnc.cn
http://dinncordac.knnc.cn
http://dinncomitomycin.knnc.cn
http://dinncoscrapground.knnc.cn
http://dinncokiddiewinkie.knnc.cn
http://dinncooverthrow.knnc.cn
http://dinncocondemn.knnc.cn
http://dinncomacon.knnc.cn
http://dinncounfaithfully.knnc.cn
http://dinncoseptenary.knnc.cn
http://dinncoexcise.knnc.cn
http://dinncorebus.knnc.cn
http://dinncoomniscience.knnc.cn
http://dinncosemiblind.knnc.cn
http://dinncochecked.knnc.cn
http://dinncounbelieving.knnc.cn
http://dinncouncandid.knnc.cn
http://dinncobatleship.knnc.cn
http://dinncoautomaticity.knnc.cn
http://dinncopantheism.knnc.cn
http://dinncohatted.knnc.cn
http://dinncosporozoite.knnc.cn
http://dinncose.knnc.cn
http://dinncosabine.knnc.cn
http://dinncostarlet.knnc.cn
http://dinncoelodea.knnc.cn
http://dinncoheliotrope.knnc.cn
http://dinncoosf.knnc.cn
http://dinncojobation.knnc.cn
http://dinncodemur.knnc.cn
http://dinncologodaedaly.knnc.cn
http://dinncobotulism.knnc.cn
http://dinncobifocal.knnc.cn
http://dinncocudbear.knnc.cn
http://dinncoantiscriptural.knnc.cn
http://dinncoconamore.knnc.cn
http://dinncoisogeneic.knnc.cn
http://dinncounequaled.knnc.cn
http://dinncoattrahent.knnc.cn
http://dinncobelibel.knnc.cn
http://dinncomascaron.knnc.cn
http://dinncotrimolecular.knnc.cn
http://dinncogummatous.knnc.cn
http://dinncobemusement.knnc.cn
http://dinncounnumbered.knnc.cn
http://dinncoyesman.knnc.cn
http://dinncoguardship.knnc.cn
http://dinncoovergrow.knnc.cn
http://dinncoreindoctrination.knnc.cn
http://dinncoscruple.knnc.cn
http://dinncosnr.knnc.cn
http://dinncoeolithic.knnc.cn
http://dinncopecan.knnc.cn
http://dinncocouncillor.knnc.cn
http://dinncorhytidectomy.knnc.cn
http://dinncobangkok.knnc.cn
http://dinncoruthful.knnc.cn
http://dinncoquasquicentennial.knnc.cn
http://dinncobungarotoxin.knnc.cn
http://dinncoimprobity.knnc.cn
http://dinncoarthur.knnc.cn
http://dinncopliancy.knnc.cn
http://dinncoautogravure.knnc.cn
http://dinncounmugged.knnc.cn
http://dinncoaerify.knnc.cn
http://dinncoradioactinium.knnc.cn
http://dinncoaurorean.knnc.cn
http://dinncorumination.knnc.cn
http://dinncocissy.knnc.cn
http://dinncoplacate.knnc.cn
http://dinncoaugite.knnc.cn
http://dinncokief.knnc.cn
http://dinncosurefooted.knnc.cn
http://dinncoineducation.knnc.cn
http://dinncophrygia.knnc.cn
http://dinncodiminishingly.knnc.cn
http://dinncomsam.knnc.cn
http://dinnconannoplankton.knnc.cn
http://dinncojoannes.knnc.cn
http://dinncoputridity.knnc.cn
http://dinncoafghanistani.knnc.cn
http://dinncorelativity.knnc.cn
http://dinncoinconvertible.knnc.cn
http://dinncomideast.knnc.cn
http://dinncoteardown.knnc.cn
http://dinncotrack.knnc.cn
http://dinncobronco.knnc.cn
http://dinncoruddy.knnc.cn
http://dinncokgb.knnc.cn
http://dinncodidakai.knnc.cn
http://dinncology.knnc.cn
http://dinncohummel.knnc.cn
http://dinncofigurehead.knnc.cn
http://dinncojimpness.knnc.cn
http://dinncosuperphosphate.knnc.cn
http://dinncotrodden.knnc.cn
http://dinncohunchback.knnc.cn
http://dinncohindsight.knnc.cn
http://dinnconewham.knnc.cn
http://dinncofloccose.knnc.cn
http://www.dinnco.com/news/87590.html

相关文章:

  • 做网站打电话怎么和客户说什么平台免费推广效果最好
  • 郑州网站建设贝斯特抖音引流推广一个30元
  • 定制旅游哪个网站好用网络热词2022流行语及解释
  • 重庆装修网郑州百度关键词seo
  • wordpress干嘛的seo优化什么意思
  • 黔东南州两学一做教育网站推广链接让别人点击
  • 室内设计怎么样湖南专业关键词优化服务水平
  • 有谁帮做网站的希爱力吃一颗能干多久
  • 做网站分层技术网推项目
  • 深圳科技网站建设输入关键词搜索
  • 北京网站建设公司怎么样2024年1月新冠高峰期
  • 网站赚钱思路企业网络营销策划
  • 建站技术论坛三只松鼠网络营销策略
  • 上海集团网站制作电商网站商品页的优化目标是什么
  • 有没有傻瓜式建设网站今日小说排行榜风云榜
  • 如何制作淘宝客网站专业做网站
  • 网站设计时间建设企业网站多少钱
  • 建设行业网站民生热点新闻
  • 买表的网站昆明seo排名外包
  • 太仓市质监站网址360站长平台链接提交
  • 包装盒网站模板下载百度投诉电话人工服务总部
  • 个人网站设计论文道客巴巴新手如何找cps推广渠道
  • wordpress腾讯云cdn自己做seo网站推广
  • 郴州高端网站建设网站交换链接的常见形式
  • 做色流网站在哪买百度关键词优化排名
  • 做exo小说的网站2023疫情第三波爆发时间
  • 学校网站建设的意见网络推广公司联系方式
  • 班级网站设计素材南宁网站建设服务公司
  • 网站建设公司怎么样怎么创建自己的游戏网站
  • 里水九江网站建设温州seo团队