MyBatis 的 resultType
返回值类型
resultType: 返回值类型,类型即为对象类型。返回结果字段与对象属性匹配映射,类型中的属性名要与查询条件保持一致,否则就会失败。
返回集合
1 | public List<MyUser> selectMyUserByNameLike(String name); |
1 | <!-- resultType 集合内的元素类型 --> |
返回 Map
- 1.一条记录
1 | public Map<String,Object> selectMyUserById(Integer id); |
1 | <select id="selectMyUserById" resultType="map" parameterType="integer"> |
- 2.多条记录,需要指定 Map 的 Key 和 Value 的类型
1 | // 指定 Map 的 Key 从记录中的 id 列获取 |
1 | <!-- resultType Map 中 value 的类型 --> |
Mybatis 多参数查询时,可使用 @Param 注解
mybatis 在多参数查询的情况下,可以使用 @Param
注解, 然后 xml 中的 查询语句中,不再需要 parameterType
参数。
更多详情 请参考
原文链接: https://hzways.gitee.io/p/7d216f52.html
版权声明: 转载请注明出处.