乐优商城项目总结day(7)
乐优商城项目总结day(7) 1.mapper-spring-boot-starter(通用mapper)的使用 1.1.实体类 实体类上加上 javax.persistence 包下 @Table 注解用来指定表名,表的主键字段使用 javax.persistence 包下 @Id 注解, @KeySql 是通用mapper中用来指定主键自增长策略。 1.2.dao层 该类所在的包需要使用 @MapperScan("所在包名") 声明,继承通用mapper中 Mapper 接口并指定对应的pojo就能使用,同时还能继承其他 Mapper 接口来进行增强,能够非常方便的对单表进行增删改查。 1.3.dao层的使用 Mapper 接口中自带的方法: 都是一些基于单表的增删改查。 select用法 Category category = new Category(); category.setParentId(pid); List<Category> categoryList = categoryDao.select(category); 参数中传入对象,对象的属性与值即为查询的条件。 selectByExample用法 适用于单表的动态条件查询,用法例如: public PageResult<Brand> queryBrandByPage(Integer page, Integer