mapping文件的编写(以及实体类与xml中类型的对应关系)
2017年02月18日 11:31:36 转角人生 阅读数:2918 标签: mapping文件 更多
个人分类: mapping文件
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.youkuaiyun.com/xuanzhangran/article/details/55657497
注意事项(1):
实体类 - 数据库 — xml(jdbc)
Integer – int – INTEGER
Float – float– REAL
Byte –tinyint– TINYINT
Long –bigint– BIGINT
String – varchar–VARCHAR
mapping的代码如下:
缺少的对应字段可以自己加上:
<?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.idorabox.manage.dao.jd.JdTokenDao" ><!--对应的Dao接口位置 -->
<resultMap id="BaseResultMap" type="com.idorabox.entity.JdToken" ><!--对应的实体类位置 -->
<id column="id" property="id" jdbcType="INTEGER" />
<result column="token" property="token" jdbcType="VARCHAR" />
<result column="create_date_time" property="createDateTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Base_Column_List" >
id, token, create_date_time, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from tbl_jd_token
where id = #{id,jdbcType=INTEGER}
</select>
<select id="queryList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tbl_jd_token
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from tbl_jd_token
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insertSelective" parameterType="com.idorabox.entity.JdToken" >
insert into tbl_jd_token
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="token != null" >
token,
</if>
<if test="createDateTime != null" >
create_date_time,
</if>
<if test="updateTime != null" >
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="token != null" >
#{token,jdbcType=VARCHAR},
</if>
<if test="createDateTime != null" >
#{createDateTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.idorabox.entity.JdToken" >
update tbl_jd_token
<set >
<if test="token != null" >
token = #{token,jdbcType=VARCHAR},
</if>
<if test="createDateTime != null" >
create_date_time = #{createDateTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>