1 引入pom
< dependency>
< groupId> org.springframework.boot</ groupId>
< artifactId> spring-boot</ artifactId>
< version> 2.7.14</ version>
</ dependency>
< dependency>
< groupId> com.baomidou</ groupId>
< artifactId> mybatis-plus-boot-starter</ artifactId>
< version> 3.5.3.2</ version>
</ dependency>
< dependency>
< groupId> mysql</ groupId>
< artifactId> mysql-connector-java</ artifactId>
< version> 8.0.29</ version>
</ dependency>
2 编写配置类MybatisPlusConfig
@Configuration
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor ( ) {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor ( ) ;
interceptor. addInnerInterceptor ( new PaginationInnerInterceptor ( DbType . MYSQL ) ) ;
return interceptor;
}
}
3 业务实现
3.1 Controller层
@Autowired
IComponentService componentService;
@ApiOperation ( value = "查询基础组件列表" , notes = "根据条件查询基础组件列表" )
@GetMapping ( "/list" )
public ResponseMessage < IPage < Component > > queryList ( @RequestBody QueryEntity < ComponentDTO > queryEntity) {
IPage < Component > page = new Page < > ( queryEntity. getPageNum ( ) , queryEntity. getPageSize ( ) ) ;
LambdaQueryWrapper < Component > query = new LambdaQueryWrapper < > ( ) ;
return ResponseMessage . success ( "查询成功" , componentService. queryList ( page, query) ) ;
}
3.2 service层
IPage < Component > queryList ( IPage < Component > page, LambdaQueryWrapper < Component > queryWrapper) ;
3.3 service实现层
@Override
public IPage < Component > queryList ( IPage < Component > page, LambdaQueryWrapper < Component > queryWrapper) {
return componentMapper. selectPage ( page, queryWrapper) ;
}
3.4 dao层
@Mapper
public interface ComponentMapper extends BaseMapper < Component > {
}
4 yaml配置
server :
port : 8090
servlet :
context-path : /hom
spring :
datasource :
driver-class-name : com.mysql.cj.jdbc.Driver
url : jdbc: mysql: //localhost: 3306/hom? useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=Asia/Shanghai
username : root
password : marlon
mybatis-plus :
configuration :
log-impl : org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case : true
mapper-locations : classpath: mapper/**/*.xml , classpath: mapper/*.xml
type-aliases-package : cn.com.marlon.hom.entity
global-config :
db-config :
logic-delete-value : 0
logic-not-delete-value : 1
logic-delete-field : deleted
5 postman测试