关闭

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

1812人阅读 评论(0) 收藏 举报
分类:

关于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。

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:661731次
    • 积分:8845
    • 等级:
    • 排名:第2278名
    • 原创:217篇
    • 转载:297篇
    • 译文:22篇
    • 评论:67条
    最新评论