完整mybatis应用

<?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.xy.xyd.rest.crm.repository.CrmClientRepository" >
<resultMap id="ResultMap" type="com.xy.xyd.rest.crm.entity.CrmClient" >
<id column="ID" property="id" jdbcType="BIGINT" />
<result column="NAME" property="name" jdbcType="VARCHAR" />
<result column="LATITUDE" property="latitude" jdbcType="DOUBLE" />
<result column="IS_DEL" property="isDel" jdbcType="INTEGER" />
<result column="CREATE_BY" property="createBy" jdbcType="BIGINT" />
<result column="CREATE_TIME" property="createTime" jdbcType="TIMESTAMP" />
<result column="MODIFY_BY" property="modifyBy" jdbcType="BIGINT" />
<result column="LAST_CHANGE_TIME" property="lastChangeTime" jdbcType="TIMESTAMP" />
</resultMap>

<sql id="Base_Column_List" >
ID, NAME, SHORT_NAME, COMMENT, CITY_ID, AREA_ID, PRO_ID,LAST_CHANGE_TIME
</sql>

<!--find查询列 -->
<sql id="Find_Column_List">
ID
</sql>

<sql id="Where_Clause">
<if test="id != null" >
and a.ID = #{id,jdbcType=BIGINT}
</if>
<if test="inClientIds != null">
and a.ID in (${inClientIds})
</if>
<if test="outClientIds != null">
and a.ID not in (${outClientIds})
</if>

<if test="proId != null" >
and PRO_ID = #{proId,jdbcType=BIGINT}
</if>
<if test="lastChangeTime != null" >
and a.LAST_CHANGE_TIME = #{lastChangeTime,jdbcType=TIMESTAMP}
</if>
</sql>

<sql id="Order_By">
order by
<if test="sort!=null">
<if test="sort==&quot;id&quot;">
a.ID ${order}
</if>
<if test="sort==&quot;name&quot;">
a.NAME ${order}
</if>
<if test="sort==&quot;sortOrder&quot;">
a.SORT_ORDER ${order}
</if>
</if>
<if test="sort==null">
a.ID
</if>
</sql>
<sql id="Paging">
<if test="firstResult!=null"> limit #{firstResult,jdbcType=DECIMAL} ,
#{offset,jdbcType=DECIMAL}
</if>
</sql>

<!--按Id查询 -->
<select id="selectById" resultMap="ResultMap" parameterType="Long">
select
<include refid="Base_Column_List" />
from crm_client a where id=#{id}
</select>

<!--按Id删除 -->
<delete id="deleteById" parameterType="Long">
delete a from crm_client a where id=#{id}
</delete>

<!--条件查询,只查询ID -->
<select id="selectToId" resultType="long" parameterType="map">
select
<include refid="Find_Column_List" />
from crm_client a where 1=1
<include refid="Where_Clause" />
<include refid="Order_By"/>
<include refid="Paging" />
</select>

<select id="select" resultMap="ResultMap" parameterType="map">
select
<include refid="Base_Column_List" />
from crm_client a
where 1=1
<include refid="Where_Clause" />
</select>

<!-- 同一家公司,在省的范围内,简称查重 ,如有重复,返回所有重复的客户简称及归属人姓名 -->
<select id="findRepeatListInProvince" resultType="java.util.Map" parameterType="map">
select
a.ID AS id,
a.NAME AS name,
a.SHORT_NAME AS shortName,
a.SALE_MAN AS saleMan
from crm_client a
where 1=1
<include refid="Where_Clause" />
<include refid="Paging" />
</select>

<select id="findClientInfo" resultType="java.util.Map" parameterType="map" >
select
a.NAME AS name,
a.SHORT_NAME AS shortName,
a.LATITUDE AS latitude,
b.DICT_VALUE AS typeValue,
a.SALE_MAN AS saleMan,
c.NAME AS saleManName,
a.LEVEL AS level,
d.DICT_VALUE AS levelValue,
a.INTRODUCTION AS introduction

from crm_client a
LEFT JOIN cm_dict_type b on a.TYPE = b.DICT_CODE AND b.type =‘Client_Type‘
LEFT JOIN cm_xyduser c on a.SALE_MAN = c.ID
LEFT JOIN cm_dict_type d on a.LEVEL = d.DICT_CODE AND d.type =‘Client_Level‘
where 1=1
<include refid="Where_Clause" />
</select>

<delete id="delete" parameterType="java.lang.Long" >
delete from crm_client
where ID = #{id,jdbcType=BIGINT}
</delete>

<insert id="save" parameterType="com.xy.xyd.rest.crm.entity.CrmClient" useGeneratedKeys="true" keyProperty="id">
insert into crm_client
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
ID,
</if>
<if test="name != null" >
NAME,
</if>
<if test="cityId != null" >
CITY_ID,
</if>
<if test="areaId != null" >
AREA_ID,
</if>
<if test="proId != null" >
PRO_ID,
</if>
<if test="lastChangeTime != null" >
LAST_CHANGE_TIME,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=BIGINT},
</if>
<if test="name != null" >
#{name,jdbcType=VARCHAR},
</if>
<if test="cityId != null" >
#{cityId,jdbcType=BIGINT},
</if>
<if test="areaId != null" >
#{areaId,jdbcType=BIGINT},
</if>
<if test="proId != null" >
#{proId,jdbcType=BIGINT},
</if>
<if test="lastChangeTime != null" >
#{lastChangeTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>

<update id="update" parameterType="com.xy.xyd.rest.crm.entity.CrmClient" >
update crm_client
<set >
<if test="name != null" >
NAME = #{name,jdbcType=VARCHAR},
</if>
<if test="cityId != null" >
CITY_ID = #{cityId,jdbcType=BIGINT},
</if>
<if test="areaId != null" >
AREA_ID = #{areaId,jdbcType=BIGINT},
</if>
<if test="proId != null" >
PRO_ID = #{proId,jdbcType=BIGINT},
</if>
<if test="lastChangeTime != null" >
LAST_CHANGE_TIME = #{lastChangeTime,jdbcType=TIMESTAMP},
</if>
</set>
where ID = #{id,jdbcType=BIGINT}
</update>

<!-- 批量修改 -->
<update id="updateBatch" parameterType="List" >
<foreach collection="list" item="obj" index="index" separator=" ; " >
update crm_client
<set >
<if test="obj.name != null" >
NAME = #{obj.name,jdbcType=VARCHAR},
</if>
<if test="obj.shortName != null" >
SHORT_NAME = #{obj.shortName,jdbcType=VARCHAR},
</if>
<if test="obj.ownCompanyId != null" >
OWN_COMPANY_ID = #{obj.ownCompanyId,jdbcType=BIGINT},
</if>

<if test="obj.proId != null" >
PRO_ID = #{obj.proId,jdbcType=BIGINT},
</if>
<if test="obj.lastChangeTime != null" >
LAST_CHANGE_TIME = #{obj.lastChangeTime,jdbcType=TIMESTAMP},
</if>
</set>
where ID = #{obj.id,jdbcType=BIGINT}
</foreach>
</update>

<select id="count" resultType="java.lang.Integer" parameterType="map" >
select count(1) from crm_client a
where 1=1
<include refid="Where_Clause" />
</select>

<select id="countShareClientNUmber" resultType="java.lang.Integer" parameterType="map" >
select count(*) from crm_client a
where 1=1
<if test="isShared != null" >
and a.IS_SHARED = #{isShared,jdbcType=INTEGER}
</if>
<if test="saleMan != null" >
and a.SALE_MAN = #{saleMan,jdbcType=BIGINT}
</if>
<!-- 级别筛选 -->
<if test="level != null" >
and a.LEVEL IN
<foreach item="levelArray" index="index" collection="level"
open="(" separator="," close=")">
#{levelArray}
</foreach>
</if>
</select>

<select id="findClientList" resultType="java.util.Map" parameterType="map">
select
distinct(a.ID) AS id,
a.NAME AS name,
b.MOBILE AS mobile,
a.SALE_MAN AS saleMan,
c.NAME AS saleManName,
a.IS_SHARED AS isShared,
a.LEVEL AS level,
d.DICT_VALUE AS levelValue,
date_format(a.CREATE_TIME,‘%Y%m%d%H%i%S‘) as createTime,
date_format(a.LAST_TRACK_TIME,‘%Y%m%d%H%i%S‘) as lastTrackTime
from crm_client a
LEFT JOIN crm_contact b on a.ID = b.CLIENT_ID AND b.IS_DEFAULT_CONTACT = 1
LEFT JOIN cm_xyduser c on a.SALE_MAN = c.ID
LEFT JOIN cm_dict_type d on a.LEVEL = d.DICT_CODE AND d.TYPE = ‘Client_Level‘
<if test="mainBusiness != null" >
inner JOIN crm_main_business_client e on a.ID = e.CLIENT_ID
</if>
where 1=1 and a.IS_DEL = 0 and a.SALE_MAN>-3
<!-- 省份筛选 -->
<if test="addProvince != null" >
and a.ADD_PROVINCE IN
<foreach item="typeArray" index="index" collection="addProvince"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>
<!-- 主营行业筛选 -->
<if test="mainBusiness != null" >
and e.MAIN_BUSINESS_ID IN
<foreach item="typeArray" index="index" collection="mainBusiness"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>
<!-- 归属筛选 -->
<if test="ids != null" >
and a.SALE_MAN IN
<foreach item="typeArray" index="index" collection="ids"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>
<if test="ownCompanyId != null" >
and a.OWN_COMPANY_ID = #{ownCompanyId,jdbcType=BIGINT}
</if>
<!-- 级别筛选 -->
<if test="level != null" >
and a.LEVEL IN
<foreach item="typeArray" index="index" collection="level"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>
<!-- 类型筛选 -->
<if test="type != null" >
and a.TYPE IN
<foreach item="typeArray" index="index" collection="type"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>
<!-- 跟踪日期 -->
<if test="endTrackTime != null" >
<!-- and ( a.LAST_TRACK_TIME IS NULL OR a.LAST_TRACK_TIME <![CDATA[ < ]]> #{endTrackTime,jdbcType=TIMESTAMP}) -->
and a.LAST_TRACK_TIME &lt;= #{endTrackTime,jdbcType=TIMESTAMP}
</if>
order by a.CREATE_TIME desc
<include refid="Paging" />
</select>

<select id="countClientListNumber" resultType="java.lang.Integer" parameterType="map">
select
count(distinct(a.ID))

from crm_client a
LEFT JOIN crm_contact b on a.ID = b.CLIENT_ID AND b.IS_DEFAULT_CONTACT = 1
LEFT JOIN cm_xyduser c on a.SALE_MAN = c.ID
LEFT JOIN cm_dict_type d on a.LEVEL = d.DICT_CODE AND d.TYPE = ‘Client_Level‘
<if test="mainBusiness != null" >
inner JOIN crm_main_business_client e on a.ID = e.CLIENT_ID
</if>
where 1=1 and a.IS_DEL = 0 and a.SALE_MAN>-3
<if test="item != null" >
and a.ITEM = #{item,jdbcType=VARCHAR}
</if>
<!-- 省份筛选 -->
<if test="addProvince != null" >
and a.ADD_PROVINCE IN
<foreach item="typeArray" index="index" collection="addProvince"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>
<!-- 主营行业筛选 -->
<if test="mainBusiness != null" >
and e.MAIN_BUSINESS_ID IN
<foreach item="typeArray" index="index" collection="mainBusiness"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>
<!-- 归属筛选 -->
<if test="ids != null" >
and a.SALE_MAN IN
<foreach item="typeArray" index="index" collection="ids"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>
<if test="ownCompanyId != null" >
and a.OWN_COMPANY_ID = #{ownCompanyId,jdbcType=BIGINT}
</if>
<!-- 级别筛选 -->
<if test="level != null" >
and a.LEVEL IN
<foreach item="typeArray" index="index" collection="level"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>
<!-- 跟踪日期 -->
<if test="endTrackTime != null" >
and (a.LAST_TRACK_TIME IS NULL OR a.LAST_TRACK_TIME <![CDATA[ < ]]> #{endTrackTime,jdbcType=BIGINT})
</if>
<!-- 类型筛选 -->
<if test="type != null" >
and a.TYPE IN
<foreach item="typeArray" index="index" collection="type"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>

</select>

<!-- 客户搜索 begin zyf -->
<select id="selectSearchToId" resultType="long" parameterType="map">
select
a.ID
from crm_client a
<if test="tell != null" >
LEFT JOIN crm_contact b ON a.ID = b.CLIENT_ID
</if>
where 1=1
<if test="ownCompanyId != null" >
and a.OWN_COMPANY_ID = #{ownCompanyId,jdbcType=BIGINT}
</if>
<if test="userIds != null" >
and a.SALE_MAN in(${userIds})
</if>
<if test="isDel != null" >
and a.IS_DEL = #{isDel,jdbcType=INTEGER}
</if>
and(
<if test="name != null" >
a.NAME like ‘%${name}%‘
or a.SHORT_NAME like ‘%${name}%‘
</if>
<if test="tell != null" >
or a.TELL like ‘${tell}%‘
OR (a.SALE_MAN > 0 and b.MOBILE like ‘${tell}%‘)
</if>
)
<include refid="Order_By"/>
<include refid="Paging" />
</select>

<select id="selectSearchCount" resultType="java.lang.Integer" parameterType="map" >
select COUNT(DISTINCT a.ID) from crm_client a
<if test="tell != null" >
LEFT JOIN crm_contact b ON a.ID = b.CLIENT_ID
</if>
where 1=1 and a.SALE_MAN > -3
<if test="ownCompanyId != null" >
and a.OWN_COMPANY_ID = #{ownCompanyId,jdbcType=BIGINT}
</if>
<if test="userIds != null" >
and a.SALE_MAN in(${userIds})
</if>
<if test="isDel != null" >
and a.IS_DEL = #{isDel,jdbcType=INTEGER}
</if>
and (
<if test="name != null" >
a.NAME like ‘%${name}%‘
or a.SHORT_NAME like ‘%${name}%‘
</if>
<if test="tell != null" >
or a.TELL like ‘${tell}%‘
OR (a.SALE_MAN > 0 and b.MOBILE like ‘${tell}%‘)
</if>
)
</select>
<!-- 客户搜索 end -->
<select id="findClientContactList" resultType="java.util.HashMap" parameterType="map">
select
c.ID as clientId,
c.NAME clientName,
c.short_name shortName,
c.OWN_COMPANY_ID companyId,
c.ADD_PROVINCE as province,
d.dict_value as type,
dt.dict_value as level,
c.SALE_MAN as saleMan,
c.IS_SHARED as isShared,
co.ID as contactId,
co.`NAME` as contactName,
co.MOBILE as mobile,
co.SEX as sex,
co.POSITION as position

from crm_client c
left join crm_contact co on c.ID=co.CLIENT_ID
left JOIN cm_dict_type d on d.DICT_CODE=c.type and d.type=‘Client_Type‘
left join cm_dict_type dt on dt.DICT_CODE=c.level and dt.type=‘Client_Level‘
where co.IS_DEFAULT_CONTACT =1 and c.OWN_COMPANY_ID=#{companyId,jdbcType=BIGINT}

<if test="outLevel != null" >
and c.`LEVEL` not in(${outLevel})
</if>

<if test="proId != null" >
and c.PRO_ID = #{proId,jdbcType=BIGINT}
</if>
<if test="addProvince != null" >
and c.ADD_PROVINCE like concat(‘%‘,#{addProvince,jdbcType=VARCHAR},‘%‘)
</if>
<if test="mainBusiness != null" >
and (select count(b.ID) from crm_main_business_client b where b.CLIENT_ID=c.ID and b.MAIN_BUSINESS_ID=#{mainBusiness,jdbcType=VARCHAR})>0
</if>
<if test="type != null" >
and c.TYPE = #{type,jdbcType=VARCHAR}
</if>
<if test="level != null" >
and c.LEVEL = #{level,jdbcType=VARCHAR}
</if>
<if test="likeName != null" >
and ( c.NAME like concat(‘%‘,#{likeName,jdbcType=VARCHAR},‘%‘) or co.NAME like concat(‘%‘,#{likeName,jdbcType=VARCHAR},‘%‘) )
</if>
ORDER BY c.CREATE_TIME desc
<include refid="Paging" />
</select>

<select id="findClientContactListCount" resultType="java.lang.Integer" parameterType="map">
SELECT count(1)
from crm_client c
left join crm_contact co on c.ID=co.CLIENT_ID
left JOIN cm_dict_type d on d.DICT_CODE=c.type and d.type=‘Client_Level‘
left join cm_dict_type dt on dt.DICT_CODE=c.level and dt.type=‘Client_Level‘
where co.IS_DEFAULT_CONTACT =1 and c.OWN_COMPANY_ID=#{companyId,jdbcType=BIGINT}
<if test="outLevel != null" >
and c.`LEVEL` not in(${outLevel})
</if>
<if test="proId != null" >
and c.PRO_ID = #{proId,jdbcType=BIGINT}
</if>
<if test="addProvince != null" >
and c.ADD_PROVINCE like concat(‘%‘,#{addProvince,jdbcType=VARCHAR},‘%‘)
</if>
<if test="mainBusiness != null" >
and (select count(b.ID) from crm_main_business_client b where b.CLIENT_ID=c.ID and b.MAIN_BUSINESS_ID=#{mainBusiness,jdbcType=VARCHAR})>0
</if>
<if test="type != null" >
and c.TYPE = #{type,jdbcType=VARCHAR}
</if>
<if test="level != null" >
and c.LEVEL = #{level,jdbcType=VARCHAR}
</if>
<if test="likeName != null" >
and ( c.NAME like concat(‘%‘,#{likeName,jdbcType=VARCHAR},‘%‘) or co.NAME like concat(‘%‘,#{likeName,jdbcType=VARCHAR},‘%‘) )
</if>
</select>

<resultMap id="ResultMapExport" type="com.xy.xyd.rest.crm.entity.CrmClientExport" >
<id column="ID" property="id" jdbcType="BIGINT" />
<result column="NAME" property="name" jdbcType="VARCHAR" />
<result column="CITY_ID" property="cityId" jdbcType="BIGINT" />
<result column="AREA_ID" property="areaId" jdbcType="BIGINT" />
<result column="PRO_ID" property="proId" jdbcType="BIGINT" />

<!-- 新增字段 -->
<result column="contactId" property="contactId" jdbcType="BIGINT" />
<result column="contactName" property="contactName" jdbcType="VARCHAR" />
<result column="title" property="title" jdbcType="VARCHAR" />
<result column="mobile" property="mobile" jdbcType="VARCHAR" />
<result column="sex" property="sex" jdbcType="INTEGER" />
<result column="position" property="position" jdbcType="VARCHAR" />
<result column="org" property="org" jdbcType="VARCHAR" />
<result column="mainRes" property="mainRes" jdbcType="VARCHAR" />
<result column="Qq" property="Qq" jdbcType="VARCHAR" />
<result column="email" property="email" jdbcType="VARCHAR" />
</resultMap>

<select id="exportClient" resultMap="ResultMapExport" parameterType="map">
select
c.ID ,
c.NAME ,
c.IS_SHARED ,
c.`LEVEL`,
co.ID as contactId,
co.`NAME` as contactName,
co.TENCENT_QQ as Qq,
co.EMAIL as email

from crm_client c
left join crm_contact co on c.ID=co.CLIENT_ID
where c.OWN_COMPANY_ID=#{companyId,jdbcType=BIGINT}
<if test="outLevel != null" >
and c.`LEVEL` not in(${outLevel})
</if>
<if test="proId != null" >
and c.PRO_ID = #{proId,jdbcType=BIGINT}
</if>
<if test="addProvince != null" >
and c.ADD_PROVINCE like concat(‘%‘,#{addProvince,jdbcType=VARCHAR},‘%‘)
</if>
<if test="mainBusiness != null" >
and (select count(b.ID) from crm_main_business_client b where b.CLIENT_ID=c.ID and b.MAIN_BUSINESS_ID=#{mainBusiness,jdbcType=VARCHAR})>0
</if>
<if test="type != null" >
and c.TYPE = #{type,jdbcType=VARCHAR}
</if>
<if test="level != null" >
and c.LEVEL = #{level,jdbcType=VARCHAR}
</if>
<if test="likeName != null" >
and ( c.NAME like concat(‘%‘,#{likeName,jdbcType=VARCHAR},‘%‘) or co.NAME like concat(‘%‘,#{likeName,jdbcType=VARCHAR},‘%‘) )
</if>
ORDER BY c.CREATE_TIME desc
</select>

<!-- 根据客户自动降级设置的条件:查询客户 {某个企业、多少天为跟踪的、指定级别的客户}c.CREATE_TIME < ‘‘ 过滤掉新创建的客户,其也没有符合条件的跟进记录-->
<select id="selectNotTrack" resultMap="ResultMap" parameterType="map">
select c.*
from crm_client c
where c.OWN_COMPANY_ID=#{ownCompanyId,jdbcType=BIGINT} and c.LEVEL=#{level,jdbcType=VARCHAR}
<!--铁单、重点客户: 有上级无下属的员工{才执行跑批:自动降级跑批使 -->
<if test="saleMan != null">
and c.SALE_MAN=#{saleMan,jdbcType=BIGINT}
</if>
<!-- 客户创建时间未达到指定天数,对应的日期,其必然不符合要求 -->
and date(c.LAST_CHANGE_TIME) <![CDATA[ < ]]> date(#{createTime,jdbcType=TIMESTAMP})
and not exists( <!-- 不存在跟踪记录,则说明,30天没有跟踪了 -->
<!-- 30天内的跟踪记录 -->
SELECT 1 from crm_track_recording r
where r.CLIENT_ID=c.ID and r.NEW_LEVEL=#{level,jdbcType=VARCHAR}
and r.NEW_SALE_MAN=c.SALE_MAN and
date( r.CREATE_TIME) <![CDATA[ > ]]> date(#{createTime,jdbcType=TIMESTAMP}) and r.TYPE=1
)
</select>

<!-- 根据客户自动降级设置的条件:查询客户 {某个企业、多少天未升级的、指定级别的客户}c.CREATE_TIME < ‘‘ 过滤掉新创建的客户,其也没有符合条件的跟进记录
r.OLD_LEVEL!=r.NEW_LEVEL 查询出升级记录
-->
<select id="selectNotUp" resultMap="ResultMap" parameterType="map">
select c.*
from crm_client c
where c.OWN_COMPANY_ID=#{ownCompanyId,jdbcType=BIGINT} and c.LEVEL=#{level,jdbcType=VARCHAR}
<!-- 客户创建时间未达到指定天数,对应的日期,其必然不符合要求 -->
and date(#{createTime,jdbcType=TIMESTAMP}) <![CDATA[ > ]]>date(c.LAST_CHANGE_TIME )

</select>

</mapper>

<?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.xy.xyd.rest.crm.repository.CrmClientRepository" >
<resultMap id="ResultMap" type="com.xy.xyd.rest.crm.entity.CrmClient" >
<id column="ID" property="id" jdbcType="BIGINT" />
<result column="NAME" property="name" jdbcType="VARCHAR" />
<result column="LATITUDE" property="latitude" jdbcType="DOUBLE" />
<result column="IS_DEL" property="isDel" jdbcType="INTEGER" />
<result column="CREATE_BY" property="createBy" jdbcType="BIGINT" />
<result column="CREATE_TIME" property="createTime" jdbcType="TIMESTAMP" />
<result column="MODIFY_BY" property="modifyBy" jdbcType="BIGINT" />
<result column="LAST_CHANGE_TIME" property="lastChangeTime" jdbcType="TIMESTAMP" />
</resultMap>

<sql id="Base_Column_List" >
ID, NAME, SHORT_NAME, COMMENT, CITY_ID, AREA_ID, PRO_ID,LAST_CHANGE_TIME
</sql>

<!--find查询列 -->
<sql id="Find_Column_List">
ID
</sql>

<sql id="Where_Clause">
<if test="id != null" >
and a.ID = #{id,jdbcType=BIGINT}
</if>
<if test="inClientIds != null">
and a.ID in (${inClientIds})
</if>
<if test="outClientIds != null">
and a.ID not in (${outClientIds})
</if>

<if test="proId != null" >
and PRO_ID = #{proId,jdbcType=BIGINT}
</if>
<if test="lastChangeTime != null" >
and a.LAST_CHANGE_TIME = #{lastChangeTime,jdbcType=TIMESTAMP}
</if>
</sql>

<sql id="Order_By">
order by
<if test="sort!=null">
<if test="sort==&quot;id&quot;">
a.ID ${order}
</if>
<if test="sort==&quot;name&quot;">
a.NAME ${order}
</if>
<if test="sort==&quot;sortOrder&quot;">
a.SORT_ORDER ${order}
</if>
</if>
<if test="sort==null">
a.ID
</if>
</sql>
<sql id="Paging">
<if test="firstResult!=null"> limit #{firstResult,jdbcType=DECIMAL} ,
#{offset,jdbcType=DECIMAL}
</if>
</sql>

<!--按Id查询 -->
<select id="selectById" resultMap="ResultMap" parameterType="Long">
select
<include refid="Base_Column_List" />
from crm_client a where id=#{id}
</select>

<!--按Id删除 -->
<delete id="deleteById" parameterType="Long">
delete a from crm_client a where id=#{id}
</delete>

<!--条件查询,只查询ID -->
<select id="selectToId" resultType="long" parameterType="map">
select
<include refid="Find_Column_List" />
from crm_client a where 1=1
<include refid="Where_Clause" />
<include refid="Order_By"/>
<include refid="Paging" />
</select>

<select id="select" resultMap="ResultMap" parameterType="map">
select
<include refid="Base_Column_List" />
from crm_client a
where 1=1
<include refid="Where_Clause" />
</select>

<!-- 同一家公司,在省的范围内,简称查重 ,如有重复,返回所有重复的客户简称及归属人姓名 -->
<select id="findRepeatListInProvince" resultType="java.util.Map" parameterType="map">
select
a.ID AS id,
a.NAME AS name,
a.SHORT_NAME AS shortName,
a.SALE_MAN AS saleMan
from crm_client a
where 1=1
<include refid="Where_Clause" />
<include refid="Paging" />
</select>

<select id="findClientInfo" resultType="java.util.Map" parameterType="map" >
select
a.NAME AS name,
a.SHORT_NAME AS shortName,
a.LATITUDE AS latitude,
b.DICT_VALUE AS typeValue,
a.SALE_MAN AS saleMan,
c.NAME AS saleManName,
a.LEVEL AS level,
d.DICT_VALUE AS levelValue,
a.INTRODUCTION AS introduction

from crm_client a
LEFT JOIN cm_dict_type b on a.TYPE = b.DICT_CODE AND b.type =‘Client_Type‘
LEFT JOIN cm_xyduser c on a.SALE_MAN = c.ID
LEFT JOIN cm_dict_type d on a.LEVEL = d.DICT_CODE AND d.type =‘Client_Level‘
where 1=1
<include refid="Where_Clause" />
</select>

<delete id="delete" parameterType="java.lang.Long" >
delete from crm_client
where ID = #{id,jdbcType=BIGINT}
</delete>

<insert id="save" parameterType="com.xy.xyd.rest.crm.entity.CrmClient" useGeneratedKeys="true" keyProperty="id">
insert into crm_client
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
ID,
</if>
<if test="name != null" >
NAME,
</if>
<if test="cityId != null" >
CITY_ID,
</if>
<if test="areaId != null" >
AREA_ID,
</if>
<if test="proId != null" >
PRO_ID,
</if>
<if test="lastChangeTime != null" >
LAST_CHANGE_TIME,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=BIGINT},
</if>
<if test="name != null" >
#{name,jdbcType=VARCHAR},
</if>
<if test="cityId != null" >
#{cityId,jdbcType=BIGINT},
</if>
<if test="areaId != null" >
#{areaId,jdbcType=BIGINT},
</if>
<if test="proId != null" >
#{proId,jdbcType=BIGINT},
</if>
<if test="lastChangeTime != null" >
#{lastChangeTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>

<update id="update" parameterType="com.xy.xyd.rest.crm.entity.CrmClient" >
update crm_client
<set >
<if test="name != null" >
NAME = #{name,jdbcType=VARCHAR},
</if>
<if test="cityId != null" >
CITY_ID = #{cityId,jdbcType=BIGINT},
</if>
<if test="areaId != null" >
AREA_ID = #{areaId,jdbcType=BIGINT},
</if>
<if test="proId != null" >
PRO_ID = #{proId,jdbcType=BIGINT},
</if>
<if test="lastChangeTime != null" >
LAST_CHANGE_TIME = #{lastChangeTime,jdbcType=TIMESTAMP},
</if>
</set>
where ID = #{id,jdbcType=BIGINT}
</update>

<!-- 批量修改 -->
<update id="updateBatch" parameterType="List" >
<foreach collection="list" item="obj" index="index" separator=" ; " >
update crm_client
<set >
<if test="obj.name != null" >
NAME = #{obj.name,jdbcType=VARCHAR},
</if>
<if test="obj.shortName != null" >
SHORT_NAME = #{obj.shortName,jdbcType=VARCHAR},
</if>
<if test="obj.ownCompanyId != null" >
OWN_COMPANY_ID = #{obj.ownCompanyId,jdbcType=BIGINT},
</if>

<if test="obj.proId != null" >
PRO_ID = #{obj.proId,jdbcType=BIGINT},
</if>
<if test="obj.lastChangeTime != null" >
LAST_CHANGE_TIME = #{obj.lastChangeTime,jdbcType=TIMESTAMP},
</if>
</set>
where ID = #{obj.id,jdbcType=BIGINT}
</foreach>
</update>

<select id="count" resultType="java.lang.Integer" parameterType="map" >
select count(1) from crm_client a
where 1=1
<include refid="Where_Clause" />
</select>

<select id="countShareClientNUmber" resultType="java.lang.Integer" parameterType="map" >
select count(*) from crm_client a
where 1=1
<if test="isShared != null" >
and a.IS_SHARED = #{isShared,jdbcType=INTEGER}
</if>
<if test="saleMan != null" >
and a.SALE_MAN = #{saleMan,jdbcType=BIGINT}
</if>
<!-- 级别筛选 -->
<if test="level != null" >
and a.LEVEL IN
<foreach item="levelArray" index="index" collection="level"
open="(" separator="," close=")">
#{levelArray}
</foreach>
</if>
</select>

<select id="findClientList" resultType="java.util.Map" parameterType="map">
select
distinct(a.ID) AS id,
a.NAME AS name,
b.MOBILE AS mobile,
a.SALE_MAN AS saleMan,
c.NAME AS saleManName,
a.IS_SHARED AS isShared,
a.LEVEL AS level,
d.DICT_VALUE AS levelValue,
date_format(a.CREATE_TIME,‘%Y%m%d%H%i%S‘) as createTime,
date_format(a.LAST_TRACK_TIME,‘%Y%m%d%H%i%S‘) as lastTrackTime
from crm_client a
LEFT JOIN crm_contact b on a.ID = b.CLIENT_ID AND b.IS_DEFAULT_CONTACT = 1
LEFT JOIN cm_xyduser c on a.SALE_MAN = c.ID
LEFT JOIN cm_dict_type d on a.LEVEL = d.DICT_CODE AND d.TYPE = ‘Client_Level‘
<if test="mainBusiness != null" >
inner JOIN crm_main_business_client e on a.ID = e.CLIENT_ID
</if>
where 1=1 and a.IS_DEL = 0 and a.SALE_MAN>-3
<!-- 省份筛选 -->
<if test="addProvince != null" >
and a.ADD_PROVINCE IN
<foreach item="typeArray" index="index" collection="addProvince"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>
<!-- 主营行业筛选 -->
<if test="mainBusiness != null" >
and e.MAIN_BUSINESS_ID IN
<foreach item="typeArray" index="index" collection="mainBusiness"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>
<!-- 归属筛选 -->
<if test="ids != null" >
and a.SALE_MAN IN
<foreach item="typeArray" index="index" collection="ids"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>
<if test="ownCompanyId != null" >
and a.OWN_COMPANY_ID = #{ownCompanyId,jdbcType=BIGINT}
</if>
<!-- 级别筛选 -->
<if test="level != null" >
and a.LEVEL IN
<foreach item="typeArray" index="index" collection="level"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>
<!-- 类型筛选 -->
<if test="type != null" >
and a.TYPE IN
<foreach item="typeArray" index="index" collection="type"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>
<!-- 跟踪日期 -->
<if test="endTrackTime != null" >
<!-- and ( a.LAST_TRACK_TIME IS NULL OR a.LAST_TRACK_TIME <![CDATA[ < ]]> #{endTrackTime,jdbcType=TIMESTAMP}) -->
and a.LAST_TRACK_TIME &lt;= #{endTrackTime,jdbcType=TIMESTAMP}
</if>
order by a.CREATE_TIME desc
<include refid="Paging" />
</select>

<select id="countClientListNumber" resultType="java.lang.Integer" parameterType="map">
select
count(distinct(a.ID))

from crm_client a
LEFT JOIN crm_contact b on a.ID = b.CLIENT_ID AND b.IS_DEFAULT_CONTACT = 1
LEFT JOIN cm_xyduser c on a.SALE_MAN = c.ID
LEFT JOIN cm_dict_type d on a.LEVEL = d.DICT_CODE AND d.TYPE = ‘Client_Level‘
<if test="mainBusiness != null" >
inner JOIN crm_main_business_client e on a.ID = e.CLIENT_ID
</if>
where 1=1 and a.IS_DEL = 0 and a.SALE_MAN>-3
<if test="item != null" >
and a.ITEM = #{item,jdbcType=VARCHAR}
</if>
<!-- 省份筛选 -->
<if test="addProvince != null" >
and a.ADD_PROVINCE IN
<foreach item="typeArray" index="index" collection="addProvince"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>
<!-- 主营行业筛选 -->
<if test="mainBusiness != null" >
and e.MAIN_BUSINESS_ID IN
<foreach item="typeArray" index="index" collection="mainBusiness"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>
<!-- 归属筛选 -->
<if test="ids != null" >
and a.SALE_MAN IN
<foreach item="typeArray" index="index" collection="ids"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>
<if test="ownCompanyId != null" >
and a.OWN_COMPANY_ID = #{ownCompanyId,jdbcType=BIGINT}
</if>
<!-- 级别筛选 -->
<if test="level != null" >
and a.LEVEL IN
<foreach item="typeArray" index="index" collection="level"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>
<!-- 跟踪日期 -->
<if test="endTrackTime != null" >
and (a.LAST_TRACK_TIME IS NULL OR a.LAST_TRACK_TIME <![CDATA[ < ]]> #{endTrackTime,jdbcType=BIGINT})
</if>
<!-- 类型筛选 -->
<if test="type != null" >
and a.TYPE IN
<foreach item="typeArray" index="index" collection="type"
open="(" separator="," close=")">
#{typeArray}
</foreach>
</if>

</select>

<!-- 客户搜索 begin zyf -->
<select id="selectSearchToId" resultType="long" parameterType="map">
select
a.ID
from crm_client a
<if test="tell != null" >
LEFT JOIN crm_contact b ON a.ID = b.CLIENT_ID
</if>
where 1=1
<if test="ownCompanyId != null" >
and a.OWN_COMPANY_ID = #{ownCompanyId,jdbcType=BIGINT}
</if>
<if test="userIds != null" >
and a.SALE_MAN in(${userIds})
</if>
<if test="isDel != null" >
and a.IS_DEL = #{isDel,jdbcType=INTEGER}
</if>
and(
<if test="name != null" >
a.NAME like ‘%${name}%‘
or a.SHORT_NAME like ‘%${name}%‘
</if>
<if test="tell != null" >
or a.TELL like ‘${tell}%‘
OR (a.SALE_MAN > 0 and b.MOBILE like ‘${tell}%‘)
</if>
)
<include refid="Order_By"/>
<include refid="Paging" />
</select>

<select id="selectSearchCount" resultType="java.lang.Integer" parameterType="map" >
select COUNT(DISTINCT a.ID) from crm_client a
<if test="tell != null" >
LEFT JOIN crm_contact b ON a.ID = b.CLIENT_ID
</if>
where 1=1 and a.SALE_MAN > -3
<if test="ownCompanyId != null" >
and a.OWN_COMPANY_ID = #{ownCompanyId,jdbcType=BIGINT}
</if>
<if test="userIds != null" >
and a.SALE_MAN in(${userIds})
</if>
<if test="isDel != null" >
and a.IS_DEL = #{isDel,jdbcType=INTEGER}
</if>
and (
<if test="name != null" >
a.NAME like ‘%${name}%‘
or a.SHORT_NAME like ‘%${name}%‘
</if>
<if test="tell != null" >
or a.TELL like ‘${tell}%‘
OR (a.SALE_MAN > 0 and b.MOBILE like ‘${tell}%‘)
</if>
)
</select>
<!-- 客户搜索 end -->
<select id="findClientContactList" resultType="java.util.HashMap" parameterType="map">
select
c.ID as clientId,
c.NAME clientName,
c.short_name shortName,
c.OWN_COMPANY_ID companyId,
c.ADD_PROVINCE as province,
d.dict_value as type,
dt.dict_value as level,
c.SALE_MAN as saleMan,
c.IS_SHARED as isShared,
co.ID as contactId,
co.`NAME` as contactName,
co.MOBILE as mobile,
co.SEX as sex,
co.POSITION as position

from crm_client c
left join crm_contact co on c.ID=co.CLIENT_ID
left JOIN cm_dict_type d on d.DICT_CODE=c.type and d.type=‘Client_Type‘
left join cm_dict_type dt on dt.DICT_CODE=c.level and dt.type=‘Client_Level‘
where co.IS_DEFAULT_CONTACT =1 and c.OWN_COMPANY_ID=#{companyId,jdbcType=BIGINT}

<if test="outLevel != null" >
and c.`LEVEL` not in(${outLevel})
</if>

<if test="proId != null" >
and c.PRO_ID = #{proId,jdbcType=BIGINT}
</if>
<if test="addProvince != null" >
and c.ADD_PROVINCE like concat(‘%‘,#{addProvince,jdbcType=VARCHAR},‘%‘)
</if>
<if test="mainBusiness != null" >
and (select count(b.ID) from crm_main_business_client b where b.CLIENT_ID=c.ID and b.MAIN_BUSINESS_ID=#{mainBusiness,jdbcType=VARCHAR})>0
</if>
<if test="type != null" >
and c.TYPE = #{type,jdbcType=VARCHAR}
</if>
<if test="level != null" >
and c.LEVEL = #{level,jdbcType=VARCHAR}
</if>
<if test="likeName != null" >
and ( c.NAME like concat(‘%‘,#{likeName,jdbcType=VARCHAR},‘%‘) or co.NAME like concat(‘%‘,#{likeName,jdbcType=VARCHAR},‘%‘) )
</if>
ORDER BY c.CREATE_TIME desc
<include refid="Paging" />
</select>

<select id="findClientContactListCount" resultType="java.lang.Integer" parameterType="map">
SELECT count(1)
from crm_client c
left join crm_contact co on c.ID=co.CLIENT_ID
left JOIN cm_dict_type d on d.DICT_CODE=c.type and d.type=‘Client_Level‘
left join cm_dict_type dt on dt.DICT_CODE=c.level and dt.type=‘Client_Level‘
where co.IS_DEFAULT_CONTACT =1 and c.OWN_COMPANY_ID=#{companyId,jdbcType=BIGINT}
<if test="outLevel != null" >
and c.`LEVEL` not in(${outLevel})
</if>
<if test="proId != null" >
and c.PRO_ID = #{proId,jdbcType=BIGINT}
</if>
<if test="addProvince != null" >
and c.ADD_PROVINCE like concat(‘%‘,#{addProvince,jdbcType=VARCHAR},‘%‘)
</if>
<if test="mainBusiness != null" >
and (select count(b.ID) from crm_main_business_client b where b.CLIENT_ID=c.ID and b.MAIN_BUSINESS_ID=#{mainBusiness,jdbcType=VARCHAR})>0
</if>
<if test="type != null" >
and c.TYPE = #{type,jdbcType=VARCHAR}
</if>
<if test="level != null" >
and c.LEVEL = #{level,jdbcType=VARCHAR}
</if>
<if test="likeName != null" >
and ( c.NAME like concat(‘%‘,#{likeName,jdbcType=VARCHAR},‘%‘) or co.NAME like concat(‘%‘,#{likeName,jdbcType=VARCHAR},‘%‘) )
</if>
</select>

<resultMap id="ResultMapExport" type="com.xy.xyd.rest.crm.entity.CrmClientExport" >
<id column="ID" property="id" jdbcType="BIGINT" />
<result column="NAME" property="name" jdbcType="VARCHAR" />
<result column="CITY_ID" property="cityId" jdbcType="BIGINT" />
<result column="AREA_ID" property="areaId" jdbcType="BIGINT" />
<result column="PRO_ID" property="proId" jdbcType="BIGINT" />

<!-- 新增字段 -->
<result column="contactId" property="contactId" jdbcType="BIGINT" />
<result column="contactName" property="contactName" jdbcType="VARCHAR" />
<result column="title" property="title" jdbcType="VARCHAR" />
<result column="mobile" property="mobile" jdbcType="VARCHAR" />
<result column="sex" property="sex" jdbcType="INTEGER" />
<result column="position" property="position" jdbcType="VARCHAR" />
<result column="org" property="org" jdbcType="VARCHAR" />
<result column="mainRes" property="mainRes" jdbcType="VARCHAR" />
<result column="Qq" property="Qq" jdbcType="VARCHAR" />
<result column="email" property="email" jdbcType="VARCHAR" />
</resultMap>

<select id="exportClient" resultMap="ResultMapExport" parameterType="map">
select
c.ID ,
c.NAME ,
c.IS_SHARED ,
c.`LEVEL`,
co.ID as contactId,
co.`NAME` as contactName,
co.TENCENT_QQ as Qq,
co.EMAIL as email

from crm_client c
left join crm_contact co on c.ID=co.CLIENT_ID
where c.OWN_COMPANY_ID=#{companyId,jdbcType=BIGINT}
<if test="outLevel != null" >
and c.`LEVEL` not in(${outLevel})
</if>
<if test="proId != null" >
and c.PRO_ID = #{proId,jdbcType=BIGINT}
</if>
<if test="addProvince != null" >
and c.ADD_PROVINCE like concat(‘%‘,#{addProvince,jdbcType=VARCHAR},‘%‘)
</if>
<if test="mainBusiness != null" >
and (select count(b.ID) from crm_main_business_client b where b.CLIENT_ID=c.ID and b.MAIN_BUSINESS_ID=#{mainBusiness,jdbcType=VARCHAR})>0
</if>
<if test="type != null" >
and c.TYPE = #{type,jdbcType=VARCHAR}
</if>
<if test="level != null" >
and c.LEVEL = #{level,jdbcType=VARCHAR}
</if>
<if test="likeName != null" >
and ( c.NAME like concat(‘%‘,#{likeName,jdbcType=VARCHAR},‘%‘) or co.NAME like concat(‘%‘,#{likeName,jdbcType=VARCHAR},‘%‘) )
</if>
ORDER BY c.CREATE_TIME desc
</select>

<!-- 根据客户自动降级设置的条件:查询客户 {某个企业、多少天为跟踪的、指定级别的客户}c.CREATE_TIME < ‘‘ 过滤掉新创建的客户,其也没有符合条件的跟进记录-->
<select id="selectNotTrack" resultMap="ResultMap" parameterType="map">
select c.*
from crm_client c
where c.OWN_COMPANY_ID=#{ownCompanyId,jdbcType=BIGINT} and c.LEVEL=#{level,jdbcType=VARCHAR}
<!--铁单、重点客户: 有上级无下属的员工{才执行跑批:自动降级跑批使 -->
<if test="saleMan != null">
and c.SALE_MAN=#{saleMan,jdbcType=BIGINT}
</if>
<!-- 客户创建时间未达到指定天数,对应的日期,其必然不符合要求 -->
and date(c.LAST_CHANGE_TIME) <![CDATA[ < ]]> date(#{createTime,jdbcType=TIMESTAMP})
and not exists( <!-- 不存在跟踪记录,则说明,30天没有跟踪了 -->
<!-- 30天内的跟踪记录 -->
SELECT 1 from crm_track_recording r
where r.CLIENT_ID=c.ID and r.NEW_LEVEL=#{level,jdbcType=VARCHAR}
and r.NEW_SALE_MAN=c.SALE_MAN and
date( r.CREATE_TIME) <![CDATA[ > ]]> date(#{createTime,jdbcType=TIMESTAMP}) and r.TYPE=1
)
</select>

<!-- 根据客户自动降级设置的条件:查询客户 {某个企业、多少天未升级的、指定级别的客户}c.CREATE_TIME < ‘‘ 过滤掉新创建的客户,其也没有符合条件的跟进记录
r.OLD_LEVEL!=r.NEW_LEVEL 查询出升级记录
-->
<select id="selectNotUp" resultMap="ResultMap" parameterType="map">
select c.*
from crm_client c
where c.OWN_COMPANY_ID=#{ownCompanyId,jdbcType=BIGINT} and c.LEVEL=#{level,jdbcType=VARCHAR}
<!-- 客户创建时间未达到指定天数,对应的日期,其必然不符合要求 -->
and date(#{createTime,jdbcType=TIMESTAMP}) <![CDATA[ > ]]>date(c.LAST_CHANGE_TIME )

</select>

</mapper>

时间: 2024-10-03 13:45:25

完整mybatis应用的相关文章

浅谈mybatis如何半自动化解耦和ORM实现

在JAVA发展过程中,涌现出一系列的ORM框架,JPA,Hibernate,Mybatis和Spring jdbc,本系列,将来研究Mybatis. 通过研究mybatis源码,可将mybatis的大致架构总结为下图: 1.根据Mybatis源码,将其抽象为三层:基础支持层,核心处理层和接口层 2.基础支持层包括:数据源.事务管理.日志.类型转换.缓存.Bind.解析器等 3.核心处理层包括:配置解析.配置映射.SQL解析.SQL执行.结果集映射.插件等 4.接口层主要提供JAVA API 在本

Spring mvc整合mybatis基于mysql数据库实现用户增删改查及其分页显示的完整入门实例【转】

Spring mvc整合mybatis例子, 基于mysql数据库实现对用户的增.删.改.查,及分页显示的完整例子. 查询显示用户 添加用户 更新用户 官方验证: 项目截图 必须修改applicationContext.xml中mysql的配置为本地的,否则启动失败. 另外jar包多一个ehcache.jar无关紧要,删除即可. 1. 使用阿里巴巴Druid连接池(高效.功能强大.可扩展性好的数据库连接池.监控数据库访问性能.支持Common-Logging.Log4j和JdkLog,监控数据库

Spring整合MyBatis完整示例

为了梳理前面学习的内容<Spring整合MyBatis(Maven+MySQL)一>与<Spring整合MyBatis(Maven+MySQL)二>,做一个完整的示例完成一个简单的图书管理功能,主要使用到的技术包含Spring.MyBatis.Maven.MySQL及简单MVC等.最后的运行效果如下所示: 项目结构如下: 一.新建一个基于Maven的Web项目 1.1.创建一个简单的Maven项目,项目信息如下: 1.2.修改层面信息,在项目上右键选择属性,再选择“Project

Spring集成MyBatis完整示例

为了梳理前面学习的<Spring整合MyBatis(Maven+MySQL)一>与<Spring整合MyBatis(Maven+MySQL)二>中的内容,准备做一个完整的示例完成一个简单的图书管理功能,主要使用到的技术包含Spring.MyBatis.Maven与MySQL等.最后的运行效果如下: 项目结构如下: 一.新建一个基于Maven的Web项目 1.1.创建一个简单的Maven项目,项目信息如下: 1.2.修改层面信息,在项目上右键选择属性,再选择“Project Face

mybatis调用mysql存储过程返回多结果集(完整)

最近,有个开发提了个需求,希望中间件支持调用mysql存储过程时支持多结果集返回,因为某些原因我们使用了不少的存储过程,很多复杂的逻辑目前来看交互非常的多,所以从当前的现状来说,这个需求还是蛮合理的.中午抽空特地搜了下,整合完整示例如下: 1.创建测试存储过程 delimiter $$ CREATE PROCEDURE sp_multi_resultset(IN p_operator_company_no int, IN p_operator_no int, OUT p_error_code v

MyBatis源码分析-SQL语句执行的完整流程

MyBatis 是支持定制化 SQL.存储过程以及高级映射的优秀的持久层框架.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis 可以对配置和原生Map使用简单的 XML 或注解,将接口和 Java 的 POJOs(Plain Old Java Objects,普通的 Java对象)映射成数据库中的记录.如何新建MyBatis源码工程请点击MyBatis源码分析-IDEA新建MyBatis源码工程. MyBatis框架主要完成的是以下2件事情: 根据JD

【JavaWeb】Spring+SpringMVC+MyBatis+SpringSecurity+EhCache+JCaptcha 完整Web基础框架(前言)

一直希望能够搭建一个完整的,基础Web框架,方便日后接一些外快的时候,能够省时省力,终于花了一周的时间,把这个东西搞定了.特此写下此博客,一来是纪念,二来是希望能够为别人提供方便.顺带说一下,恩,组合框架的各个部分用的版本有的是最新的,有的则不是,不敢保证最新版本下,按照这个整合方式,不会报错... 简单介绍一下,本框架的基本功能点: Spring:整个框架的主体部分,这个自不用说. SpringMVC:MVC部分我还是比较喜欢Spring的. MyBatis:选型的时候选择这个ORM主要也是考

一个完整的Mybatis分页解决方案

[布景] 号码大全项目结构是 SpringMVC+Mybatis, 需求是想选用自定义的分页标签,关键词挖掘工具一起,要尽量少的影响事务程序开发的. 假如你已经运用了JS结构( 如:Ext,EasyUi等)自带的分页机能,这篇文章帮助能够不大,因为JS结构供给了固定的接口. [关于疑问] 大多数分页器会运用在查询页面,要思考以下疑问: 1)分页时是要随时带有近来一次查询条件 2)不能影响现有的sql,相似aop的作用 3)mybatis供给了通用的阻拦接口,要挑选恰当的阻拦办法和时点 4)尽量少

MyBatis拦截器打印不带问号的完整sql语句方法

? 1 /* Preparing: SELECT * FROM tb_user WHERE id = ? AND user_name = ?  <br>   目标是打印:SELECT * FROM tb_user WHERE id = 1000059081 AND user_name = '积极'<br>*/ 这部分代码只是拦截了查询和更新,如果想对其他语句进行拦截,在@Intercepts中添加对应方法即可 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1