Boot-crm管理系统开发教程(三)

    (ps:前两章咱们已经把管理员登陆和查看用户的功能实现了,那么今天咱们将要实现:添加用户,删除用户,和修改用户功能)html

    因为Cusomer的POJO类型已经写好了,因此此次咱们以前从CustomerController下手!!!mysql

        添加用户功能

    ①在CutsomerController类中编写customerCreate方法,并在方法名上头写上请求映射路径(@RequestMapping("/customer/create.action")) ,和@ResponseBody。sql

     ②在customerCreate方法中先获取用户session,而后将当前用户id存储在客户对象中,而后调用customer.setCust_create_id()方法将当前用户id存储在客户对象中,接着为了获得mysql里面的时间戳,咱们用了Timestamp对象获取一个yyyy/MM/dd HH:mm:ss 的时间格式,而后将这个Timestamp对象装载到customer.setCust_createtime()方法中,最后再判断Service层中受影响的行数来判断是否建立用户成功,这样咱们CustomerController中的建立客户就写完了,还记得第二章教程中的流程图吗?如今咱们就得去Service层中编写接口,并实现接口类。session

     ③在CustomerService接口中建立createCustomer方法(注意此处的返回值类型是int类型),而后去CustomerServiceImpl实现类中实现该接口方法。app

        ④在CustomerDao接口中也一样编写createCustomer方法,而后在CustomerDao.xml中编写添加客户的sql语句,代码以下:框架

<!-- 添加客户 -->
	<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>

      ⑤写到这里,咱们的添加用户的功能就写完了。回顾一下咱们是怎么写的:"首先咱们是从CustomerController下手的!在该方法中咱们建立了createCustomer方法,而后再到Service层中编写createCustomer该接口方法,而后让CustomerServiceImpl实现类去实现它,最后在回到CustomerDao中建立一样的方法,而后重点是在CustomerDao.xml中的sql语句"。        spa

    更新用户功能,删除用户功能

           通过以前查看用户和建立用户功能,相信你们对SSM框架的运用已经了如指掌了,那么省下的两个功能,我将Controller和sql的代码粘贴到这,其余的你们本身写写试试,写不出来也不要紧,源码已经分享到CSDN上了,待会会把网址贴在文章底部。
            Controller:
/*
	 * 更新客户
	 */
	@RequestMapping("/customer/update.action")
	@ResponseBody
	public String customerUpdate(Customer customer)
	{
		int rows=customerService.updateCustomer(customer);
		if(rows>0)
		{
			return "OK";
		}else {
			return "FAIL";
		}
	}
	/*
	 * 删除客户
	 */
	@RequestMapping("/customer/delete.action")
	@ResponseBody
	public String customerDelete(Integer id)
	{
		int rows=customerService.deleteCustomer(id);
		if(rows>0)
		{
			return "OK";
		}else {
			return "FAIL";
		}
	}

                XML:.net

<!-- 更新客户 -->
	<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>

           源码下载地址: Boot-crm管理系统源码下载code

相关文章
相关标签/搜索