新增客户
前言测试数据准备控制操作权限效劳器逻辑
定义常量类service层处置 ICustomerService定义CustomerServiceImpl中实现IUserService接口UserServiceImpl实现UserMapper接口UserMapper.xmlIBasicServiceBasicServiceImplBasicDataMapper接口BasicDataMapper.xmlControllercustomer.jsp页面
测试
前言
测试数据准备
创建对应的测试数据如下
控制操作权限
通过上面的规则理解我们发现,可以操作新增客户的角色有业务员和操作员,而管理员可以操作修改客户的业务员。这样可以看到“新增客户”菜单按钮的就只能是具有“业务员”和“操作员”角色的用户。所以如下设置。
left.jsp- <%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
- <shiro:hasAnyRolesname="业务员,操作员"><li><cite></cite><ahref="/customer/customerUpdate"target="rightFrame">新增客户</a><i></i></li></shiro:hasAnyRoles>
复制代码
index.jsp中显示当前账号登录信息
简单测试:admin登录看不到“新增客户”菜单:
效劳器逻辑
定义常量类
- /**
- * 常量工具类
- * @author JustinNeil
- */publicclassConstant{publicstaticfinal String ROLE_SALESMAN ="业务员";publicstaticfinal String ROLE_OPERATOR ="操作员";publicstaticfinal String ROLE_ADMIN ="管理员";publicstaticfinal String BASIC_COMMON_INTERVAL ="常用区间";}
复制代码 service层处置 ICustomerService定义
- package com.yjn.service;import org.springframework.ui.Model;publicinterfaceICustomerService{/**
- * 查询更新或者添加需要的信息
- */publicvoidgetUpdateInfo(Integer id,Model m);publicvoidaddCustomer(Customer customer);}
复制代码 CustomerServiceImpl中实现
- package com.yjn.service.impl;import java.util.List;import javax.annotation.Resource;import org.springframework.stereotype.Service;import org.springframework.ui.Model;import com.yjn.mapper.CustomerMapper;import com.yjn.pojo.BasicData;import com.yjn.pojo.Customer;import com.yjn.pojo.User;import com.yjn.service.IBasicService;import com.yjn.service.ICustomerService;import com.yjn.service.IUserService;import com.yjn.utils.Constant;@ServicepublicclassCustomerServiceImplimplementsICustomerService{@Resourceprivate CustomerMapper customerMapper;@Resourceprivate IUserService userService;@Resourceprivate IBasicService basicService;/**
- * 新增客户
- * 查询 所有的角色是业务员的用户
- * 查询 常用区间 根底数据
- * 修改客户
- * 查询 所有的角色是业务员的用户
- * 查询 常用区间 根底数据
- * 根据客户ID 查询详细信息
- */@OverridepublicvoidgetUpdateInfo(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 = customerMapper.selectByPrimaryKey(id);
- m.addAttribute("customer", customer);}
- m.addAttribute("users", users);
- m.addAttribute("intervals", intervals);}}
复制代码 IUserService接口
- /**
- * 根据角色名称查询对应的用户信息
- * @param roleName
- * @return
- */public List<User>queryUserByRoleName(String roleName);
复制代码 UserServiceImpl实现
- @Overridepublic List<User>queryUserByRoleName(String roleName){return userMapper.queryUserByRoleName(roleName);}
复制代码 UserMapper接口
- List<User>queryUserByRoleName(String roleName);
复制代码 UserMapper.xml
- <selectid="queryUserByRoleName"resultMap="BaseResultMap">
- select *
- from t_user
- where user_id in (
- select user_id from t_user_role where role_id = (
- select role_id from t_role where role_name = #{param1}
- )
- )
- </select>
复制代码 IBasicService
- /**
- * 根据大类名称查询对应的小类
- * @param parentName
- * @return
- */public List<BasicData>getBasicDataByParentName(String parentName);
复制代码 BasicServiceImpl
- @Overridepublic List<BasicData>getBasicDataByParentName(String basicCommonInterval){return basicMapper.getBasicDataByParentName(basicCommonInterval);}
复制代码 BasicDataMapper接口
- List<BasicData>getBasicDataByParentName(String basicCommonInterval);
复制代码 BasicDataMapper.xml
- <select id="getBasicDataByParentName" resultMap="BaseResultMap">
- select *
- from t_basicdata
- where parent_id in (
- select base_id from t_basicdata where base_name = #{param1})</select>
复制代码 Controller
- package com.yjn.controller;import javax.annotation.Resource;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import com.yjn.service.ICustomerService;@Controller@RequestMapping("/customer")publicclassCustomerController{@Resourceprivate ICustomerService customerService;@RequestMapping("/customerUpdate")public String customerUpdate(Integer id,Model model){
- customerService.getUpdateInfo(id, model);return"customer/customerUpdate";}@RequestMapping("/saveOrUpdate")public String saveOrUpdate(Customer customer)throws IOException{if(customer.getCustomerId()!=null &&!"".equals(customer.getCustomerId())){// 更新}else{// 添加
- customerService.addCustomer(customer);}return"success";}}
复制代码 customer.jsp页面
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
- <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><metahttp-equiv="Content-Type"content="text/html; charset=utf-8"/><title>无标题文档</title><linkhref="/css/style.css"rel="stylesheet"type="text/css"/><linkhref="/css/select.css"rel="stylesheet"type="text/css"/><scripttype="text/javascript"src="/js/jquery.js"></script><scripttype="text/javascript"src="/js/jquery.idTabs.min.js"></script><scripttype="text/javascript"src="/js/select-ui.min.js"></script><scripttype="text/javascript">$(document).ready(function(e){$(".select1").uedSelect({
- width :345});$(".select2").uedSelect({
- width :167});$(".select3").uedSelect({
- width :100});});</script></head><body><divclass="place"><span>位置:</span><ulclass="placeul"><li><ahref="/">首页</a></li><li><ahref="/customer/query">客户管理</a></li></ul></div><divclass="formbody"><divclass="formtitle"><span>新增客户信息</span></div><formaction="/customer/saveOrUpdate"><ulclass="forminfo"><li><label>客户姓名</label><inputname="customerName"type="text"class="dfinput"/><i></i></li><li><label>客户电话</label><inputname="mobilePhone"type="text"class="dfinput"/></li><li><label>性别</label><inputtype="radio"name="cSex"value="0"checked> 男
- <inputtype="radio"name="cSex"value="1"> 女
- </li><li><label>电子邮箱</label><inputname="email"type="text"class="dfinput"/><i></i></li><li><label>通讯地址</label><inputname="address"type="text"class="dfinput"/><i></i></li><li><label>身份证号码</label><inputname="idCard"type="text"class="dfinput"/><i></i></li><li><label>业务员</label><divclass="vocation"><selectclass="select1"name="userId"><c:forEachitems="${ users}"var="user"><optionvalue="${user.userId }">
- ${user.realName }
- </option></c:forEach></select></div><i></i></li><li><label>常用区间</label><divclass="vocation"><selectclass="select1"name="baseId"><c:forEachitems="${ intervals}"var="interval"><optionvalue="${interval.baseId }">
- ${interval.baseName }
- </option></c:forEach></select></div><i></i></li><li><label>备注</label><textareaname="remark"cols=""rows=""class="textinput"></textarea></li><li><label> </label><inputname=""type="submit"class="btn"value="确认保管"/></li></ul></form></div><divstyle="display: none"><scriptsrc='http://v7.cnzz.com/stat.php?id=155540&web_id=155540'language='JavaScript'charset='gb2312'></script></div></body></html>
复制代码 测试
添加胜利 |