1.前言
对学习过程的一次记录
2.集成步骤
(一)添加依赖
<!--引入mybatis plus : 内部包含有分页插件-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.2</version>
</dependency>
(二)调整配置,首先将之前的mybatis配置注释掉,再添加新的mybatis-plus配置
# mybatis-plus配置
mybatis-plus:
typeAliasesPackage: com.qcby.rbacwyq.entity #对应实体类路径
mapperLocations: classpath:mapper/*.xml #对应mapper映射xml文件所在路径
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
(三)测试是否能够使用
(1)首先在dao层写一个DemoDao接口,继承BaseMapper类
package com.qcby.rbacwyq.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qcby.rbacwyq.entity.Role;
/**
* @ClassName DemoDao
* @Description: //TODO 测试mybatis-plus
* @Author wyq
* @Date 2021/8/30 11:49
*/
public interface DemoDao extends BaseMapper<Role> {
}
(2)创建service层接口,继承IService类
/**
* @ClassName DemoService
* @Description: //TODO 测试mybatis-plus
* @Author wyq
* @Date 2021/8/30 11:50
*/
public interface DemoService extends IService<Role> {
}
(3)在实现层创建DemoServiceImpl类,传递DemoDao
/**
* @ClassName DemoServiceImpl
* @Description: //TODO 测试mybatis-plus
* @Author wyq
* @Date 2021/8/30 11:53
*/
@Service
public class DemoServiceImpl extends ServiceImpl<DemoDao, Role> implements DemoService {
@Resource
private DemoDao demoDao;
}
(4)controller层写接口实现,mybatis-plus自带单表查询
/**
* @ClassName DemoController
* @Description 测试mybatis-plus
* @Author wyq
* @Date 2021/8/20 0:29
*/
@RestController
@RequestMapping("demo")
public class DemoController {
@Resource
private DemoService demoService;
//查询所有信息
@RequestMapping("listAll")
public RestultJson listAll(){
return RestultJson.ok(demoService.list());
}
//添加
@RequestMapping("save")
public RestultJson save(Role role) {
return RestultJson.ok(demoService.save(role));
}
//批量删除
@RequestMapping("deleteByIds")
public RestultJson deleteByIds(@RequestParam List<Long> ids) {
return RestultJson.ok(demoService.removeByIds(ids));
}
//修改
@RequestMapping("updateById")
public RestultJson updateById(Role role) {
return RestultJson.ok(demoService.updateById(role));
}
}
(四)postman测试