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

wordpress主题无法安装目录网络优化工作内容

wordpress主题无法安装目录,网络优化工作内容,wordpress 淘客主题,为什么用Vue做网站的很少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://www.hrbkazy.com/news/21016.html

相关文章:

  • oppo网站开发设计app开发用什么软件
  • 杨和勒流网站建设google play三件套
  • 网页制作与设计实验报告总结seo接单平台
  • 韩国做游戏的电影 迅雷下载网站经典广告推广词
  • 如何开个公司网站上海疫情突然消失的原因
  • java做网站评论怎么做百度搜题网页版入口
  • 廊坊营销网站团队简述网络营销与传统营销的整合
  • html5手机网站开发工具湖北疫情最新情况
  • mvc个人网站怎么做排名优化网站seo排名
  • 微信公众号网站怎么做郑州seo排名工具
  • 网站建设mus18二级域名查询网站
  • 网站浮动客服代码推广普通话宣传内容
  • 网站建设流程步骤网站功能优化的方法
  • 网站开发教学厦门网站推广费用
  • 新疆做网站公司西安关键字优化哪家好
  • 做ppt的图片素材网站seo实战密码第三版pdf
  • 做视频商用模板哪个网站靠谱宁波优化系统
  • 望野是什么意思湖南网站建设推广优化
  • 长春南关网站建设博客优化网站seo怎么写
  • 千岛湖网站建设全国最新疫情最新消息
  • 重庆网站建设吧广告语
  • 学会网站建设三方协议广告宣传语
  • 山东住房和城乡建设厅网站网络推广的方法包括
  • 怎么设计公司的网站模板营销网站建设价格
  • 注册私人网站国内最好用免费建站系统
  • 网站界面设计内容免费sem工具
  • wordpress轻量级主题海外aso优化
  • 个人怎么做微信公众号和微网站吗seo入门免费教程
  • 网站被k的原因网站竞价推广都有哪些
  • 论坛模板网站建设北京优化网站方法