关于Mybatis的XML配置文件的namespace元素的作用。

关于Mybatis的XML配置文件的namespace元素的作用。


配置文件如下:

<?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.Voucher">
<cache-ref namespace="com.hzcominfo.dataggr.cloud" />


<insert id="insertVoucher" parameterType="com.hzcominfo.voucher.mapper.Voucher"
keyProperty="id">
INSERT INTO VOUCHER (
<include refid="fields" />
) VALUES (
<include refid="values" />
)
</insert>


<update id="updateVoucher" parameterType="com.hzcominfo.voucher.mapper.Voucher">
UPDATE VOUCHER
<include refid="set" />
WHERE id = #{id}
</update>


<update id="updateVoucherByCriteria" parameterType="net.butfly.albacore.dbo.criteria.Criteria">
UPDATE VOUCHER
<include refid="set" />
<include refid="where" />
</update>
<update id="updateList" parameterType="com.hzcominfo.voucher.mapper.Voucher">
UPDATE VOUCHER
<include refid="set" />
where promotion_id=#{promotionId}
</update>
<update id="deleteVoucher" parameterType="String">
DELETE FROM VOUCHER
WHERE id = #{id}
</update>


<update id="deleteVoucherByContentCriteria" parameterType="net.butfly.albacore.dbo.criteria.Criteria">
DELETE FROM VOUCHER
<include refid="where" />
</update>


<select id="selectVoucher" parameterType="String"
resultType="com.hzcominfo.voucher.mapper.Voucher">
SELECT * FROM VOUCHER where id = #{id}
</select>


<select id="selectVoucherByCriteria" parameterType="net.butfly.albacore.dbo.criteria.Criteria"
resultType="String">
SELECT id FROM VOUCHER
<include refid="where" />
</select>
<select id="countVoucherByCriteria" parameterType="net.butfly.albacore.dbo.criteria.Criteria"
resultType="long">
SELECT count(id) FROM VOUCHER
<include refid="where" />
</select>


<select id="selectVoucherIssue" parameterType="com.hzcominfo.voucher.mapper.VoucherIssue"
resultType="com.hzcominfo.voucher.mapper.VoucherIssue">
SELECT P.ID PROMOTIONID,F.ID PROMOTIONFACTORID,U.ID USEFACTORID
FROM PROMOTION P, PROMOTION_FACTOR F, USE_FACTOR U
WHERE P.ID=F.PROMOTION_ID AND U.PROMOTION_FACTOR_ID=F.ID AND F.ISSUING_FLAG='1'
AND F.ISSUE_TOTAIL_NUM>=F.ISSUE_NUM AND P.DELETED = '0' AND F.DELETED='0'
<if test="money!=null and money!=0">
<![CDATA[AND ${money}>=F.MONEY]]>
</if>
<if test="storeZomeLevel!=null and storeZomeLevel!=''">
<![CDATA[AND F.STORE_ZOME_LEVEL = '${storeZomeLevel}']]>
</if>
<if test="time!=null and time!=''">
<![CDATA[AND to_char(P.START_TIME,'yyyy-MM-dd') <= '${time}']]>
<![CDATA[AND to_char(P.END_TIME,'yyyy-MM-dd') >= '${time}']]>
</if>
<if test="isCash!=null and isCash!=''">
<![CDATA[AND F.COMMODITY_ID IS  NULL]]>
</if>
</select>

<sql id="fields">
id
<if test="promotionId!=null">,promotion_id</if>
<if test="status!=null">,status</if>
<if test="customerId!=null">,customer_id</if>
<if test="deleted!=null">,deleted</if>
<if test="addTime!=null">,add_time</if>
<if test="updateTime!=null">,update_time</if>
<if test="startTime!=null">,start_time</if>
<if test="endTime!=null">,end_time</if>
<if test="factorId!=null">,factor_id</if>
<if test="useId!=null">,use_id</if>
</sql>


<sql id="values">
#{id}
<if test="promotionId!=null">,#{promotionId}</if>
<if test="status!=null">,#{status}</if>
<if test="customerId!=null">,#{customerId}</if>
<if test="deleted!=null">,#{deleted}</if>
<if test="addTime!=null">,#{addTime}</if>
<if test="updateTime!=null">,#{updateTime}</if>
<if test="startTime!=null">,#{startTime}</if>
<if test="endTime!=null">,#{endTime}</if>
<if test="factorId!=null">,#{factorId}</if>
<if test="useId!=null">,#{useId}</if>

</sql>


<sql id="set">
<set>
<trim prefix="" prefixOverrides=",">
<if test="promotionId!=null">,promotion_id=#{promotionId}</if>
<if test="status!=null">,status=#{status}</if>
<if test="customerId!=null">,customer_id=#{customerId}</if>
<if test="deleted!=null">,deleted=#{deleted}</if>
<if test="addTime!=null">,add_time=#{addTime}</if>
<if test="updateTime!=null">,update_time=#{updateTime}</if>
<if test="startTime!=null">,start_time=#{startTime}</if>
<if test="endTime!=null">,end_time=#{endTime}</if>
<if test="factorId!=null">,factor_id=#{factorId}</if>
<if test="useId!=null">,use_id=#{useId}</if>
</trim>
</set>
</sql>
<sql id="where">
<where>
DELETED = '0'
<if test="id!=null">AND id=#{id}</if>
<if test="promotionId!=null">AND promotion_id=#{promotionId}</if>
<if test="status!=null">AND status=#{status}</if>
<if test="customerId!=null">AND customer_id=#{customerId}</if>
<if test="addTime!=null">AND add_time=#{addTime}</if>
<if test="startTime!=null">AND start_time=#{startTime}</if>
<if test="endTime!=null">AND end_time=#{endTime}</if>
<if test="factorId!=null">AND factor_id=#{factorId}</if>
<if test="useId!=null">AND use_id=#{useId}</if>
</where>
</sql>


</mapper>



java代码如下:


package com.hzcominfo.voucher.impl.dao;


import net.butfly.albacore.dao.EntityDAOBase;
import net.butfly.albacore.exception.BusinessException;


import java.util.List;


import com.hzcominfo.voucher.dao.VoucherDao;
import com.hzcominfo.voucher.mapper.Voucher;
import com.hzcominfo.voucher.mapper.VoucherIssue;



public class VoucherDaoImpl extends EntityDAOBase implements VoucherDao {


private static final long serialVersionUID = 1L;


@Override
public int updateList(Voucher voucher) throws BusinessException {
int flag = this.template.update("com.hzcominfo.voucher.Voucher.updateList", voucher);
return flag;
}

@Override
public List<VoucherIssue> selectVoucherIssue(VoucherIssue voucherIssue) {
List<VoucherIssue> list = this.template.selectList("com.hzcominfo.voucher.Voucher.selectVoucherIssue", voucherIssue);
return list;
}
}


其中:List<VoucherIssue> list = this.template.selectList("com.hzcominfo.voucher.Voucher.selectVoucherIssue", voucherIssue);

的com.hzcominfo.voucher.Voucher对应XML配置文件的namespace元素名,selectVoucherIssue对应其中的同名<select>元素的sql。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值