mybatis plus
Published on: | Views: 109简介
mybatis plus是在mybatis基础上做了一些封装,简化了配置,对于简单的sql不再需要写sql语句。
引入
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2'
implementation 'com.baomidou:mybatis-plus-boot-starter:3.4.0'
配置
@Configuration
@MapperScan("com.xxx.data.dao")
public class MybatisPlusConfig {
@Bean
public OptimisticLockerInterceptor optimisticLockerInterceptor() {
return new OptimisticLockerInterceptor();
}
}
定义数据类
@Data
@EqualsAndHashCode(callSuper = true)
public class User extends BaseEntity {
// ...
@TableField(insertStrategy = FieldStrategy.NOT_NULL)
private Date createTime;
@TableField(insertStrategy = FieldStrategy.NOT_NULL, update = "now()")
private Date updateTime;
}
定义mapper
public interface UserMapper extends BaseMapper<User> {
}
使用
@Autowired
private UserMapper userMapper;
@Test
public void test(){
userMapper.selectList(null);
}