1.在启动类上面添加@MapperScan注解,扫描mapper包
1 @SpringBootApplication 2 @MapperScan("com.qiao.demo02.mapper") 3 public class SpringbootDemo02Application { 4 5 public static void main(String[] args) { 6 SpringApplication.run(SpringbootDemo02Application.class, args); 7 } 8 9 }
2baseMapper里面生成了大量的crud方法
UserMapper接口
public interface UserMapper extends BaseMapper<User> { 2 3 }
1 public interface UserMapper extends BaseMapper<User> { 2 3 }
最重要的是继承BaseMapper<E>接口:里面声明了很强大的CRUD方法
public interface BaseMapper<T> extends Mapper<T> { 2 int insert(T entity); 3 4 int deleteById(Serializable id); 5 6 int deleteByMap(@Param("cm") Map<String, Object> columnMap); 7 8 int delete(@Param("ew") Wrapper<T> wrapper); 9 10 int deleteBatchIds(@Param("coll") Collection<? extends Serializable> idList); 11 12 int updateById(@Param("et") T entity); 13 14 int update(@Param("et") T entity, @Param("ew") Wrapper<T> updateWrapper); 15 16 T selectById(Serializable id); 17 18 List<T> selectBatchIds(@Param("coll") Collection<? extends Serializable> idList); 19 20 List<T> selectByMap(@Param("cm") Map<String, Object> columnMap); 21 22 T selectOne(@Param("ew") Wrapper<T> queryWrapper); 23 24 Integer selectCount(@Param("ew") Wrapper<T> queryWrapper); 25 26 List<T> selectList(@Param("ew") Wrapper<T> queryWrapper); 27 28 List<Map<String, Object>> selectMaps(@Param("ew") Wrapper<T> queryWrapper); 29 30 List<Object> selectObjs(@Param("ew") Wrapper<T> queryWrapper); 31 32 IPage<T> selectPage(IPage<T> page, @Param("ew") Wrapper<T> queryWrapper); 33 34 IPage<Map<String, Object>> selectMapsPage(IPage<T> page, @Param("ew") Wrapper<T> queryWrapper); 35 }
1 public interface BaseMapper<T> extends Mapper<T> { 2 int insert(T entity); 3 4 int deleteById(Serializable id); 5 6 int deleteByMap(@Param("cm") Map<String, Object> columnMap); 7 8 int delete(@Param("ew") Wrapper<T> wrapper); 9 10 int deleteBatchIds(@Param("coll") Collection<? extends Serializable> idList); 11 12 int updateById(@Param("et") T entity); 13 14 int update(@Param("et") T entity, @Param("ew") Wrapper<T> updateWrapper); 15 16 T selectById(Serializable id); 17 18 List<T> selectBatchIds(@Param("coll") Collection<? extends Serializable> idList); 19 20 List<T> selectByMap(@Param("cm") Map<String, Object> columnMap); 21 22 T selectOne(@Param("ew") Wrapper<T> queryWrapper); 23 24 Integer selectCount(@Param("ew") Wrapper<T> queryWrapper); 25 26 List<T> selectList(@Param("ew") Wrapper<T> queryWrapper); 27 28 List<Map<String, Object>> selectMaps(@Param("ew") Wrapper<T> queryWrapper); 29 30 List<Object> selectObjs(@Param("ew") Wrapper<T> queryWrapper); 31 32 IPage<T> selectPage(IPage<T> page, @Param("ew") Wrapper<T> queryWrapper); 33 34 IPage<Map<String, Object>> selectMapsPage(IPage<T> page, @Param("ew") Wrapper<T> queryWrapper); 35 }