概述
mapper.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="com.hzcominfo.voucher.CommodityCategoryManager">
<cache-ref namespace="com.hzcominfo.dataggr.cloud" />
<insert id="insertCommodityCategoryManager" parameterType="com.hzcominfo.voucher.mapper.CommodityCategoryManager" keyProperty="id" >
INSERT INTO COMMODITY_CATEGORY_MANAGER (
<include refid="fields" />
) VALUES (
<include refid="values" />
)
</insert>
<update id="updateCommodityCategoryManager" parameterType="com.hzcominfo.voucher.mapper.CommodityCategoryManagerKey">
UPDATE COMMODITY_CATEGORY_MANAGER
<include refid="set" />
<include refid="where" />
</update>
<update id="deleteCommodityCategoryManager" parameterType="com.hzcominfo.voucher.mapper.CommodityCategoryManagerKey">
DELETE FROM COMMODITY_CATEGORY_MANAGER <include refid="where" />
</update>
<select id="selectCommodityCategoryManager" parameterType="String"
resultType="com.hzcominfo.voucher.mapper.CommodityCategoryManager">
SELECT * FROM COMMODITY_CATEGORY_MANAGER <include refid="where" />
</select>
<select id="selectCommodityCategoryManagerByCriteria" parameterType="net.butfly.albacore.dbo.criteria.Criteria"
resultType="com.hzcominfo.voucher.mapper.CommodityCategoryManagerKey">
SELECT CATEGORY_ID, USER_ID FROM COMMODITY_CATEGORY_MANAGER <include refid="where" />
</select>
<select id="countCommodityCategoryManagerByCriteria" parameterType="net.butfly.albacore.dbo.criteria.Criteria"
resultType="long">
SELECT count(*) FROM COMMODITY_CATEGORY_MANAGER <include refid="where" />
</select>
<sql id="fields">
<if test="categoryId!=null">CATEGORY_ID</if>
<if test="userId!=null">,USER_ID</if>
</sql>
<sql id="values">
<if test="categoryId!=null">#{categoryId}</if>
<if test="userId!=null">,#{userId}</if>
</sql>
<sql id="set">
<set>
<trim prefix="" prefixOverrides=",">
<if test="categoryId!=null">,CATEGORY_ID=#{categoryId}</if>
<if test="userId!=null">,USER_ID=#{userId}</if>
</trim>
</set>
</sql>
<sql id="where">
<where>
<trim prefix="" prefixOverrides="and|or" >
<if test="categoryId!=null">AND CATEGORY_ID=#{categoryId}</if>
<if test="userId!=null">AND USER_ID=#{userId}</if>
</trim>
</where>
</sql>
</mapper>
最后
以上就是端庄黑猫为你收集整理的mybatis的mapper配置文件的一般写法。的全部内容,希望文章能够帮你解决mybatis的mapper配置文件的一般写法。所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复