ssm项目——CRM系统修改与删除客户

本章是最后一章,CRM系统最后两个小功能,修改客户与删除客户

一、修改客户

修改客户有两件事需要做:

一是在弹出的页面中回显选择客户的信息

 根据jsp代码编写代码

由jsp可知,使用的ajax请求,根据这个请求可以开发后台逻辑,提供给前端页面进行调用

Controller:

        //修改页面,注意responseBody
	@RequestMapping("/customer/edit.action")
	public @ResponseBody Customer edit(Integer id) {
		Customer customer = customerService.selectCustomerByID(id);
		return customer;
	}

Controller需要注意@ResponseBody别忘写了

Service:

        @Override
	public Customer selectCustomerByID(Integer id) {
		// TODO Auto-generated method stub
		return customerDao.selectCustomerByID(id);
	}

Dao:

        //根据ID查询对象
	public Customer selectCustomerByID(Integer id);

Mapper:

        <!-- //根据ID查询对象
   	public Customer selectCustomerByID(Integer id); -->
	<select id="selectCustomerByID" parameterType="Integer" resultType="Customer">
		select * from customer
		<where>
			cust_id = #{id}
		</where>
	</select>

这样就完成了客户信息回显的功能

 

二是保存修改的信息

也是很简单的功能,只要把客户信息保存就好,主要是mapper中select语句需要注意判断空值,而且根据jsp代码可知传的是Customer对象,而不是id,不要弄错了,直接放代码了

Controller:

	//保存修改信息
	@RequestMapping("/customer/update.action")
	public @ResponseBody String update(Customer cust) {
		customerService.updateCustomerByID(cust);
		return "ok";
	}

Service:


	@Override
	public void updateCustomerByID(Customer cust) {
		// TODO Auto-generated method stub
		customerDao.updateCustomerByID(cust);
	}

Dao:

	//根据Id修改对象
	public void updateCustomerByID(Customer cust);

Mapper:

	<!-- 	//根据Id修改对象
	public void updateCustomerByID(Integer id); -->
	<select id="updateCustomerByID" parameterType="Integer">
		update customer
		SET
		<if test="cust_name !=null and cust_name != ''">
			`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 and cust_source != ''">
			`cust_source` = #{cust_source},
		</if>
		<if test="cust_industry !=null and cust_industry != ''">
			`cust_industry` = #{cust_industry},
		</if>
		<if test="cust_level !=null and cust_level != ''">
			`cust_level` = #{cust_level},
		</if>
		<if test="cust_linkman !=null and cust_linkman != ''">
			`cust_linkman` = #{cust_linkman},
		</if>
		<if test="cust_phone !=null and cust_phone != ''">
			`cust_phone` = #{cust_phone},
		</if>
		<if test="cust_mobile !=null and cust_mobile != ''">
			`cust_mobile` = #{cust_mobile},
		</if>
		<if test="cust_zipcode !=null and cust_zipcode != ''">
			`cust_zipcode` = #{cust_zipcode},
		</if>
		<if test="cust_address !=null and cust_address != ''">
			`cust_address` = #{cust_address},
		</if>
		`cust_createtime` = NOW()
		WHERE
		(`cust_id` = #{cust_id});
	</select>

 

二、删除客户

也是非常简单的功能,根据jsp写好Controller就好了,直接放代码了

Controller:

	//删除页面
	@RequestMapping("/customer/delete.action")
	public @ResponseBody String delete(Integer id) {
		customerService.deleteCustomerByID(id);
		return "ok";
	}

Service:

	@Override
	public void deleteCustomerByID(Integer id) {
		// TODO Auto-generated method stub
		customerDao.deleteCustomerByID(id);
	}

Dao:

	//根据Id删除对象
	public void deleteCustomerByID(Integer id);

Mapper:

	<select id="deleteCustomerByID" parameterType="Integer">
		delete from customer where cust_id = #{id}
	</select>

至此,一个简单的基于SSM框架的crm小项目就完成了。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值