标签:
1、mybaties 的返回值是对象的话定义为resultMap="resultMap"
值resultMap在文件首部进行重定义避免返回值为空,现在对象存储都是hashmap如下所示
<resultMap id="resultMap" type="java.util.HashMap">
<result column="USER_ID" property="userId" jdbcType="BIGINT" />
<result column="USER_ERP" property="erp" jdbcType="VARCHAR" />
<result column="USER_NAME" property="name" jdbcType="VARCHAR" />
<result column="USER_EMAIL" property="email" jdbcType="VARCHAR" />
<result column="USER_PHONE" property="phone" jdbcType="VARCHAR" />
<result column="USER_ROLE" property="role" jdbcType="VARCHAR" />
</resultMap>
<insert id="add" parameterType="com.jd.app.server.irp.common.beans.User">
INSERT INTO irp_user (
USER_ID,
USER_ERP,
USER_NAME,
USER_EMAIL,
USER_PHONE,
USER_ROLE)
VALUES (
#{userId,jdbcType=BIGINT},
#{erp,jdbcType=VARCHAR},
#{name,jdbcType=VARCHAR},
#{email,jdbcType=VARCHAR},
#{phone,jdbcType=VARCHAR},
#{role,jdbcType=VARCHAR})
</insert>
<select id="getUserByErp" resultMap="resultMap" parameterType="java.lang.String">
SELECT USER_ID,
USER_ERP,
USER_NAME,
USER_EMAIL,
USER_PHONE,
USER_ROLE
FROM irp_user
WHERE 1=1
AND USER_ERP = #{erp,jdbcType=VARCHAR}
</select>
<select id="getUsersByPage" resultMap="resultMap" parameterType="java.lang.Integer">
SELECT USER_ID,
USER_ERP,
USER_NAME,
USER_EMAIL,
USER_PHONE,
USER_ROLE
FROM irp_user
LIMIT #{0},#{1}
</select>
标签:
原文地址:http://www.cnblogs.com/freedommovie/p/5757635.html