六、DAO的配置
BaseDictDao.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.itheima.core.dao.BaseDictDao" >
<!-- 根据类别代码查询 -->
<select id="selectBaseDictByTypeCode" resultType="baseDict"
parameterType="String" >
select * from base_dict where dict_type_code = #{
typecode}
</select>
</mapper>
BaseDictDao 接口
package com.itheima.core.dao;
import java.util.List;
import com.itheima.core.po.BaseDict;
/**
* 数据字典
*/
public interface BaseDictDao {
// 根据类别代码查询数据字典
public List<BaseDict> selectBaseDictByTypeCode(String typecode);
}
UserDao.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.itheima.core.dao.UserDao" >
<!-- 查询用户 -->
<select id="findUser" parameterType="String" resultType="user">
select *
from sys_user
where user_code = #{
usercode}
and user_password =#{
password}
and user_state = '1'
</select>
</mapper>
UserDao 接口
package com.itheima.core.dao;
import org.apache.ibatis.annotations.Param;
import com.itheima.core.po.User;
/**
* 用户DAO层接口
*/
public interface UserDao {
/**
* 通过账号和密码查询用户
*/
public User findUser(@Param("usercode") String usercode,
@Param("password") String password);
}
CustomerDao.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.itheima.core.dao.CustomerDao">
<!--SQL片段 -->
<sql id="selectCustomerListWhere">
<where>
<if test="cust_name != null" >
cust_name like "%"#{
cust_name}"%"
</if>
<if test="cust_source != null" >
and cust_source = #{
cust_source}
</if>
<if test="cust_industry != null" >
and cust_industry = #{
cust_industry}
</if>
<if test="cust_level != null" >
and cust_level = #{
cust_level}
</if>
</where>
</sql>
<!-- 查询客户列表 -->
<select id="selectCustomerList" parameterType="customer"
resultType="customer">
SELECT
cust_id,
cust_name,
cust_user_id,
cust_create_id,
b.dict_item_name cust_source,
c.dict_item_name cust_industry,
d.dict_item_name cust_level,
cust_linkman,
cust_phone,
cust_mobile,
cust_createtime
FROM
customer a
LEFT JOIN (
SELECT
dict_id,
dict_item_name
FROM
base_dict
WHERE
dict_type_code = '002'
) b ON a.cust_source = b.dict_id
LEFT JOIN (
SELECT
dict_id,
dict_item_name
FROM
base_dict
WHERE
dict_type_code = '001·'
) c ON a.cust_industry = c.dict_id
LEFT JOIN (
SELECT
dict_id,
dict_item_name
FROM
base_dict
WHERE
dict_type_code = '006'
) d ON a.cust_level = d.dict_id
<include refid="selectCustomerListWhere"/>
<!-- 执行分页查询 -->
<if test="start !=null and rows != null">
limit #{
start},#{
rows}
</if>
</select>
<!-- 查询客户总数 -->
<select id="selectCustomerListCount" parameterType="customer"
resultType="Integer">
select count(*) from customer
<include refid="selectCustomerListWhere"/>
</select>
<!-- 添加客户 -->
<insert id="createCustomer" parameterType="customer">
insert into customer(
cust_name,
cust_user_id,
cust_create_id,
cust_source,
cust_industry,
cust_level,
cust_linkman,
cust_phone,
cust_mobile,
cust_zipcode,
cust_address,
cust_createtime
)
values(#{
cust_name},
#{
cust_user_id},
#{
cust_create_id},
#{
cust_source},
#{
cust_industry},
#{
cust_level},
#{
cust_linkman},
#{
cust_phone},
#{
cust_mobile},
#{
cust_zipcode},
#{
cust_address},
#{
cust_createtime}
)
</insert>
<!-- 根据id获取客户信息 -->
<select id="getCustomerById" parameterType="Integer"
resultType="customer">
select * from customer where cust_id = #{
id}
</select>
<!-- 更新客户 -->
<update id="updateCustomer" parameterType="customer">
update customer
<set>
<if test="cust_name!=null">
cust_name=#{
cust_name},
</if>
<if test="cust_user_id!=null">
cust_user_id=#{
cust_user_id},
</if>
<if test="cust_create_id!=null">
cust_create_id=#{
cust_create_id},
</if>
<if test="cust_source!=null">
cust_source=#{
cust_source},
</if>
<if test="cust_industry!=null">
cust_industry=#{
cust_industry},
</if>
<if test="cust_level!=null">
cust_level=#{
cust_level},
</if>
<if test="cust_linkman!=null">
cust_linkman=#{
cust_linkman},
</if>
<if test="cust_phone!=null">
cust_phone=#{
cust_phone},
</if>
<if test="cust_mobile!=null">
cust_mobile=#{
cust_mobile},
</if>
<if test="cust_zipcode!=null">
cust_zipcode=#{
cust_zipcode},
</if>
<if test="cust_address!=null">
cust_address=#{
cust_address},
</if>
<if test="cust_createtime!=null">
cust_createtime=#{
cust_createtime},
</if>
</set>
where cust_id=#{
cust_id}
</update>
<!-- 删除客户 -->
<delete id="deleteCustomer" parameterType="Integer">
delete from customer where cust_id=#{
id}
</delete>
</mapper>
CustomerDao
package com.itheima.core.dao;
import java.util.List;
import com.itheima.core.po.Customer;
/**
* Customer接口
*/
public interface CustomerDao {
// 客户列表
public List<Customer>