mybatis Resultmap 与 ResultType 区别
来源:互联网 发布:python static method 编辑:程序博客网 时间:2024/05/16 07:25
Resultmap 的写法====目的是为了做映射
<resultMap id="BaseResultMap"type="com.suning.jupiter.common.pojo.storemanager.StoreBO"><!-- <result column="id" property="id" jdbcType="BIGINT" /><result column="storeName" property="store_name" jdbcType="VARCHAR" /><result column="storeType" property="store_type" jdbcType="VARCHAR" /><result column="storePath" property="store_path" jdbcType="VARCHAR" /><result column="storeWhere" property="store_where" jdbcType="VARCHAR" /> --> <result column="store_name" property="storeName" jdbcType="VARCHAR" /><result column="store_type" property="storeType" jdbcType="VARCHAR" /><result column="store_path" property="storePath" jdbcType="VARCHAR" /><result column="store_where" property="storeWhere" jdbcType="VARCHAR" /></resultMap>
注意:左边是数据库类型字段,右边是类字段,千万不可以做反了。
使用:
<select id="selectStore" parameterType="com.suning.jupiter.common.pojo.storemanager.StoreBO"resultMap="BaseResultMap">SELECTstore_name,store_type,store_path,store_whereFROMstore_manager darWHEREdar.store_name = #{storeName} anddar.store_type = #{storeType}</select>
resultType 只是确定返回类型 是什么,而且 数据库字段就是 map 的 key 的字段:
<select id="selectStore1" parameterType="com.suning.jupiter.common.pojo.storemanager.StoreBO"resultType="java.util.Map">SELECTstore_name,store_type,store_path,store_whereFROMstore_manager darWHEREdar.store_name = #{storeName} anddar.store_type = #{storeType}</select>
@Overridepublic List<StoreBO> getStoreList(Map<String, Object> map) {// TODO Auto-generated method stublog.info("ManagerServiceImpl -> addStore");if (map == null) {log.info("ManagerServiceImpl -> addStore map=null.");return null;}StoreBO storeBO = new StoreBO();storeBO.setStoreName((String)map.get("storeName"));storeBO.setStoreType((String)map.get("storeType"));List<StoreBO> list = managerStoreMapper.selectStore(storeBO);List<Map<String,Object>> listData=managerStoreMapper.selectStore1(storeBO);return list;}返回的数据:
[{store_path=http://lxl.com, store_name=lxl1, store_type=Docker, store_where=徐庄}]
按理说 resultType 是不能实现 数据库到对象的转变的,因为某字段无法和对象的属性对应起来。所以只是 map和数据库表对应。
阅读全文
0 0
- mybatis Resultmap 与 ResultType 区别
- mybatis 中resultType与resultMap区别
- mybatis中的resultMap与resultType的区别
- resultType与resultMap区别
- MyBatis中 resultType与resultMap
- Mybatis中的resultType与resultMap
- Mybatis中resultMap和resultType使用联系与区别
- Mybatis中输出映射-resultType与resultMap的区别
- Mybatis中的resultType和resultMap 区别
- mybatis中resultMap和resultType的区别
- mybatis resultType和resultMap的区别
- MyBatis中ResultMap和ResultType的区别
- MyBatis中resultType和resultMap的区别
- Mybatis: resultType和resultMap的区别
- mybatis中resultmap和resulttype区别
- Mybatis中的resultType和resultMap的区别
- Mybatis查询之resultMap和resultType区别
- mybatis中resulttype和resultmap的区别
- inline函数和宏定义区别 整理
- 北京理工大学小学期东软项目整理
- MOOC浙江大学陈月、何钦铭老师《数据结构》学习笔记01
- 机器学习博客收藏~
- 专利申请流程
- mybatis Resultmap 与 ResultType 区别
- 使用谷歌(Google)TTS服务 – Java版开源gTTS及Python gTTS
- axios 详细使用方法 及跨域请求的处理
- 计蒜客 Query on a string 线段树
- 【干货】wordpress函数实现屏蔽s.w.org提升网站速度
- 如何让多行文字与图片垂直居中
- c++中带有const ,&(引用)的常见类型的错误转换
- eclipse项目转android studio问题解决记录
- solr6.0学习之环境搭建-windows