Spring-Boot 介绍
架构
spring boot
MyBatis-Plus
MySql
start
实体映射表
1 | @Data |
Mapper层
1 | @Mapper |
service实现层
TO 继承了MyBatis-Plus的Pagination类有了分页属性1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25@Service
public class ServiceImpl implements Service {
private static AndroidPackageMapper mapper;
@Autowired
@SuppressWarnings("SpringJavaAutowiringInspection")
public AndroidPackageServiceImpl(AndroidPackageMapper mapper){
this.mapper=mapper;
}
@Override
public ActionResult<Page> List(TO){
EntityWrapper<DO> ew = new EntityWrapper<>();
ew.where("key={0}",key)
List<DO> DOList=mapper.selectPage(TO,ew);
Page<AndroidPackageVO> page=new Page(TO.getCurrent(),TO.getSize());
page.setRecords(DOList);
page.setTotal(TO.getTotal());
ActionResult<Page> ar=new ActionResult<>();
ar.setResult(page);
return ar;
}
}
service层
使用在启动类上使用@EnableTransactionManagement注解开启事务,在单元测试中的test函数上添加 @Transactional 注解配合
@Rollback 注解让每个单元测试都能在结束时回滚
1 | //开启事务 |
controller层
1 | @RestController |