case INSERT: {//insert Object param = method.convertArgsToSqlCommandParam(args); result = rowCountResult(sqlSession.insert(command.getName(), param)); break; } case UPDATE: {//update Object param = method.convertArgsToSqlCommandParam(args); result = rowCountResult(sqlSession.update(command.getNa...
"updateTime", LocalDateTime.class, LocalDateTime.now());// updateFill( metaObject);// 或者// this.strictInsertFill(metaObject, "createTime", () -> LocalDateTime.now(), LocalDateTime.class); /
@DatapublicabstractclassBaseModelimplementsSerializable {/*** 逻辑删除*/@TableField(value= "is_delete", fill =FieldFill.INSERT) @TableLogic @ApiModelProperty(hidden=true)protectedInteger deleted = 0; @TableField(fill=FieldFill.INSERT) @ApiModelProperty(hidden=true)protectedString createId; @TableField...
private String createUser; @TableField(value = "create_time", fill = FieldFill.INSERT) private LocalDateTime createTime; @TableField(value = "update_user", fill = FieldFill.INSERT_UPDATE) // 新增和更新执行 private String updateUser; @TableField(value = "update_time", fill = FieldFill.INSE...
mybatisplus执行insert和update都会有什么异常,我如果用translation注解来控制事务,需要怎么框定异常类型触发回滚操作 Mybatis-Plus 在执行插入和更新操作时,可能会抛出以下异常: org.apache.ibatis.exceptions.PersistenceException:这是 Mybatis 的基础异常,表示数据库访问过程中发生了错误。
#全局策略 mybatis-plus.global-config.db-config.update-strategy=not_empty mybatis-plus.global-config.db-config.insert-strategy=not_empty mybatis-plus.global-config.db-config.select-strategy=not_empty 可选的配置值,看源码如下 package com.baomidou.mybatisplus.annotation; public enum FieldStrategy { ...
add(new InsertBatchSomeColumn()); methodList.add(new UpdateBatchMethod()); return methodList; } } 注入Sql注入器 MybatisPlusConfig.java 将上面我们自定义的sql注入器注入到Spring容器里。 import org.mybatis.spring.annotation.MapperScan; import org.springframework.context.annotation.Bean; import org....
*/@TableField(fill=FieldFill.INSERT_UPDATE,select=false)privateLocalDateTime updateTime;} fill = FieldFill.INSERT表示insert操作的时候自动为该字段赋值 fill = FieldFill.INSERT_UPDATE表示nsert或update操作的时候自动为该字段赋值 select = false表示在使用Mybatis Wrapper条件构造器进行查询的时候,不查询这个属性...
if (isInsert && metaObjectHandler.openInsertFill()) { // 插入填充 metaObjectHandler.insertFill(metaObject); } else if (!isInsert) { // 更新填充 metaObjectHandler.updateFill(metaObject); } } return metaObject.getOriginalObject(); } 从源码分析我们可以得知当tableInfo为null时,是不走自动填充逻辑。
注解类型比较简单,在 mapper 层的接口类方法上使用@Select、@Update、@Insert、@Delete等注解并加上自定义的 sql 语句,即可代表查询、更新、存储、删除等操作。如下图所示: 虽然使用注解类型也可以实现动态 sql 的写法,但总归是太乱了,没有自定义 xml 类型条理清晰。接下来介绍自定义 xml 类型的写法。