1.简单查询:
//按id查,基本数据类型都实现了Serializable接口,用到了多态写法
T selectById(Serializable id);案例:
User user = userMapper.selectById(1317025880475725825L);
//按id集合查
List<T> selectBatchIds(@Param("coll") Collection<? extends Serializable> idList);
案例:
List<Long> idsList = Arrays.asList(1317027921528954881L, 1317028164718907393L, 1317028352149729282L);
List<User> userList = userMapper.selectBatchIds(idsList);
userList.forEach(System.out::println);
//重点:按Map查多个条件,注意这里Map中的key是表中的字段名,不是实体变量名;Map中的value是需要查的字段对应的值
List selectByMap(@Param("cm") Map columnMap);案例:
Map<String,Object> columnMap = new HashMap<>();
columnMap.put("name","Jack");
columnMap.put("age",18);
List<User> userList = userMapper.selectByMap(columnMap);
userList.forEach(System.out::println);