84669 Lernen von Personen
152542 Lernen von Personen
20005 Lernen von Personen
5487 Lernen von Personen
7821 Lernen von Personen
359900 Lernen von Personen
3350 Lernen von Personen
180660 Lernen von Personen
48569 Lernen von Personen
18603 Lernen von Personen
40936 Lernen von Personen
1549 Lernen von Personen
1183 Lernen von Personen
32909 Lernen von Personen
光阴似箭催人老,日月如移越少年。
Mybatis 的Mapper文件的映射,如果结果复杂对象需要指定属性resultMap
<mapper namespace="com.pis.entity.UserRoleMapper" > <resultMap id="BaseResultMap" type="com.pis.entity.UserRole" > <id column="id" property="roleId" jdbcType="INTEGER" /> <result column="rolename" property="roleName" jdbcType="VARCHAR" /> <result column="note" property="note" jdbcType="VARCHAR" /> </resultMap> <sql id="Base_Column_List" > roleid, rolename, note </sql> <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > select <include refid="Base_Column_List" /> from userrole where roleid = #{roleid,jdbcType=INTEGER} </select> </mapper>
解释一下其中的几个属性值。<resultMap> 标签内存放的是结果集映射,如果是从javaweb基础学起的话,直接接触jdbc,应该对ResultSet这个比较了解,这里的resultMap指定的就是一个数据库字段column 和 你自己建的 pojo/entity 对象的映射关系。其中标签内的id是用来标识resultMap的,就是代码里的BaseResultMap,可以在下方select标签selectByPrimaryKey的resultMap属性中指定,表示使用这个结果集去接收查询到的结果并映射为UserRole对象。resultMap 标签内的id 是主键对应的映射,result 是其他列的映射。column属性是数据库里字段的名称,property是UserRole对象中对应的属性名称,jdbcType表示的是数据库中该字段的存储类型。下边的没什么难度,有问题还可以再私信我。另外,能用 mybatis-generator 生成这些文件就最好不要在手动写这些基础性的代码,容易错误和遗漏。自行百度mybatis-generator吧
<resultMap>
resultMap
id
BaseResultMap
select
selectByPrimaryKey
result
column
property
UserRole
jdbcType
mybatis-generator
Mybatis 的Mapper文件的映射,如果结果复杂对象需要指定属性resultMap
解释一下其中的几个属性值。
<resultMap>
标签内存放的是结果集映射,如果是从javaweb基础学起的话,直接接触jdbc,应该对ResultSet这个比较了解,这里的resultMap
指定的就是一个数据库字段column 和 你自己建的 pojo/entity 对象的映射关系。其中标签内的id
是用来标识resultMap
的,就是代码里的BaseResultMap
,可以在下方select
标签selectByPrimaryKey
的resultMap
属性中指定,表示使用这个结果集去接收查询到的结果并映射为UserRole对象。resultMap
标签内的id
是主键对应的映射,result
是其他列的映射。column
属性是数据库里字段的名称,property
是UserRole
对象中对应的属性名称,jdbcType
表示的是数据库中该字段的存储类型。下边的没什么难度,有问题还可以再私信我。另外,能用mybatis-generator
生成这些文件就最好不要在手动写这些基础性的代码,容易错误和遗漏。自行百度mybatis-generator吧