mybatis-config.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!--set lazy fetching-->
<setting name="lazyLoadingEnabled" value="false" />
</settings>
<typeAliases>
<typeAlias alias="trialNote" type="cn.com.chnsys.rcs.caseinfo.pojo.TrialNote"/>
</typeAliases>
<mappers>
<mapper resource="ibatis/caseinfo/trialnote.xml"/>
</mappers>
</configuration>
trialnote.xml配置如下:
<?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="cn.com.chnsys.rcs.caseinfo.dao.TrialNoteDao">
<resultMap id="trialNoteResult" type="cn.com.chnsys.rcs.caseinfo.pojo.TrialNote">
<result property="noteId" column="tsblid"></result>
<result property="fileName" column="wjm"></result>
<result property="ftpUrl" column="ftpurl"></result>
<result property="vodInfoId" column="dbxxid"></result>
</resultMap>
<sql id="t_tsbl_columns">tsblid,wjm,ftpurl,dbxxid</sql>
<select id="getTrialNote" resultMap="trialNoteResult" parameterType="string">
SELECT <include refid="t_tsbl_columns" />
FROM t_tsbl
WHERE dbxxid = #{vodInfoId}
</select>
<insert id="insertTrialNote" parameterType="trialNote">
INSERT INTO t_tsbl (tsblid
<if test="fileName != null">
,wjm
</if>
<if test="ftpUrl != null">
,ftpurl
</if>
<if test="vodInfoId != null">
,dbxxid
</if>
)VALUES ( #{noteId}
<if test="fileName != null">
,#{fileName}
</if>
<if test="ftpUrl">
,#{ftpUrl}
</if>
<if test="vodInfoId != null">
,#{vodInfoId}
</if>
)
</insert>
<update id="updatetTrialNote" parameterType="trialNote">
UPDATE t_tsbl
<set>
<if test="fileName != null">wjm = #{fileName},</if>
<if test="ftpUrl != null">ftpurl = #{ftpUrl},</if>
<if test="vodInfoId != null">dbxxid = #{vodInfoId}</if>
</set>
WHERE tsblid = #{noteId}
</update>
<delete id="deleteTrialNote" parameterType="string">
DELETE FROM t_tsbl WHERE dbxxid = #{vodInfoId}
</delete>
</mapper>
与ibatis2.0不同的地方在于paramter的别名位置只能出现在config配置文件下,并且paramClass变为paramType,结果集同理。还有一点mybatis框架不再需要实现DAO接口,直接
<delete id="deleteTrialNote" parameterType="string">把其中的id项对应DAO接口方法即可。