客户管理
更新客户
更新规则如下
1.实现效果
1.1 业务员操作效果
1.2 管理员操作效果
2.实现步骤
2.1 customer.jsp
改变修改按钮的地址信息
<a href="/customer/customerUpdate?id=${dto.customer.customerId }" class="tablelink">修改</a>
2.2 CustomerController
内容不用改变,和添加的时候一样
@RequestMapping("/customerUpdate")
public String customerUpdate(Integer id,Model model){
customerService.getUpdateInfo(id, model);
return "customer/customerUpdate";
}
2.2 CustomerServiceImpl
注意:和添加时有调整
/**
* 新增客户
* 查询 所有的角色是业务员的用户
* 查询 常用区间 基础数据
* 修改客户
* 查询 所有的角色是业务员的用户
* 查询 常用区间 基础数据
* 根据客户ID 查询详细信息
*/
@Override
public void getUpdateInfo(Integer id, Model m) {
// 1.查询所有具有业务员角色的用户信息
List<User> users = userService.queryUserByRoleName(Constant.ROLE_SALESMAN);
// 2.查询 常用区间的基础数据
List<BasicData> intervals = basicService.getBasicDataByParentName(Constant.BASIC_COMMON_INTERVAL);
if(id!=null && id > 0){
Customer customer = new Customer();
customer.setCustomerId(id);
// 查询更新需要的数据
List<CustomerDto> list = customerMapper.queryView(customer);
if(list != null&& list.size()==1){
m.addAttribute("dto", list.get(0));
}
}
m.addAttribute("users", users);
m.addAttribute("intervals", intervals);
}
2.3 CustomerMapper.xml
给queryView添加了查询条件
<select id="queryView" resultMap="baseCustomerDto" parameterType="com.bobo.pojo.Customer" >
select
t1.customer_id
,t1.customer_name
,t1.address
,t1.c_sex
,t1.email
,t1.base_id
,t1.id_card
,t1.mobile_phone
,t1.order_id
,t1.remark
,t1.user_id
,t1.user_name
,t1.real_name
,t1.base_name
from v_customer t1
<where>
<if test="userId !=null and userId > 0">
user_id = #{userId}
</if>
<if test="customerId !=null and customerId > 0 ">
customer_id = #{customerId}
</if>
</where>
</select>
2.4 customerUpdate.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="/css/style.css" rel="stylesheet" type="text/css" />
<link href="/css/select.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/jquery.idTabs.min.js"></script>
<script type="text/javascript" src="/js/select-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
$(".select1").uedSelect({
width : 345
});
$(".select2").uedSelect({
width : 167
});
$(".select3").uedSelect({
width : 100
});
});
</script>
</head>
<body>
<div class="place">
<span>位置:</span>
<ul class="placeul">
<li><a href="/">首页</a></li>
<li><a href="/user/query">客户管理</a></li>
</ul>
</div>
<div class="formbody">
<div class="formtitle">
<span>新增客户信息</span>
</div>
<form action="/customer/saveOrUpdate">
<ul class="forminfo">
<input type="hidden" name="customerId" value="${dto.customer.customerId}">
<li><label>客户姓名</label>
<input name="customerName" type="text" value="${dto.customer.customerName}" class="dfinput" />
<i></i>
</li>
<li><label>客户电话</label>
<input name="mobilePhone" type="text" value="${dto.customer.mobilePhone}" class="dfinput" />
</li>
<li><label>性别 ${dto.customer.cSex}</label>
<input type="radio" name="cSex" value="0" ${dto.customer.cSex eq true?"checked":"" }> 男
<input type="radio" name="cSex" value="1" ${dto.customer.cSex eq false?"checked":"" }> 女
</li>
<li><label>电子邮箱</label>
<input name="email" type="text" class="dfinput" value="${dto.customer.email}"/><i></i>
</li>
<li><label>通讯地址</label>
<input name="address" type="text" class="dfinput" value="${dto.customer.address}"/><i></i>
</li>
<li><label>身份证号码</label>
<input name="idCard" type="text" class="dfinput" value="${dto.customer.idCard}"/><i></i>
</li>
<li><label>业务员</label>
<div class="vocation">
<select class="select1" name="userId">
<!-- 和新增客户区分开 -->
<c:if test="${empty dto}">
<c:forEach items="${ users}" var="user">
<option value="${user.userId }" >
${user.realName }
</option>
</c:forEach>
</c:if>
<c:if test="${not empty dto }">
<shiro:hasAnyRoles name="业务员,操作员">
<option value="${dto.customer.userId }" >${dto.salesMan }</option>
</shiro:hasAnyRoles>
<shiro:hasRole name="管理员">
<c:forEach items="${ users}" var="user">
<option value="${user.userId }" ${user.userId eq dto.customer.userId?"selected":"" } >
${user.realName }
</option>
</c:forEach>
</shiro:hasRole>
</c:if>
</select>
</div>
<i></i>
</li>
<li><label>常用区间</label>
<div class="vocation">
<select class="select1" name="baseId">
<c:forEach items="${ intervals}" var="it">
<option value="${it.baseId }" ${it.baseId eq dto.customer.baseId?"selected":"" }>
${it.baseName }
</option>
</c:forEach>
</select>
</div>
<i></i>
</li>
<li><label>备注</label>
<textarea name="remark" cols="" rows="" class="textinput" >
${dto.customer.remark }
</textarea>
</li>
<li><label> </label>
<input name="" type="submit"
class="btn" value="确认保存" /></li>
</ul>
</form>
</div>
<div style="display: none">
<script src='http://v7.cnzz.com/stat.php?id=155540&web_id=155540'
language='JavaScript' charset='gb2312'></script>
</div>
</body>
</html>
2.5 CustomerController
保存修改的内容
@RequestMapping("/saveOrUpdate")
public String saveOrUpdate(Customer customer) throws IOException{
if(customer.getCustomerId()!=null && !"".equals(customer.getCustomerId())){
// 更新
customerService.updateCustomer(customer);
}else{
// 添加
customerService.addCustomer(customer);
}
return "success";
}
2.6 ICustomerService
public void updateCustomer(Customer customer)
2.7 CustomerServiceImpl
@Override
public void updateCustomer(Customer customer) {
// TODO Auto-generated method stub
customerMapper.updateByPrimaryKey(customer);
}
ok 实现~