巅峰对决:那晚在诊室,护士的那声“轻点”成了我男人的勋章

核心内容摘要

7C7DCCA:科技浪潮中的璀璨新星,赋能未来无限可能
踏寻神明的足迹:八重神子踝间风韵的绝美解析

解锁视觉盛宴:麻豆漫画,你的专属二次元心动指南

SpringBoot3 MybatisPlus 修改前言修改 APIupdate 条件update 对象条件updateByIdupdateById 批量(默认)updateById 批量(自定义)前言本篇中使用到的项目工程是在《SpringBoot3 MybatisPlus 加入日志功能》基础上持续功能开发。

修改 APIupdate 条件无实体参数的 update(Wrapper updateWrapper) 方法这个方法是默认方法底层直接调用 update(null, updateWrapper)核心特点是所有更新字段和 where 条件都通过 Wrapper 统一配置无需传入实体同时要注意它不支持字段自动填充比如创建时间、更新时间的自动赋值。

官网 API/** * 根据 Wrapper 更新记录 * p此方法无法进行自动填充,如需自动填充请使用{link #update(Object, Wrapper)}/p * * param updateWrapper {link UpdateWrapper} or {link LambdaUpdateWrapper} * since

3.

4 */defaultintupdate(Param(Constants.WRAPPER)WrapperTupdateWrapper){returnupdate(null,updateWrapper);}Demo 示例TestpublicvoidtestUpdate_02(){ClientEntityclientEntityclientMapper.selectById(301L);System.out.println(修改之前JSON.toJSONString(clientEntity));UpdateWrapperClientEntityupdateWrappernewUpdateWrapper();updateWrapper.lambda().eq(ClientEntity::getId,301L).set(ClientEntity::getNickName,无实体更新-昵称-测试);intupdateclientMapper.update(updateWrapper);System.out.println(--- update update);clientEntityclientMapper.selectById(301L);System.out.println(修改之后clientEntity JSON.toJSONString(clientEntity));}输出日志

T22:37:

3

00908:00INFO15368---[springboot3-mybatisplus][main]com.zaxxer.hikari.HikariDataSource:HikariPool-1-Startcompleted.JDBCConnection[HikariProxyConnection187931144wrappingcom.mysql.cj.jdbc.ConnectionImpla1cb94]will not be managed bySpringPreparing:SELECTid,client_id,user_no,user_password,nick_name,real_name,created_time,upated_time FROM clientWHEREid?Parameters:301(Long)Columns:id,client_id,user_no,user_password,nick_name,real_name,created_time,upated_timeRow:301,301,null,null,更新后-昵称_测试,null,

:07:21,

:07:21Total:1Closingnon transactionalSqlSession[org.apache.ibatis.session.defaults.DefaultSqlSession2487e20]修改之前{clientId:301,createdTime:

22:07:21,id:301,nickName:更新后-昵称_测试,upatedTime:

22:07:21}CreatinganewSqlSessionSqlSession[org.apache.ibatis.session.defaults.DefaultSqlSession3395c2a7]was not registeredforsynchronization because synchronization is not active JDBCConnection[HikariProxyConnection1561688223wrappingcom.mysql.cj.jdbc.ConnectionImpla1cb94]will not be managed bySpringPreparing:UPDATE clientSETnick_name?WHERE(id?)Parameters:无实体更新-昵称-测试(String),301(Long)Updates:1Closingnon transactionalSqlSession[org.apache.ibatis.session.defaults.DefaultSqlSession3395c2a7]---update1CreatinganewSqlSessionSqlSession[org.apache.ibatis.session.defaults.DefaultSqlSession4ebed2b3]was not registeredforsynchronization because synchronization is not active JDBCConnection[HikariProxyConnection285646508wrappingcom.mysql.cj.jdbc.ConnectionImpla1cb94]will not be managed bySpringPreparing:SELECTid,client_id,user_no,user_password,nick_name,real_name,created_time,upated_time FROM clientWHEREid?Parameters:301(Long)Columns:id,client_id,user_no,user_password,nick_name,real_name,created_time,upated_timeRow:301,301,null,null,无实体更新-昵称-测试,null,

:07:21,

:07:21Total:1Closingnon transactionalSqlSession[org.apache.ibatis.session.defaults.DefaultSqlSession4ebed2b3]修改之后clientEntity{clientId:301,createdTime:

22:07:21,id:301,nickName:无实体更新-昵称-测试,upatedTime:

22:07:21}update 对象条件官网 API/** * 根据 whereEntity 条件更新记录 * * param entity 实体对象 (set 条件值,可以为 null,当entity为null时,无法进行自动填充) * param updateWrapper 实体对象封装操作类可以为 null,里面的 entity 用于生成 where 语句 */intupdate(Param(Constants.ENTITY)Tentity,Param(Constants.WRAPPER)WrapperTupdateWrapper);Demo 示例TestpublicvoidtestUpdate(){ClientEntityclientEntitynewClientEntity();clientEntity.setNickName(更新后-昵称_测试);UpdateWrapperClientEntityupdateWrappernewUpdateWrapper();updateWrapper.eq(id,301L);intupdateclientMapper.update(clientEntity,updateWrapper);System.out.println(update update);// 进行查询验证.clientEntityclientMapper.selectById(301L);System.out.println(clientEntity JSON.toJSONString(clientEntity));}输出日志

T22:27:

4

81508:00INFO17412---[springboot3-mybatisplus][main]com.zaxxer.hikari.HikariDataSource:HikariPool-1-Startcompleted.JDBCConnection[HikariProxyConnection1376533963wrappingcom.mysql.cj.jdbc.ConnectionImpl7791ff50]will not be managed bySpringPreparing:UPDATE clientSETnick_name?WHERE(id?)Parameters:更新后-昵称_测试(String),301(Long)Updates:1Closingnon transactionalSqlSession[org.apache.ibatis.session.defaults.DefaultSqlSession3a70575]update1CreatinganewSqlSessionSqlSession[org.apache.ibatis.session.defaults.DefaultSqlSession5d74507c]was not registeredforsynchronization because synchronization is not active JDBCConnection[HikariProxyConnection800040885wrappingcom.mysql.cj.jdbc.ConnectionImpl7791ff50]will not be managed bySpringPreparing:SELECTid,client_id,user_no,user_password,nick_name,real_name,created_time,upated_time FROM clientWHEREid?Parameters:301(Long)Columns:id,client_id,user_no,user_password,nick_name,real_name,created_time,upated_timeRow:301,301,null,null,更新后-昵称_测试,null,

:07:21,

:07:21Total:1Closingnon transactionalSqlSession[org.apache.ibatis.session.defaults.DefaultSqlSession5d74507c]clientEntity{clientId:301,createdTime:

22:07:21,id:301,nickName:更新后-昵称_测试,upatedTime:

22:07:21}

T22:27:

4

99608:00INFO17412---[springboot3-mybatisplus][ionShutdownHook]com.zaxxer.hikari.HikariDataSource:HikariPool-1-Shutdowninitiated...updateById官网 API/** * 根据 ID 修改 * * param entity 实体对象 */intupdateById(Param(Constants.ENTITY)Tentity);Demo 示例TestpublicvoidtestUpdate_03(){ClientEntityclientEntitynewClientEntity();clientEntity.setId(301L);clientEntity.setRealName(根据ID更新-名称);intupdateclientMapper.updateById(clientEntity);System.out.println(update update);clientEntityclientMapper.selectById(301L);System.out.println(clientEntity JSON.toJSONString(clientEntity));}输出日志

T22:41:

2

24408:00INFO13536---[springboot3-mybatisplus][main]com.zaxxer.hikari.HikariDataSource:HikariPool-1-Startcompleted.JDBCConnection[HikariProxyConnection65194223wrappingcom.mysql.cj.jdbc.ConnectionImpl362be0cd]will not be managed bySpringPreparing:UPDATE clientSETreal_name?WHEREid?Parameters:根据ID更新-名称(String),301(Long)Updates:1Closingnon transactionalSqlSession[org.apache.ibatis.session.defaults.DefaultSqlSessiond8e4250]update1CreatinganewSqlSessionSqlSession[org.apache.ibatis.session.defaults.DefaultSqlSession5b59c3d]was not registeredforsynchronization because synchronization is not active JDBCConnection[HikariProxyConnection110044003wrappingcom.mysql.cj.jdbc.ConnectionImpl362be0cd]will not be managed bySpringPreparing:SELECTid,client_id,user_no,user_password,nick_name,real_name,created_time,upated_time FROM clientWHEREid?Parameters:301(Long)Columns:id,client_id,user_no,user_password,nick_name,real_name,created_time,upated_timeRow:301,301,null,null,无实体更新-昵称-测试,根据ID更新-名称,

:07:21,

:07:21Total:1Closingnon transactionalSqlSession[org.apache.ibatis.session.defaults.DefaultSqlSession5b59c3d]clientEntity{clientId:301,createdTime:

22:07:21,id:301,nickName:无实体更新-昵称-测试,realName:根据ID更新-名称,upatedTime:

22:07:21}

T22:41:

2

41708:00INFO13536---[springboot3-mybatisplus][ionShutdownHook]com.zaxxer.hikari.HikariDataSource:HikariPool-1-Shutdowninitiated...updateById 批量(默认)参考官网 API 可知默认 1000 条数量批次提交。

int DEFAULT_BATCH_SIZE 1000;官网 API/** * 根据ID 批量更新 * * param entityList 实体对象集合 * since

3.

7 */defaultListBatchResultupdateById(CollectionTentityList){returnupdateById(entityList,Constants.DEFAULT_BATCH_SIZE);}/** * 默认批次提交数量 */intDEFAULT_BATCH_SIZE1000;updateById 批量(自定义)官网 API/** * 根据ID 批量更新 * * param entityList 实体对象集合 * param batchSize 插入批次数量 * since

3.

7 */defaultListBatchResultupdateById(CollectionTentityList,intbatchSize){MapperProxyMetadatamapperProxyMetadataMybatisUtils.getMapperProxy(this);MybatisBatch.MethodTmethodnewMybatisBatch.Method(mapperProxyMetadata.getMapperInterface());SqlSessionFactorysqlSessionFactoryMybatisUtils.getSqlSessionFactory(mapperProxyMetadata.getSqlSession());returnMybatisBatchUtils.execute(sqlSessionFactory,entityList,method.updateById(),batchSize);}Demo 示例TestpublicvoidtestUpdate_04(){// 生成批量测试数据.ListClientEntityclientEntityListnewArrayList();for(inti300;i303;i){ClientEntityclientEntitynewClientEntity();clientEntity.setId(Long.valueOf(i

);clientEntity.setClientId(Long.valueOf(i

);// 此处省略其他属性的 set 方法// clientEntity.setXXX;clientEntity.setNickName(批量-测试姓名i);clientEntityList.add(clientEntity);}// 默认批量提交数量intbatchSize2;clientMapper.updateById(clientEntityList,batchSize);}输出日志

T22:45:

4

69408:00INFO4580---[springboot3-mybatisplus][main]com.zaxxer.hikari.HikariDataSource:HikariPool-1-Startcompleted.JDBCConnection[HikariProxyConnection1878814375wrappingcom.mysql.cj.jdbc.ConnectionImpl2833c093]will not be managed bySpringPreparing:UPDATE clientSETclient_id?,nick_name?WHEREid?Parameters:301(Long),批量-测试姓名300(String),301(Long)Parameters:302(Long),批量-测试姓名301(String),302(Long)Preparing:UPDATE clientSETclient_id?,nick_name?WHEREid?Parameters:303(Long),批量-测试姓名302(String),303(Long)若有转载请标明出处https://blog.csdn.net/CharlesYuangc/article/details/157479468

日本群体交往活动视频大全-日本群体交往活动视频大全应用

百度百家号客服电话人工服务

123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123