pom依赖修改
<!--取消mybatis -->
<!--<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>-->
<!--mybatis-plus start>
<!--解决实体类中使用了LocalDateTime 等时间类型报错问题-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-typehandlers-jsr310</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.2</version>
</dependency>
<!--mybatis-plus end-->
JAVA ConfigBean配置类的修改
主要是修改sqlSessionFactoryBean的实现类,改为mybatis-plus提供的类
@Bean(name = "OmsSqlSessionFactory")
public SqlSessionFactory OmsSqlSessionFactory(@Qualifier("omsDataSource") DataSource omsDataSource)
throws Exception {
final MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean();
sessionFactory.setDataSource(omsDataSource);
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(OmsConfig.MAPPER_LOCATION));
//设置动态schema
Properties prop = new Properties();
prop.setProperty("NW_APP", nwapp);
sessionFactory.setConfigurationProperties(prop);
return sessionFactory.getObject();
}
使用技巧
- mapper接口实现BaseMapper<你的实体类>
- 实体类指定表名
@TableName("TABLE_NAME")
- 实体类时间类型处理
//这个注解是为了controller层返回的json数据的时间格式
@JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss")
private LocalDateTime createDate;