MyBatis

MyBatis mybatis-generator配置

MyBatis mybatis-generator配置

数据库连接配置 generator.properties generator.jdbc.driver=com.mysql.jdbc.Driver generator.jdbc.url=jdbc\:mysql\://192.168.161.11\:3306/appblog?useUnicode\=t

Joe.Ye Joe.Ye 2023-04-01
0 0 0
MyBatis mybatis-generator插件安装配置

MyBatis mybatis-generator插件安装配置

插件位置:Maven Projects窗口 -> dao项目 -> Plugins -> mybatis-generator -> mybatis-generator:generate 注:切勿重复执行mybatis-generator:generate,否则生成的Map

Joe.Ye Joe.Ye 2023-04-01
0 0 0
Spring Boot集成MySql、MyBatis和PageHelper插件

Spring Boot集成MySql、MyBatis和PageHelper插件

配置文件 在配置文件application.yml中配置MySql数据库连接池和Mybatis扫描包以及PageHelper分页插件 server: port: 8080 servlet: context-path: / spring: # mvc: # view: #

Joe.Ye Joe.Ye 2023-04-01
0 0 1
MySQL传参字段与DB字段数据类型不一致导致精度问题采坑记录

MySQL传参字段与DB字段数据类型不一致导致精度问题采坑记录

假设t_user表中,user_id字段的数据类型为varchar MySQL传参字段与DB字段数据类型不一致 select * from t_user where merchant_id = 10086; //可能会查出多条数据 select * from t_user where merch

Joe.Ye Joe.Ye 2023-04-01
0 0 0
MyBatis动态传入表名,字段名参数的解决办法–用于分表–表名是动态的

MyBatis动态传入表名,字段名参数的解决办法–用于分表–表名是动态的

背景描述 一直在使用MyBatis这个ORM框架,都是使用MyBatis里的一些常用功能。今天在项目开发中有个业务是需要限制各个用户对某些表里的字段查询以及某些字段是否显示,如某张表的某些字段不让用户查询到。这种情况下,就需要构建sql来动态传入表名、字段名了。现在对解决方法进行下总结,希望对遇到同

Joe.Ye Joe.Ye 2023-04-01
0 0 0
MyBatis 报错 No bean named org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry

MyBatis 报错 No bean named org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry

Spring Boot集成MyBatis报错:No bean named org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry 详细错误 Caused by: org.spring

Joe.Ye Joe.Ye 2023-04-01
0 0 0
MyBatis批量插入、批量更新、批量删除、批量查询

MyBatis批量插入、批量更新、批量删除、批量查询

批量插入 WaterEleMapper部分代码 int insertList(List<WaterEle> list); WaterEleMapper.xml部分代码 <!--批量增加测试--> <insert id="insertList" pa

Joe.Ye Joe.Ye 2023-04-01
0 0 0
无需mapper.xml,MyBatis新特性动态SQL

无需mapper.xml,MyBatis新特性动态SQL

当我们使用MyBatis的时候,需要在mapper.xml中书写大量的SQL语句。当我们使用MyBatis Generator(MBG)作为代码生成器时,也会生成大量的mapper.xml文件。其实从MBG 1.3.6版本以后,MyBatis官方已经推荐使用Dynamic SQL,使用这一新特性基本

Joe.Ye Joe.Ye 2023-03-25
0 0 0
MyBatis generator自定义插件或者扩展报Cannot instantiate object of type XXX

MyBatis generator自定义插件或者扩展报Cannot instantiate object of type XXX

错误说明 Mybatis generator确实好用,但是离我们的生产代码还是有差别的。比如缺少toString hashCode equals等方法,或者自定义的一些注释,作者信息等。 官方文档也说可以自定义插件,但是当我们继承或者实现mybatis-generator的类或者接口时,运行报错:

Joe.Ye Joe.Ye 2023-03-25
0 0 0
MyBatis mybatis-generator自定义plugin

MyBatis mybatis-generator自定义plugin

字段添加注释 generatorConfig.xml添加自定义plugin示例 <!-- 生成的代码去掉注释 --> <commentGenerator type="com.lianpay.globalpay.remit.common.plugin.CommentGen

Joe.Ye Joe.Ye 2023-03-11
0 0 0
MyBatis根据List批量更新及删除记录

MyBatis根据List批量更新及删除记录

查询 //根据多个设备id获取设备信息 public List<Devices> getDevicesList(@Param("devicesIds") String[] devicesIds); <select id="getDevicesList

Joe.Ye Joe.Ye 2023-03-11
0 0 0
MyBatis中插入记录后获取该条记录ID

MyBatis中插入记录后获取该条记录ID

主键生成有两种方式: 主键自增长,需要得到插入成功后数据库生成的id 自定义主键,主要用于分布式开发,一般是现在java代码中生成id,然后存入数据库 MyBatis中主键回填的两种实现方式: (1)推荐方式 <insert id="insert" useGenera

Joe.Ye Joe.Ye 2023-03-11
0 0 0
Spring Boot中MyBatis打印sql

Spring Boot中MyBatis打印sql

如果使用的是application.properties文件,加入如下配置: logging.level.cn.appblog.demo=debug logging.level.*后面的路径指的是Mybatis对应的方法接口所在的包,并不是mapper.xml所在的包。 如果使用的是applica

Joe.Ye Joe.Ye 2023-03-11
0 0 0
MyBatis之java.lang.UnsupportedOperationException异常解决方案

MyBatis之java.lang.UnsupportedOperationException异常解决方案

今天在使用MyBatis执行sql语句时,出现如下异常: 执行的sql语句配置信息如下: <select id="getColumnsByTableName" parameterType="String" resultType="java.ut

Joe.Ye Joe.Ye 2023-03-11
0 0 0
MyBatis根据List批量查询List结果

MyBatis根据List批量查询List结果

基本使用 (1) Mapper接口 /** * 根据用户id list批量查询用户 */ public List<User> selectByIds(@Param("userIds") List<Long> userIds); (2) mapper.

Joe.Ye Joe.Ye 2023-03-11
0 0 0
1 2