💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[TOC] # 返回值是list resultType里面写list里面的属性就行 # 返回值是map ## 多个返回值,指定key xml ~~~ <select id="findAll" resultType="java.util.Map"> select * from user where username = #{username} or address = #{address} </select> ~~~ dao ~~~ //告诉mybatis 键是那个字段 @MapKey("id") Map<Integer, User> findAll(Map<String, Object> map); ~~~ 执行 ~~~ HashMap<String, Object> map = new HashMap<>(); map.put("username", "老王"); map.put("address", "北京"); Map<Integer, User> all = userDao.findAll(map); System.out.println(all); ~~~ 返回 `id=>javaBean` ## 单个返回值 **只适合查找一条记录,不然会报错** dao ~~~ Map<String, Object> findAll(Integer id); ~~~ xml 加limit是只要1条,不然返回多条会报错 ~~~ <select id="findAll" resultType="java.util.Map"> select * from user where id = #{id} limit 1 </select> ~~~ 执行 ~~~ Map<String, Object> res = userDao.findAll(41); System.out.println(res); ~~~ 返回 ~~~ {birthday=2018-02-27 17:47:08.0, address=北京, sex=男, id=41, username=老王} ~~~