MyBatis的mapping.xml中有两个重要的属性:parameterType和resultMap属性(parameterMap现在不建议使用)
parameterType用来指定传入参数的类型,比如Bean或Map\List。
<configuration> <typeAliases> <typeAlias alias="Product" type="com.zainagou.supplier.entity.Product"/> </typeAliases> <!-- 映射map --> <mappers> </mappers> </configuration>
resultMap是MyBatis中最重要最强大的元素。resultMap封装查询的结果集,type可以是Bean、Object、Primitive type。
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mapper namespace="com.zainagou.supplier.mapper.ProductCategoryMapper"> <parameterMap id="productCategory" type="com.zainagou.supplier.entity.ProductCategory"></parameterMap> <resultMap id="resultMap" type="com.zainagou.supplier.entity.ProductCategory" > <id column="id" property="id" jdbcType="INTEGER" /> <result column="p_id" property="pid" jdbcType="INTEGER" /> <result column="name" property="name" jdbcType="VARCHAR" /> </resultMap> <sql id="Base_Column_List" > id, fid, name </sql> <select id="getProductCategorys" resultMap="resultMap" parameterMap="productCategory"> select <include refid="Base_Column_List" /> from product_category where 0=0 <if test="name!=null and name!=''"> and name like "%"#{name,jdbcType=VARCHAR}"%" </if> </select> </mapper>
从上面mapping.xml可以看出:
resultMap中, column是列名,property是列映射到实体对象的属性,jdbcType是列在数据库中的数据类型,格式统一都是大写,和MySql中的数据类型多数保持一致,少数有差异。
这种方式可以解决列名不匹配。
相关推荐
mybatis 一对多collection的使用 在mybatis如何进行一对多的多表查询呢?这里用一个简单的例子说明
详细说明了MyBatis的resultMap使用方法
主要介绍了mybatis教程之resultmap,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
mybatis的核心知识点, if trim where set foreach等
2.2.0mybatis-plus代码自动生成。网上的配置起来复杂,我这个简单就可以实现这个功能
Mybatis mybatis공부(Spring启动和mybatis缓存,resultMap,dynamicSQL,事务)
根据MyBatis的ResultMap生成增删改sql
主要介绍了MyBatis中的resultMap简要概述的相关资料,需要的朋友可以参考下
mybatis中resultmap详细使用说明
MyBatis_sql-resultMap-缓存
mybatis中mapper文件resultMap中collection和association的使用,参考地址:https://blog.csdn.net/zhizhuodewo6/article/details/82863452
如果是实体中是直接引用别的对象的具体参数字段,直接用原始方式就行 SELECT eer.visit_number as visitNumber, eer.patient_name as patientName, eer.send_time as sendTime, eek.id as id, ...
MyBatis(四) 删除单条数据
mybatis-demo4-resultMap手动映射.zip
MyBatis源码:原来 resultMap解析完是这样
mybatis3--4.resultMap高级映射
NULL 博文链接:https://724073277.iteye.com/blog/1479584
主要介绍了MyBatis中resultMap和resultType的区别详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧