BOOT客户管理系统IDEA开发(二)

本文详细介绍了在IDEA中开发BOOT客户管理系统时,DAO的配置过程,包括BaseDictDao、UserDao和CustomerDao的XML配置及接口设定。接着,文章讲解了配置各类Java类和接口,如NavigationTag、Page、LoginInterceptor等,以及Service和Controller的相关实现。
摘要由CSDN通过智能技术生成

六、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> 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值