正在显示
25 个修改的文件
包含
778 行增加
和
184 行删除
| @@ -17,6 +17,7 @@ | @@ -17,6 +17,7 @@ | ||
| 17 | <properties> | 17 | <properties> | 
| 18 | <java.version>1.8</java.version> | 18 | <java.version>1.8</java.version> | 
| 19 | <spring-cloud.version>Greenwich.BUILD-SNAPSHOT</spring-cloud.version> | 19 | <spring-cloud.version>Greenwich.BUILD-SNAPSHOT</spring-cloud.version> | 
| 20 | + <fastjson_version>1.2.28</fastjson_version> | ||
| 20 | </properties> | 21 | </properties> | 
| 21 | 22 | ||
| 22 | <dependencies> | 23 | <dependencies> | 
| @@ -85,6 +86,11 @@ | @@ -85,6 +86,11 @@ | ||
| 85 | <artifactId>commons-codec</artifactId> | 86 | <artifactId>commons-codec</artifactId> | 
| 86 | <version>1.11</version> | 87 | <version>1.11</version> | 
| 87 | </dependency> | 88 | </dependency> | 
| 89 | + <dependency> | ||
| 90 | + <groupId>com.alibaba</groupId> | ||
| 91 | + <artifactId>fastjson</artifactId> | ||
| 92 | + <version>${fastjson_version}</version> | ||
| 93 | + </dependency> | ||
| 88 | <!-- tools--> | 94 | <!-- tools--> | 
| 89 | <!-- alibaba的druid数据库连接池 --> | 95 | <!-- alibaba的druid数据库连接池 --> | 
| 90 | <dependency> | 96 | <dependency> | 
| @@ -26,8 +26,8 @@ public class ImfLog { | @@ -26,8 +26,8 @@ public class ImfLog { | ||
| 26 | public String Home(Model model){ | 26 | public String Home(Model model){ | 
| 27 | PERMISSION msg = new PERMISSION(); | 27 | PERMISSION msg = new PERMISSION(); | 
| 28 | msg.setDescription("权限描述"); | 28 | msg.setDescription("权限描述"); | 
| 29 | - msg.setPermissionName("权限名称"); | ||
| 30 | - msg.setPermissionSign("权限路径"); | 29 | + msg.setName("权限名称"); | 
| 30 | + msg.setPermissionOrder("权限路径"); | ||
| 31 | model.addAttribute("msg", msg); | 31 | model.addAttribute("msg", msg); | 
| 32 | return "home"; | 32 | return "home"; | 
| 33 | } | 33 | } | 
| 1 | +package com.tianbo.warehouse.controller; | ||
| 2 | + | ||
| 3 | +import com.github.pagehelper.PageInfo; | ||
| 4 | +import com.tianbo.warehouse.controller.response.ResultJson; | ||
| 5 | +import com.tianbo.warehouse.dao.PERMISSIONMapper; | ||
| 6 | +import com.tianbo.warehouse.model.PERMISSION; | ||
| 7 | +import com.tianbo.warehouse.model.ROLE; | ||
| 8 | +import com.tianbo.warehouse.service.PermissionService; | ||
| 9 | +import org.apache.cxf.annotations.Logging; | ||
| 10 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 11 | +import org.springframework.security.core.context.SecurityContextHolder; | ||
| 12 | +import org.springframework.security.core.userdetails.UserDetails; | ||
| 13 | +import org.springframework.web.bind.annotation.*; | ||
| 14 | + | ||
| 15 | +import java.util.List; | ||
| 16 | +import java.util.Map; | ||
| 17 | + | ||
| 18 | + | ||
| 19 | +@Logging | ||
| 20 | +@RestController() | ||
| 21 | +public class PermssionController { | ||
| 22 | + | ||
| 23 | + @Autowired | ||
| 24 | + PermissionService permissionService; | ||
| 25 | + | ||
| 26 | + @GetMapping("/perm/list") | ||
| 27 | + public PageInfo<PERMISSION> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1") | ||
| 28 | + int pageNum, | ||
| 29 | + @RequestParam(value = "pageSize",required = false,defaultValue = "5") | ||
| 30 | + int pageSize){ | ||
| 31 | + return permissionService.findAll(pageNum,pageSize); | ||
| 32 | + | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + @PostMapping("/perm/add") | ||
| 36 | + public ResultJson add(@RequestBody PERMISSION permission){ | ||
| 37 | + int i =permissionService.insertSelective(permission); | ||
| 38 | + | ||
| 39 | + ResultJson resultJson = new ResultJson(); | ||
| 40 | + if (1==i){ | ||
| 41 | + resultJson = new ResultJson("200","添加账户成功"); | ||
| 42 | + }else { | ||
| 43 | + resultJson = new ResultJson("500","insert faild"); | ||
| 44 | + } | ||
| 45 | + return resultJson; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + @GetMapping("/perm/userMenus") | ||
| 49 | + public Map<String,Object> getLoginUserMenus(){ | ||
| 50 | + | ||
| 51 | + try{ | ||
| 52 | + UserDetails userDetails =(UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | ||
| 53 | + int i; | ||
| 54 | + }catch (Exception e){ | ||
| 55 | + e.printStackTrace(); | ||
| 56 | + } | ||
| 57 | + Map<String,Object> menuMap = permissionService.getUserMenus(); | ||
| 58 | + return menuMap; | ||
| 59 | + } | ||
| 60 | +} | 
| 1 | +package com.tianbo.warehouse.controller; | ||
| 2 | + | ||
| 3 | +import com.github.pagehelper.PageInfo; | ||
| 4 | +import com.tianbo.warehouse.controller.response.ResultJson; | ||
| 5 | +import com.tianbo.warehouse.model.ROLE; | ||
| 6 | +import com.tianbo.warehouse.service.RoleService; | ||
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | +import org.springframework.web.bind.annotation.*; | ||
| 9 | + | ||
| 10 | +@RestController() | ||
| 11 | +public class RoleController { | ||
| 12 | + | ||
| 13 | + @Autowired | ||
| 14 | + RoleService roleService; | ||
| 15 | + | ||
| 16 | + @GetMapping("/role/list") | ||
| 17 | + public PageInfo<ROLE> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1") | ||
| 18 | + int pageNum, | ||
| 19 | + @RequestParam(value = "pageSize",required = false,defaultValue = "5") | ||
| 20 | + int pageSize){ | ||
| 21 | + return roleService.findAll(pageNum,pageSize); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + @PostMapping("/role/add") | ||
| 25 | + public ResultJson add(@RequestBody ROLE role){ | ||
| 26 | + int i =roleService.insertSelective(role); | ||
| 27 | + | ||
| 28 | + ResultJson resultJson = new ResultJson(); | ||
| 29 | + if (1==i){ | ||
| 30 | + resultJson = new ResultJson("200","添加账户成功"); | ||
| 31 | + }else { | ||
| 32 | + resultJson = new ResultJson("500","insert faild"); | ||
| 33 | + } | ||
| 34 | + return resultJson; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | +} | 
| 1 | package com.tianbo.warehouse.controller; | 1 | package com.tianbo.warehouse.controller; | 
| 2 | 2 | ||
| 3 | import com.github.pagehelper.PageInfo; | 3 | import com.github.pagehelper.PageInfo; | 
| 4 | +import com.tianbo.warehouse.controller.response.ResultJson; | ||
| 4 | import com.tianbo.warehouse.model.USERS; | 5 | import com.tianbo.warehouse.model.USERS; | 
| 5 | import com.tianbo.warehouse.service.UserService; | 6 | import com.tianbo.warehouse.service.UserService; | 
| 7 | +import org.bouncycastle.asn1.ASN1Sequence; | ||
| 8 | +import org.bouncycastle.asn1.ocsp.ResponseData; | ||
| 6 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; | 
| 7 | import org.springframework.security.core.context.SecurityContextHolder; | 10 | import org.springframework.security.core.context.SecurityContextHolder; | 
| 11 | +import org.springframework.security.core.userdetails.User; | ||
| 8 | import org.springframework.security.core.userdetails.UserDetails; | 12 | import org.springframework.security.core.userdetails.UserDetails; | 
| 9 | -import org.springframework.web.bind.annotation.GetMapping; | ||
| 10 | -import org.springframework.web.bind.annotation.RequestParam; | ||
| 11 | -import org.springframework.web.bind.annotation.RestController; | 13 | +import org.springframework.web.bind.annotation.*; | 
| 12 | 14 | ||
| 15 | +import javax.servlet.http.HttpServletRequest; | ||
| 16 | +import javax.servlet.http.HttpServletResponse; | ||
| 13 | import java.util.List; | 17 | import java.util.List; | 
| 14 | 18 | ||
| 15 | @RestController | 19 | @RestController | 
| @@ -21,7 +25,7 @@ public class UserController { | @@ -21,7 +25,7 @@ public class UserController { | ||
| 21 | @GetMapping("/user/list") | 25 | @GetMapping("/user/list") | 
| 22 | public PageInfo<USERS> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1") | 26 | public PageInfo<USERS> list(@RequestParam(value = "pageNum",required = false,defaultValue = "1") | 
| 23 | int pageNum, | 27 | int pageNum, | 
| 24 | - @RequestParam(value = "pageSize",required = false,defaultValue = "10") | 28 | + @RequestParam(value = "pageSize",required = false,defaultValue = "5") | 
| 25 | int pageSize){ | 29 | int pageSize){ | 
| 26 | return userService.selectAllUser(pageNum,pageSize); | 30 | return userService.selectAllUser(pageNum,pageSize); | 
| 27 | } | 31 | } | 
| @@ -32,4 +36,42 @@ public class UserController { | @@ -32,4 +36,42 @@ public class UserController { | ||
| 32 | UserDetails userDetails =(UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | 36 | UserDetails userDetails =(UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | 
| 33 | return "欢迎回来:"+userDetails.getUsername(); | 37 | return "欢迎回来:"+userDetails.getUsername(); | 
| 34 | } | 38 | } | 
| 39 | + | ||
| 40 | + @PutMapping("/user/edit") | ||
| 41 | + public ResultJson updateUserById(@RequestBody USERS user){ | ||
| 42 | + int i = userService.updateByPrimaryKeySelective(user); | ||
| 43 | + ResultJson resultJson = new ResultJson(); | ||
| 44 | + if (1==i){ | ||
| 45 | + resultJson = new ResultJson("200","success"); | ||
| 46 | + }else { | ||
| 47 | + resultJson = new ResultJson("500","update faild"); | ||
| 48 | + } | ||
| 49 | + return resultJson; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + @PostMapping("/user/add") | ||
| 53 | + public ResultJson addUser(@RequestBody USERS user,HttpServletRequest request,HttpServletResponse response){ | ||
| 54 | + int i = userService.insertSelective(user); | ||
| 55 | + ResultJson resultJson = new ResultJson(); | ||
| 56 | + if (1==i){ | ||
| 57 | + resultJson = new ResultJson("200","新建账户成功"); | ||
| 58 | + }else { | ||
| 59 | + resultJson = new ResultJson("500","insert faild"); | ||
| 60 | + } | ||
| 61 | + return resultJson; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @DeleteMapping("/user/del") | ||
| 65 | + public ResultJson delUser(@RequestBody USERS user,HttpServletRequest request,HttpServletResponse response){ | ||
| 66 | + //String username = getusername(); | ||
| 67 | + int i = userService.deleteByPrimaryKey(user.getUserId()); | ||
| 68 | + ResultJson resultJson = new ResultJson(); | ||
| 69 | + if (1==i){ | ||
| 70 | + resultJson = new ResultJson("200","删除账户成功"); | ||
| 71 | + }else { | ||
| 72 | + resultJson = new ResultJson("500","delete faild"); | ||
| 73 | + } | ||
| 74 | + return resultJson; | ||
| 75 | + } | ||
| 76 | + | ||
| 35 | } | 77 | } | 
| 1 | +package com.tianbo.warehouse.controller.response; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSON; | ||
| 4 | +import org.springframework.core.MethodParameter; | ||
| 5 | +import org.springframework.http.MediaType; | ||
| 6 | +import org.springframework.http.converter.HttpMessageConverter; | ||
| 7 | +import org.springframework.http.server.ServerHttpRequest; | ||
| 8 | +import org.springframework.http.server.ServerHttpResponse; | ||
| 9 | +import org.springframework.web.bind.annotation.ControllerAdvice; | ||
| 10 | +import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 统一拦截response接口返回数据 | ||
| 14 | + */ | ||
| 15 | +//@ControllerAdvice | ||
| 16 | +public class RestControllerResponseAdvice implements ResponseBodyAdvice<Object>{ | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * //判断支持的类型,因为我们定义的BaseResponseVo 里面的data可能是任何类型,这里就不判断统一放过 | ||
| 20 | + * 如果你想对执行的返回体进行操作,可将上方的Object换成你自己的类型 | ||
| 21 | + * @param returnType | ||
| 22 | + * @param converterType | ||
| 23 | + * @return | ||
| 24 | + */ | ||
| 25 | + @Override | ||
| 26 | + public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType){ | ||
| 27 | + return true; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response){ | ||
| 32 | + // 对body进行封装处理 | ||
| 33 | + if (body instanceof String) { | ||
| 34 | + String msg = (String) body; | ||
| 35 | + ResultJson resultJson = new ResultJson("-1", msg); | ||
| 36 | + // 因为在controller层中返回的是String类型,这边如果换成ResultJson的话,会导致StringMessageConverter方法类型转换异常,所以这边将对象转成字符串 | ||
| 37 | + return JSON.toJSONString(resultJson); | ||
| 38 | + } else if (body instanceof Object) { | ||
| 39 | + Object data = (Object) body; | ||
| 40 | + ResultJson resultJson = new ResultJson(data); | ||
| 41 | + return resultJson; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + return body; | ||
| 45 | + } | ||
| 46 | +} | 
| 1 | +package com.tianbo.warehouse.controller.response; | ||
| 2 | + | ||
| 3 | +import java.io.Serializable; | ||
| 4 | + | ||
| 5 | +public class ResultJson implements Serializable{ | ||
| 6 | + private static final long serialVersionUID = 1L; | ||
| 7 | + | ||
| 8 | + // 状态码 正确为0 | ||
| 9 | + private String code = "0"; | ||
| 10 | + // 错误描述 | ||
| 11 | + private String msg = ""; | ||
| 12 | + // 返回对象 | ||
| 13 | + private Object data = ""; | ||
| 14 | + | ||
| 15 | + public ResultJson() { | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + public ResultJson(String code) { | ||
| 19 | + this.code = code; | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + public ResultJson(String code, String msg) { | ||
| 23 | + this.code = code; | ||
| 24 | + this.msg = msg; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public ResultJson(Object data) { | ||
| 28 | + this.data = data; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public ResultJson(String code, String msg, Object data) { | ||
| 32 | + this.code = code; | ||
| 33 | + this.msg = msg; | ||
| 34 | + this.data = data; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public String getCode() { | ||
| 38 | + return code; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public void setCode(String code) { | ||
| 42 | + this.code = code; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public String getMsg() { | ||
| 46 | + return msg; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public void setMsg(String msg) { | ||
| 50 | + this.msg = msg; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public Object getData() { | ||
| 54 | + return data; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public void setData(Object data) { | ||
| 58 | + this.data = data; | ||
| 59 | + } | ||
| 60 | +} | 
| @@ -20,6 +20,8 @@ public interface PERMISSIONMapper { | @@ -20,6 +20,8 @@ public interface PERMISSIONMapper { | ||
| 20 | 20 | ||
| 21 | List<PERMISSION> findAll(); | 21 | List<PERMISSION> findAll(); | 
| 22 | 22 | ||
| 23 | + List<PERMISSION> getAllMenus(); | ||
| 24 | + | ||
| 23 | List<PERMISSION> findByUserId(Integer userId); | 25 | List<PERMISSION> findByUserId(Integer userId); | 
| 24 | 26 | ||
| 25 | List<String> findRoleListByUrl(String permissionUrl); | 27 | List<String> findRoleListByUrl(String permissionUrl); | 
| 1 | package com.tianbo.warehouse.model; | 1 | package com.tianbo.warehouse.model; | 
| 2 | 2 | ||
| 3 | +import java.util.List; | ||
| 4 | + | ||
| 3 | public class PERMISSION { | 5 | public class PERMISSION { | 
| 4 | private Integer permissionId; | 6 | private Integer permissionId; | 
| 5 | 7 | ||
| 6 | - private String permissionName; | 8 | + private String name; | 
| 7 | 9 | ||
| 8 | - private String permissionSign; | 10 | + private String permissionOrder; | 
| 9 | 11 | ||
| 10 | private String description; | 12 | private String description; | 
| 11 | 13 | ||
| 12 | - private String groupName; | 14 | + private Boolean ismenu; | 
| 15 | + | ||
| 16 | + private Boolean hidden; | ||
| 13 | 17 | ||
| 14 | private Integer parentId; | 18 | private Integer parentId; | 
| 15 | 19 | ||
| @@ -17,34 +21,32 @@ public class PERMISSION { | @@ -17,34 +21,32 @@ public class PERMISSION { | ||
| 17 | 21 | ||
| 18 | private String url; | 22 | private String url; | 
| 19 | 23 | ||
| 20 | - private String ext1; | 24 | + private String method; | 
| 21 | 25 | ||
| 22 | - private String ext2; | 26 | + private String iconCls; | 
| 23 | 27 | ||
| 24 | - private String ext3; | 28 | + private String component; | 
| 29 | + | ||
| 30 | + private List<PERMISSION> children; | ||
| 25 | 31 | ||
| 26 | public Integer getPermissionId() { | 32 | public Integer getPermissionId() { | 
| 27 | return permissionId; | 33 | return permissionId; | 
| 28 | } | 34 | } | 
| 29 | 35 | ||
| 30 | - public void setPermissionId(Integer permissionId) { | ||
| 31 | - this.permissionId = permissionId; | ||
| 32 | - } | ||
| 33 | - | ||
| 34 | - public String getPermissionName() { | ||
| 35 | - return permissionName; | 36 | + public String getName() { | 
| 37 | + return name; | ||
| 36 | } | 38 | } | 
| 37 | 39 | ||
| 38 | - public void setPermissionName(String permissionName) { | ||
| 39 | - this.permissionName = permissionName == null ? null : permissionName.trim(); | 40 | + public void setName(String name) { | 
| 41 | + this.name = name; | ||
| 40 | } | 42 | } | 
| 41 | 43 | ||
| 42 | - public String getPermissionSign() { | ||
| 43 | - return permissionSign; | 44 | + public String getPermissionOrder() { | 
| 45 | + return permissionOrder; | ||
| 44 | } | 46 | } | 
| 45 | 47 | ||
| 46 | - public void setPermissionSign(String permissionSign) { | ||
| 47 | - this.permissionSign = permissionSign == null ? null : permissionSign.trim(); | 48 | + public void setPermissionOrder(String permissionOrder) { | 
| 49 | + this.permissionOrder = permissionOrder; | ||
| 48 | } | 50 | } | 
| 49 | 51 | ||
| 50 | public String getDescription() { | 52 | public String getDescription() { | 
| @@ -55,12 +57,12 @@ public class PERMISSION { | @@ -55,12 +57,12 @@ public class PERMISSION { | ||
| 55 | this.description = description == null ? null : description.trim(); | 57 | this.description = description == null ? null : description.trim(); | 
| 56 | } | 58 | } | 
| 57 | 59 | ||
| 58 | - public String getGroupName() { | ||
| 59 | - return groupName; | 60 | + public Boolean getIsmenu() { | 
| 61 | + return ismenu; | ||
| 60 | } | 62 | } | 
| 61 | 63 | ||
| 62 | - public void setGroupName(String groupName) { | ||
| 63 | - this.groupName = groupName == null ? null : groupName.trim(); | 64 | + public void setIsmenu(Boolean ismenu) { | 
| 65 | + this.ismenu = ismenu; | ||
| 64 | } | 66 | } | 
| 65 | 67 | ||
| 66 | public Integer getParentId() { | 68 | public Integer getParentId() { | 
| @@ -87,28 +89,35 @@ public class PERMISSION { | @@ -87,28 +89,35 @@ public class PERMISSION { | ||
| 87 | this.url = url == null ? null : url.trim(); | 89 | this.url = url == null ? null : url.trim(); | 
| 88 | } | 90 | } | 
| 89 | 91 | ||
| 90 | - public String getExt1() { | ||
| 91 | - return ext1; | 92 | + public String getMethod() { | 
| 93 | + return method; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public void setMethod(String method) { | ||
| 97 | + this.method = method; | ||
| 92 | } | 98 | } | 
| 93 | 99 | ||
| 94 | - public void setExt1(String ext1) { | ||
| 95 | - this.ext1 = ext1 == null ? null : ext1.trim(); | 100 | + public String getIconCls() { | 
| 101 | + return iconCls; | ||
| 96 | } | 102 | } | 
| 97 | 103 | ||
| 98 | - public String getExt2() { | ||
| 99 | - return ext2; | 104 | + public void setIconCls(String iconCls) { | 
| 105 | + this.iconCls = iconCls; | ||
| 100 | } | 106 | } | 
| 101 | 107 | ||
| 102 | - public void setExt2(String ext2) { | ||
| 103 | - this.ext2 = ext2 == null ? null : ext2.trim(); | 108 | + public String getComponent() { | 
| 109 | + return component; | ||
| 104 | } | 110 | } | 
| 105 | 111 | ||
| 106 | - public String getExt3() { | ||
| 107 | - return ext3; | 112 | + public void setComponent(String component) { | 
| 113 | + this.component = component; | ||
| 108 | } | 114 | } | 
| 109 | 115 | ||
| 110 | - public void setExt3(String ext3) { | ||
| 111 | - this.ext3 = ext3 == null ? null : ext3.trim(); | 116 | + public List<PERMISSION> getChildren() { | 
| 117 | + return children; | ||
| 112 | } | 118 | } | 
| 113 | 119 | ||
| 120 | + public void setChildren(List<PERMISSION> children) { | ||
| 121 | + this.children = children; | ||
| 122 | + } | ||
| 114 | } | 123 | } | 
| @@ -35,11 +35,11 @@ public class USERS implements UserDetails { | @@ -35,11 +35,11 @@ public class USERS implements UserDetails { | ||
| 35 | 35 | ||
| 36 | private String userface; | 36 | private String userface; | 
| 37 | 37 | ||
| 38 | - private String ext1; | 38 | + private String realname; | 
| 39 | 39 | ||
| 40 | - private String ext2; | 40 | + private String email; | 
| 41 | 41 | ||
| 42 | - private String ext3; | 42 | + private Integer age; | 
| 43 | 43 | ||
| 44 | private List<ROLE> roles; | 44 | private List<ROLE> roles; | 
| 45 | 45 | ||
| @@ -135,28 +135,28 @@ public class USERS implements UserDetails { | @@ -135,28 +135,28 @@ public class USERS implements UserDetails { | ||
| 135 | this.userface = userface == null ? null : userface.trim(); | 135 | this.userface = userface == null ? null : userface.trim(); | 
| 136 | } | 136 | } | 
| 137 | 137 | ||
| 138 | - public String getExt1() { | ||
| 139 | - return ext1; | 138 | + public String getRealname() { | 
| 139 | + return realname; | ||
| 140 | } | 140 | } | 
| 141 | 141 | ||
| 142 | - public void setExt1(String ext1) { | ||
| 143 | - this.ext1 = ext1 == null ? null : ext1.trim(); | 142 | + public void setRealname(String realname) { | 
| 143 | + this.realname = realname; | ||
| 144 | } | 144 | } | 
| 145 | 145 | ||
| 146 | - public String getExt2() { | ||
| 147 | - return ext2; | 146 | + public String getEmail() { | 
| 147 | + return email; | ||
| 148 | } | 148 | } | 
| 149 | 149 | ||
| 150 | - public void setExt2(String ext2) { | ||
| 151 | - this.ext2 = ext2 == null ? null : ext2.trim(); | 150 | + public void setEmail(String email) { | 
| 151 | + this.email = email; | ||
| 152 | } | 152 | } | 
| 153 | 153 | ||
| 154 | - public String getExt3() { | ||
| 155 | - return ext3; | 154 | + public Integer getAge() { | 
| 155 | + return age; | ||
| 156 | } | 156 | } | 
| 157 | 157 | ||
| 158 | - public void setExt3(String ext3) { | ||
| 159 | - this.ext3 = ext3 == null ? null : ext3.trim(); | 158 | + public void setAge(Integer age) { | 
| 159 | + this.age = age; | ||
| 160 | } | 160 | } | 
| 161 | 161 | ||
| 162 | public List<ROLE> getRoles() { | 162 | public List<ROLE> getRoles() { | 
| @@ -176,8 +176,8 @@ public class USERS implements UserDetails { | @@ -176,8 +176,8 @@ public class USERS implements UserDetails { | ||
| 176 | } | 176 | } | 
| 177 | 177 | ||
| 178 | /** | 178 | /** | 
| 179 | - * 账户未过期 | ||
| 180 | - * @return | 179 | + * | 
| 180 | + * @return 账户未过期 | ||
| 181 | */ | 181 | */ | 
| 182 | @Override | 182 | @Override | 
| 183 | public boolean isAccountNonExpired(){ | 183 | public boolean isAccountNonExpired(){ | 
| @@ -185,17 +185,17 @@ public class USERS implements UserDetails { | @@ -185,17 +185,17 @@ public class USERS implements UserDetails { | ||
| 185 | } | 185 | } | 
| 186 | 186 | ||
| 187 | /** | 187 | /** | 
| 188 | - * 账户未锁定 | ||
| 189 | - * @return | 188 | + * | 
| 189 | + * @return 账户未锁定 | ||
| 190 | */ | 190 | */ | 
| 191 | @Override | 191 | @Override | 
| 192 | public boolean isAccountNonLocked(){ | 192 | public boolean isAccountNonLocked(){ | 
| 193 | return true; | 193 | return true; | 
| 194 | } | 194 | } | 
| 195 | 195 | ||
| 196 | - /**密码未过期 | 196 | + /** | 
| 197 | * | 197 | * | 
| 198 | - * @return | 198 | + * @return 密码未过期 | 
| 199 | */ | 199 | */ | 
| 200 | @Override | 200 | @Override | 
| 201 | public boolean isCredentialsNonExpired(){ | 201 | public boolean isCredentialsNonExpired(){ | 
| @@ -203,8 +203,8 @@ public class USERS implements UserDetails { | @@ -203,8 +203,8 @@ public class USERS implements UserDetails { | ||
| 203 | } | 203 | } | 
| 204 | 204 | ||
| 205 | /** | 205 | /** | 
| 206 | - * //账户可用 | ||
| 207 | - * @return | 206 | + * | 
| 207 | + * @return 账户可用 | ||
| 208 | */ | 208 | */ | 
| 209 | @Override | 209 | @Override | 
| 210 | public boolean isEnabled(){ | 210 | public boolean isEnabled(){ | 
| @@ -212,8 +212,8 @@ public class USERS implements UserDetails { | @@ -212,8 +212,8 @@ public class USERS implements UserDetails { | ||
| 212 | } | 212 | } | 
| 213 | 213 | ||
| 214 | /** | 214 | /** | 
| 215 | - * user的权限列表 | ||
| 216 | - * @return | 215 | + * | 
| 216 | + * @return user的权限列表 | ||
| 217 | */ | 217 | */ | 
| 218 | @Override | 218 | @Override | 
| 219 | public Collection<? extends GrantedAuthority> getAuthorities(){ | 219 | public Collection<? extends GrantedAuthority> getAuthorities(){ | 
| @@ -36,24 +36,42 @@ public class MyAccessDecisionManager implements AccessDecisionManager{ | @@ -36,24 +36,42 @@ public class MyAccessDecisionManager implements AccessDecisionManager{ | ||
| 36 | c = iter.next(); | 36 | c = iter.next(); | 
| 37 | needRole = c.getAttribute(); | 37 | needRole = c.getAttribute(); | 
| 38 | 38 | ||
| 39 | - //如果URL需要的权限为匿名访问,返回 | ||
| 40 | - if(("ROLE_ANONYMOUS").equals(needRole.trim())){ | ||
| 41 | - return; | ||
| 42 | - } | 39 | + | 
| 43 | 40 | ||
| 44 | //authentication 为在注释1 中循环添加到 GrantedAuthority 对象中的权限信息集合 | 41 | //authentication 为在注释1 中循环添加到 GrantedAuthority 对象中的权限信息集合 | 
| 45 | for(GrantedAuthority ga : authentication.getAuthorities()) { | 42 | for(GrantedAuthority ga : authentication.getAuthorities()) { | 
| 43 | + | ||
| 44 | + //如果URL需要的权限为匿名访问,返回 | ||
| 45 | + if(("ROLE_admin").equals(ga.getAuthority())){ | ||
| 46 | + return; | ||
| 47 | + } | ||
| 48 | + | ||
| 46 | if(needRole.trim().equals(ga.getAuthority())) { | 49 | if(needRole.trim().equals(ga.getAuthority())) { | 
| 47 | return; | 50 | return; | 
| 48 | } | 51 | } | 
| 49 | } | 52 | } | 
| 50 | } | 53 | } | 
| 51 | throw new AccessDeniedException("权限不足!"); | 54 | throw new AccessDeniedException("权限不足!"); | 
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * ExceptionTranslationFilter | ||
| 58 | + | ||
| 59 | + ExceptionTranslationFilter 是Spring Security的核心filter之一,用来处理AuthenticationException和AccessDeniedException两种异常。 | ||
| 60 | + | ||
| 61 | + 在我们的例子中,AuthenticationException指的是未登录状态下访问受保护资源,AccessDeniedException指的是登陆了但是由于权限不足(比如普通用户访问管理员界面)。 | ||
| 62 | + | ||
| 63 | + ExceptionTranslationFilter 持有两个处理类,分别是AuthenticationEntryPoint和AccessDeniedHandler。 | ||
| 64 | + | ||
| 65 | + ExceptionTranslationFilter 对异常的处理是通过这两个处理类实现的,处理规则很简单: | ||
| 66 | + | ||
| 67 | + 规则1. 如果异常是 AuthenticationException,使用 AuthenticationEntryPoint 处理 | ||
| 68 | + 规则2. 如果异常是 AccessDeniedException 且用户是匿名用户,使用 AuthenticationEntryPoint 处理 | ||
| 69 | + 规则3. 如果异常是 AccessDeniedException 且用户不是匿名用户,如果否则交给 AccessDeniedHandler 处理。 | ||
| 70 | + */ | ||
| 52 | } | 71 | } | 
| 53 | 72 | ||
| 54 | @Override | 73 | @Override | 
| 55 | public boolean supports(ConfigAttribute var1){ | 74 | public boolean supports(ConfigAttribute var1){ | 
| 56 | - | ||
| 57 | return true; | 75 | return true; | 
| 58 | } | 76 | } | 
| 59 | 77 | 
| @@ -15,7 +15,7 @@ import java.io.IOException; | @@ -15,7 +15,7 @@ import java.io.IOException; | ||
| 15 | public class MyFilterSecurityInterceptor extends AbstractSecurityInterceptor implements Filter { | 15 | public class MyFilterSecurityInterceptor extends AbstractSecurityInterceptor implements Filter { | 
| 16 | 16 | ||
| 17 | @Autowired | 17 | @Autowired | 
| 18 | - private FilterInvocationSecurityMetadataSource securityMetadataSource; | 18 | + private MyInvocationSecurityMetadataSourceService securityMetadataSource; | 
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | @Autowired | 21 | @Autowired | 
| @@ -9,6 +9,7 @@ import org.springframework.security.web.FilterInvocation; | @@ -9,6 +9,7 @@ import org.springframework.security.web.FilterInvocation; | ||
| 9 | import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource; | 9 | import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource; | 
| 10 | import org.springframework.security.web.util.matcher.AntPathRequestMatcher; | 10 | import org.springframework.security.web.util.matcher.AntPathRequestMatcher; | 
| 11 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; | 
| 12 | +import org.springframework.util.AntPathMatcher; | ||
| 12 | 13 | ||
| 13 | import javax.servlet.http.HttpServletRequest; | 14 | import javax.servlet.http.HttpServletRequest; | 
| 14 | import java.util.*; | 15 | import java.util.*; | 
| @@ -22,11 +23,12 @@ public class MyInvocationSecurityMetadataSourceService implements FilterInvocati | @@ -22,11 +23,12 @@ public class MyInvocationSecurityMetadataSourceService implements FilterInvocati | ||
| 22 | 23 | ||
| 23 | @Autowired | 24 | @Autowired | 
| 24 | PERMISSIONMapper permissionMapper; | 25 | PERMISSIONMapper permissionMapper; | 
| 26 | + AntPathMatcher pathMatcher = new AntPathMatcher(); | ||
| 25 | 27 | ||
| 26 | private HashMap<String, Collection<ConfigAttribute>> map =null; | 28 | private HashMap<String, Collection<ConfigAttribute>> map =null; | 
| 27 | 29 | ||
| 28 | /** | 30 | /** | 
| 29 | - * 加载权限表中所有权限 | 31 | + * 加载权限表中所有权限,还是加载URL所需要的权限 | 
| 30 | */ | 32 | */ | 
| 31 | public void loadResourceDefine(String requestUrl){ | 33 | public void loadResourceDefine(String requestUrl){ | 
| 32 | map = new HashMap<>(); | 34 | map = new HashMap<>(); | 
| @@ -41,37 +43,86 @@ public class MyInvocationSecurityMetadataSourceService implements FilterInvocati | @@ -41,37 +43,86 @@ public class MyInvocationSecurityMetadataSourceService implements FilterInvocati | ||
| 41 | // 此处添加的信息将会作为MyAccessDecisionManager类的decide的第三个参数。 | 43 | // 此处添加的信息将会作为MyAccessDecisionManager类的decide的第三个参数。 | 
| 42 | 44 | ||
| 43 | //CFG存储访问的URL需要的权限"ROLE_??"LIST | 45 | //CFG存储访问的URL需要的权限"ROLE_??"LIST | 
| 44 | - List<String> urlOfRoles = permissionMapper.findRoleListByUrl(requestUrl); | 46 | + String pUrl = permission.getUrl(); | 
| 47 | + List<String> urlOfRoles = permissionMapper.findRoleListByUrl(pUrl); | ||
| 48 | + | ||
| 49 | + //路径适配,这个很重要,是配上后会包含其他适配的所有权限,比如/**与/user/List是可以适配上的, | ||
| 50 | + // 那么/**这个通用适配是要有/user/list这个路径所对应的角色信息的 | ||
| 51 | + if(pathMatcher.match(pUrl,requestUrl)){ | ||
| 52 | + | ||
| 53 | + } | ||
| 45 | 54 | ||
| 46 | for (String roleName:urlOfRoles) { | 55 | for (String roleName:urlOfRoles) { | 
| 47 | - cfg = new SecurityConfig(roleName); | ||
| 48 | - array.add(cfg); | 56 | + | 
| 57 | + if(null!=roleName) { | ||
| 58 | + cfg = new SecurityConfig(roleName); | ||
| 59 | + array.add(cfg); | ||
| 60 | + } | ||
| 49 | } | 61 | } | 
| 50 | //用权限的getUrl() 作为map的key,用ConfigAttribute的集合作为 value, | 62 | //用权限的getUrl() 作为map的key,用ConfigAttribute的集合作为 value, | 
| 51 | - map.put(permission.getUrl(), array); | 63 | + map.put(pUrl, array); | 
| 64 | + | ||
| 65 | + | ||
| 52 | } | 66 | } | 
| 53 | 67 | ||
| 54 | } | 68 | } | 
| 55 | 69 | ||
| 56 | /** | 70 | /** | 
| 57 | - * 此方法是为了判定用户请求的url 是否在权限表中, | ||
| 58 | - * 如果在权限表中,则返回给 decide 方法, | 71 | + * 所有的权限表中的url所对应的角色信息 | 
| 72 | + * @return 有就返回集合 没有就返回null | ||
| 73 | + */ | ||
| 74 | + public Collection<ConfigAttribute> loadResourceDefine(){ | ||
| 75 | + Collection<ConfigAttribute> array; | ||
| 76 | + ConfigAttribute cfg; | ||
| 77 | + List<PERMISSION> permissions = permissionMapper.findAll(); | ||
| 78 | + for(PERMISSION permission : permissions) { | ||
| 79 | + array = new ArrayList<>(); | ||
| 80 | + | ||
| 81 | + //此处只添加了用户的名字,其实还可以添加更多权限的信息, | ||
| 82 | + // 例如请求方法到ConfigAttribute的集合中去。 | ||
| 83 | + // 此处添加的信息将会作为MyAccessDecisionManager类的decide的第三个参数。 | ||
| 84 | + | ||
| 85 | + //CFG存储访问的URL需要的权限"ROLE_??"LIST | ||
| 86 | + String pUrl = permission.getUrl(); | ||
| 87 | + List<String> urlOfRoles = permissionMapper.findRoleListByUrl(pUrl); | ||
| 88 | + | ||
| 89 | + for (String roleName:urlOfRoles) { | ||
| 90 | + if(null!=roleName) { | ||
| 91 | + cfg = new SecurityConfig(roleName); | ||
| 92 | + array.add(cfg); | ||
| 93 | + } | ||
| 94 | + } | ||
| 95 | + return array; | ||
| 96 | + | ||
| 97 | + } | ||
| 98 | + return null; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + /** | ||
| 102 | + * 此方法是为了判定用户请求的url权限 是否有对应的角色, | ||
| 103 | + * 如果有对应角色信息,则返回给 decide 方法, | ||
| 59 | * 用来判定用户是否有此权限。如果不在权限表中则放行。 | 104 | * 用来判定用户是否有此权限。如果不在权限表中则放行。 | 
| 60 | * 如果getAttributes(Object o)方法返回null的话,意味着当前这个请求不需要任何角色就能访问 | 105 | * 如果getAttributes(Object o)方法返回null的话,意味着当前这个请求不需要任何角色就能访问 | 
| 61 | * getAttributes(Object o)方法返回的集合最终会来到AccessDecisionManager类中 | 106 | * getAttributes(Object o)方法返回的集合最终会来到AccessDecisionManager类中 | 
| 107 | + * @param object | ||
| 108 | + * @return | ||
| 109 | + * @throws IllegalArgumentException | ||
| 62 | */ | 110 | */ | 
| 63 | @Override | 111 | @Override | 
| 64 | public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException { | 112 | public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException { | 
| 65 | //清楚地址 | 113 | //清楚地址 | 
| 66 | - String requestUrl = ((FilterInvocation)object).getRequestUrl(); | ||
| 67 | - if(map ==null) {loadResourceDefine(requestUrl);} | 114 | + String requestUrl = ((FilterInvocation)object).getRequest().getRequestURI(); | 
| 115 | + | ||
| 116 | + //每次判定的时候都加载权限对应URL表 | ||
| 117 | +// if(map ==null) { | ||
| 118 | + loadResourceDefine(requestUrl); | ||
| 119 | +// } | ||
| 68 | //object 中包含用户请求的request 信息 | 120 | //object 中包含用户请求的request 信息 | 
| 69 | HttpServletRequest request = ((FilterInvocation) object).getHttpRequest(); | 121 | HttpServletRequest request = ((FilterInvocation) object).getHttpRequest(); | 
| 70 | - AntPathRequestMatcher matcher; | ||
| 71 | String resUrl; | 122 | String resUrl; | 
| 72 | for(Iterator<String> iter = map.keySet().iterator(); iter.hasNext(); ) { | 123 | for(Iterator<String> iter = map.keySet().iterator(); iter.hasNext(); ) { | 
| 73 | resUrl = iter.next(); | 124 | resUrl = iter.next(); | 
| 74 | - matcher = new AntPathRequestMatcher(resUrl); | 125 | + AntPathRequestMatcher matcher = new AntPathRequestMatcher(resUrl); | 
| 75 | if(matcher.matches(request)) { | 126 | if(matcher.matches(request)) { | 
| 76 | return map.get(resUrl); | 127 | return map.get(resUrl); | 
| 77 | } | 128 | } | 
| @@ -79,8 +130,13 @@ public class MyInvocationSecurityMetadataSourceService implements FilterInvocati | @@ -79,8 +130,13 @@ public class MyInvocationSecurityMetadataSourceService implements FilterInvocati | ||
| 79 | return null; | 130 | return null; | 
| 80 | } | 131 | } | 
| 81 | 132 | ||
| 133 | + /** | ||
| 134 | + * | ||
| 135 | + * @return 所有URL对应的所有权限 | ||
| 136 | + */ | ||
| 82 | @Override | 137 | @Override | 
| 83 | public Collection<ConfigAttribute> getAllConfigAttributes() { | 138 | public Collection<ConfigAttribute> getAllConfigAttributes() { | 
| 139 | +// return loadResourceDefine(); | ||
| 84 | return null; | 140 | return null; | 
| 85 | } | 141 | } | 
| 86 | 142 | 
| 1 | +package com.tianbo.warehouse.security.config; | ||
| 2 | + | ||
| 3 | +import org.springframework.core.convert.converter.Converter; | ||
| 4 | + | ||
| 5 | +import java.text.ParseException; | ||
| 6 | +import java.text.SimpleDateFormat; | ||
| 7 | +import java.util.Date; | ||
| 8 | + | ||
| 9 | +public class DateConverter implements Converter<String,Date>{ | ||
| 10 | + private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); | ||
| 11 | + | ||
| 12 | + @Override | ||
| 13 | + public Date convert(String s) { | ||
| 14 | + if ("".equals(s) || s == null) { | ||
| 15 | + return null; | ||
| 16 | + } | ||
| 17 | + try { | ||
| 18 | + return simpleDateFormat.parse(s); | ||
| 19 | + } catch (ParseException e) { | ||
| 20 | + e.printStackTrace(); | ||
| 21 | + } | ||
| 22 | + return null; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | +} | 
| 1 | +package com.tianbo.warehouse.security.config; | ||
| 2 | + | ||
| 3 | +import org.springframework.context.annotation.Configuration; | ||
| 4 | +import org.springframework.format.FormatterRegistry; | ||
| 5 | +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
| 6 | + | ||
| 7 | +//@Configuration | ||
| 8 | +public class MyWebMvcConfig { | ||
| 9 | + | ||
| 10 | + | ||
| 11 | + public void addFormatters(FormatterRegistry registry) { | ||
| 12 | + registry.addConverter(new DateConverter()); | ||
| 13 | + } | ||
| 14 | +} | 
| 1 | package com.tianbo.warehouse.security.config; | 1 | package com.tianbo.warehouse.security.config; | 
| 2 | 2 | ||
| 3 | import com.netflix.discovery.converters.Auto; | 3 | import com.netflix.discovery.converters.Auto; | 
| 4 | +import com.tianbo.warehouse.security.CustomUserDetailService; | ||
| 4 | import com.tianbo.warehouse.security.handel.MyAuthenticationAccessDeniedHandler; | 5 | import com.tianbo.warehouse.security.handel.MyAuthenticationAccessDeniedHandler; | 
| 5 | import com.tianbo.warehouse.security.handel.MyAuthenticationFailHandler; | 6 | import com.tianbo.warehouse.security.handel.MyAuthenticationFailHandler; | 
| 6 | import com.tianbo.warehouse.security.handel.MyAuthenticationSuccessHandler; | 7 | import com.tianbo.warehouse.security.handel.MyAuthenticationSuccessHandler; | 
| @@ -41,7 +42,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | @@ -41,7 +42,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | ||
| 41 | 42 | ||
| 42 | @Qualifier("customuserservice") | 43 | @Qualifier("customuserservice") | 
| 43 | @Autowired | 44 | @Autowired | 
| 44 | - private UserDetailsService userDetailsService; | 45 | + private CustomUserDetailService userDetailsService; | 
| 45 | 46 | ||
| 46 | @Autowired | 47 | @Autowired | 
| 47 | private MyAuthenticationAccessDeniedHandler myAuthenticationAccessDeniedHandler; | 48 | private MyAuthenticationAccessDeniedHandler myAuthenticationAccessDeniedHandler; | 
| @@ -53,6 +54,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | @@ -53,6 +54,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | ||
| 53 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { | 54 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { | 
| 54 | //user Details Service验证 | 55 | //user Details Service验证 | 
| 55 | auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder); | 56 | auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder); | 
| 57 | + //不删除凭据,以便记住用户 | ||
| 58 | + auth.eraseCredentials(false); | ||
| 56 | } | 59 | } | 
| 57 | 60 | ||
| 58 | /** | 61 | /** | 
| @@ -69,7 +72,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | @@ -69,7 +72,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | ||
| 69 | //跨域配置 | 72 | //跨域配置 | 
| 70 | .requestMatchers(CorsUtils::isPreFlightRequest).permitAll() | 73 | .requestMatchers(CorsUtils::isPreFlightRequest).permitAll() | 
| 71 | //管理页面只允许管理员角色访问 | 74 | //管理页面只允许管理员角色访问 | 
| 72 | - .antMatchers("/admin","/role").authenticated() | 75 | + .antMatchers("/admin/**","/role/**","/user/**").authenticated() | 
| 73 | //任何请求,登录后可以访问 | 76 | //任何请求,登录后可以访问 | 
| 74 | //其余的不需要验证 | 77 | //其余的不需要验证 | 
| 75 | .anyRequest().permitAll() | 78 | .anyRequest().permitAll() | 
| @@ -107,5 +110,11 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | @@ -107,5 +110,11 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | ||
| 107 | .csrf().disable(); | 110 | .csrf().disable(); | 
| 108 | 111 | ||
| 109 | http.addFilterBefore(myFilterSecurityInterceptor, FilterSecurityInterceptor.class); | 112 | http.addFilterBefore(myFilterSecurityInterceptor, FilterSecurityInterceptor.class); | 
| 113 | + | ||
| 114 | + //session管理 | ||
| 115 | + //session失效后跳转 | ||
| 116 | +// http.sessionManagement().invalidSessionUrl("/login"); | ||
| 117 | +// //只允许一个用户登录,如果同一个账户两次登录,那么第一个账户将被踢下线,跳转到登录页面 | ||
| 118 | +// http.sessionManagement().maximumSessions(1).expiredUrl("/login"); | ||
| 110 | } | 119 | } | 
| 111 | } | 120 | } | 
| 1 | +package com.tianbo.warehouse.service; | ||
| 2 | + | ||
| 3 | +import com.github.pagehelper.PageInfo; | ||
| 4 | +import com.tianbo.warehouse.model.PERMISSION; | ||
| 5 | + | ||
| 6 | +import java.util.List; | ||
| 7 | +import java.util.Map; | ||
| 8 | + | ||
| 9 | +public interface PermissionService { | ||
| 10 | + | ||
| 11 | + PageInfo<PERMISSION> findAll(int pageNum, int pageSize); | ||
| 12 | + | ||
| 13 | + int insertSelective(PERMISSION record); | ||
| 14 | + | ||
| 15 | + Map<String,Object> getUserMenus(); | ||
| 16 | +} | 
| @@ -7,5 +7,12 @@ import java.util.List; | @@ -7,5 +7,12 @@ import java.util.List; | ||
| 7 | 7 | ||
| 8 | public interface UserService { | 8 | public interface UserService { | 
| 9 | USERS loadByUsername(String username); | 9 | USERS loadByUsername(String username); | 
| 10 | + | ||
| 10 | PageInfo<USERS> selectAllUser(int pageNum, int pageSize); | 11 | PageInfo<USERS> selectAllUser(int pageNum, int pageSize); | 
| 12 | + | ||
| 13 | + int updateByPrimaryKeySelective(USERS record); | ||
| 14 | + | ||
| 15 | + int insertSelective(USERS record); | ||
| 16 | + | ||
| 17 | + int deleteByPrimaryKey(Integer userId); | ||
| 11 | } | 18 | } | 
| 1 | +package com.tianbo.warehouse.service.imp; | ||
| 2 | + | ||
| 3 | +import com.github.pagehelper.Page; | ||
| 4 | +import com.github.pagehelper.PageHelper; | ||
| 5 | +import com.github.pagehelper.PageInfo; | ||
| 6 | +import com.tianbo.warehouse.dao.PERMISSIONMapper; | ||
| 7 | +import com.tianbo.warehouse.model.PERMISSION; | ||
| 8 | +import com.tianbo.warehouse.model.ROLE; | ||
| 9 | +import com.tianbo.warehouse.service.PermissionService; | ||
| 10 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 11 | +import org.springframework.stereotype.Service; | ||
| 12 | + | ||
| 13 | +import java.util.*; | ||
| 14 | + | ||
| 15 | +@Service("PermissionService") | ||
| 16 | +public class PermissionServiceImp implements PermissionService{ | ||
| 17 | + | ||
| 18 | + @Autowired | ||
| 19 | + PERMISSIONMapper permissionMapper; | ||
| 20 | + | ||
| 21 | + @Override | ||
| 22 | + public PageInfo<PERMISSION> findAll(int pageNum, int pageSize){ | ||
| 23 | + Page<PERMISSION> page = PageHelper.startPage(pageNum,pageSize); | ||
| 24 | + List<PERMISSION> list = permissionMapper.findAll(); | ||
| 25 | + PageInfo<PERMISSION> result = new PageInfo<>(list); | ||
| 26 | + return result; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + public int insertSelective(PERMISSION record){ | ||
| 31 | + return permissionMapper.insertSelective(record); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + public Map<String,Object> getUserMenus(){ | ||
| 36 | + Map<String,Object> data = new HashMap<String,Object>(); | ||
| 37 | + try { | ||
| 38 | + //查询所有菜单 | ||
| 39 | + List<PERMISSION> allMenu = permissionMapper.getAllMenus(); | ||
| 40 | + //根节点 | ||
| 41 | + List<PERMISSION> rootMenu = new ArrayList<PERMISSION>(); | ||
| 42 | + for (PERMISSION nav : allMenu) { | ||
| 43 | + if(nav.getParentId()==0){//父节点是0的,为根节点。 | ||
| 44 | + rootMenu.add(nav); | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + /* 根据Menu类的order排序 */ | ||
| 49 | +// Collections.sort(rootMenu, order()); | ||
| 50 | + //为根菜单设置子菜单,getClild是递归调用的 | ||
| 51 | + for (PERMISSION nav : rootMenu) { | ||
| 52 | + /* 获取根节点下的所有子节点 使用getChild方法*/ | ||
| 53 | + List<PERMISSION> childList = getChild(nav.getPermissionId(), allMenu); | ||
| 54 | + nav.setChildren(childList);//给根节点设置子节点 | ||
| 55 | + } | ||
| 56 | + /** | ||
| 57 | + * 输出构建好的菜单数据。 | ||
| 58 | + * | ||
| 59 | + */ | ||
| 60 | + data.put("success", "true"); | ||
| 61 | + data.put("list", rootMenu); | ||
| 62 | + return data; | ||
| 63 | + } catch (Exception e) { | ||
| 64 | + data.put("success", "false"); | ||
| 65 | + data.put("list", new ArrayList()); | ||
| 66 | + return data; | ||
| 67 | + } | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + /** | ||
| 71 | + * 获取子节点 | ||
| 72 | + * @param id 父节点id | ||
| 73 | + * @param allMenu 所有菜单列表 | ||
| 74 | + * @return 每个根节点下,所有子菜单列表 | ||
| 75 | + */ | ||
| 76 | + public List<PERMISSION> getChild(Integer id,List<PERMISSION> allMenu){ | ||
| 77 | + //子菜单 | ||
| 78 | + List<PERMISSION> childList = new ArrayList<PERMISSION>(); | ||
| 79 | + for (PERMISSION nav : allMenu) { | ||
| 80 | + // 遍历所有节点,将所有菜单的父id与传过来的根节点的id比较 | ||
| 81 | + //相等说明:为该根节点的子节点。 | ||
| 82 | + if(nav.getParentId().equals(id)){ | ||
| 83 | + childList.add(nav); | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + //递归 | ||
| 87 | + for (PERMISSION nav : childList) { | ||
| 88 | + nav.setChildren(getChild(nav.getPermissionId(), allMenu)); | ||
| 89 | + } | ||
| 90 | +// Collections.sort(childList,order());//排序 | ||
| 91 | + //如果节点下没有子节点,返回一个空List(递归退出) | ||
| 92 | + if(childList.size() == 0){ | ||
| 93 | + return new ArrayList<PERMISSION>(); | ||
| 94 | + } | ||
| 95 | + return childList; | ||
| 96 | + } | ||
| 97 | +} | 
| 1 | +package com.tianbo.warehouse.service.imp; | ||
| 2 | + | ||
| 3 | +import com.github.pagehelper.Page; | ||
| 4 | +import com.github.pagehelper.PageHelper; | ||
| 5 | +import com.github.pagehelper.PageInfo; | ||
| 6 | +import com.tianbo.warehouse.dao.ROLEMapper; | ||
| 7 | +import com.tianbo.warehouse.model.PERMISSION; | ||
| 8 | +import com.tianbo.warehouse.model.ROLE; | ||
| 9 | +import com.tianbo.warehouse.model.USERS; | ||
| 10 | +import com.tianbo.warehouse.service.RoleService; | ||
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 12 | +import org.springframework.stereotype.Service; | ||
| 13 | + | ||
| 14 | +import java.util.List; | ||
| 15 | + | ||
| 16 | +@Service(value = "roleService") | ||
| 17 | +public class RoleServiceImp implements RoleService{ | ||
| 18 | + | ||
| 19 | + @Autowired | ||
| 20 | + ROLEMapper roleMapper; | ||
| 21 | + | ||
| 22 | + @Override | ||
| 23 | + public PageInfo<ROLE> findAll(int pageNum, int pageSize){ | ||
| 24 | + Page<ROLE> page = PageHelper.startPage(pageNum,pageSize); | ||
| 25 | + List<ROLE> list = roleMapper.findAll(); | ||
| 26 | + PageInfo<ROLE> result = new PageInfo<ROLE>(list); | ||
| 27 | + return result; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public int insertSelective(ROLE record){ | ||
| 32 | + return roleMapper.insertSelective(record); | ||
| 33 | + } | ||
| 34 | +} | 
| @@ -62,4 +62,32 @@ public class UserServiceImpl implements UserService{ | @@ -62,4 +62,32 @@ public class UserServiceImpl implements UserService{ | ||
| 62 | PageInfo<USERS> result = new PageInfo<USERS>(list); | 62 | PageInfo<USERS> result = new PageInfo<USERS>(list); | 
| 63 | return result; | 63 | return result; | 
| 64 | } | 64 | } | 
| 65 | + | ||
| 66 | + @Override | ||
| 67 | + public int updateByPrimaryKeySelective(USERS record){ | ||
| 68 | + int i = 0; | ||
| 69 | + if (record!=null){ | ||
| 70 | + i = usersMapper.updateByPrimaryKeySelective(record); | ||
| 71 | + } | ||
| 72 | + return i; | ||
| 73 | + | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + @Override | ||
| 77 | + public int insertSelective(USERS record){ | ||
| 78 | + if (null!=record){ | ||
| 79 | + return usersMapper.insertSelective(record); | ||
| 80 | + }else { | ||
| 81 | + return 0; | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + @Override | ||
| 86 | + public int deleteByPrimaryKey(Integer userId){ | ||
| 87 | + if (null!=userId && userId>0){ | ||
| 88 | + return usersMapper.deleteByPrimaryKey(userId); | ||
| 89 | + }else { | ||
| 90 | + return 0; | ||
| 91 | + } | ||
| 92 | + } | ||
| 65 | } | 93 | } | 
| @@ -8,10 +8,15 @@ server.servlet.context-path=${SERVER_CONTEXTPATH:} | @@ -8,10 +8,15 @@ server.servlet.context-path=${SERVER_CONTEXTPATH:} | ||
| 8 | spring.application.name=tianbo.base.dev.devkit | 8 | spring.application.name=tianbo.base.dev.devkit | 
| 9 | 9 | ||
| 10 | spring.jackson.serialization.fail-on-empty-beans=false | 10 | spring.jackson.serialization.fail-on-empty-beans=false | 
| 11 | + | ||
| 11 | #springboot2.0之后会把Date类型字段自动给转成UTC字符串 如:1990-11-26T16:00:00.000+0000,如果想转成时间戳在application.properties配置文件增加以下配置 | 12 | #springboot2.0之后会把Date类型字段自动给转成UTC字符串 如:1990-11-26T16:00:00.000+0000,如果想转成时间戳在application.properties配置文件增加以下配置 | 
| 12 | -spring.jackson.serialization.write-dates-as-timestamps=true | 13 | +#jackson相关配置 | 
| 14 | +spring.jackson.date-format = yyyy-MM-dd HH:mm:ss | ||
| 15 | +spring.jackson.serialization.write-dates-as-timestamps=false | ||
| 16 | +#时区必须要设置 | ||
| 13 | spring.jackson.time-zone=GMT+8 | 17 | spring.jackson.time-zone=GMT+8 | 
| 14 | - | 18 | +#ALWAYS的意思是即时属性为null,仍然也会输出这个key | 
| 19 | +spring.jackson.default-property-inclusion=always | ||
| 15 | 20 | ||
| 16 | #springcloud 基本配置 | 21 | #springcloud 基本配置 | 
| 17 | 22 | ||
| @@ -37,8 +42,8 @@ spring.datasource.type=com.alibaba.druid.pool.DruidDataSource | @@ -37,8 +42,8 @@ spring.datasource.type=com.alibaba.druid.pool.DruidDataSource | ||
| 37 | #spring.datasource.username=CGOETL | 42 | #spring.datasource.username=CGOETL | 
| 38 | #spring.datasource.password=1q2w3e4r | 43 | #spring.datasource.password=1q2w3e4r | 
| 39 | 44 | ||
| 40 | -#spring datasource mysql | ||
| 41 | -spring.datasource.url=jdbc:mysql://127.0.0.1:3307/statistics | 45 | +#spring datasource mysql,注意编码配置,缺少数据库编码配置容易引起中文入库乱码 | 
| 46 | +spring.datasource.url=jdbc:mysql://127.0.0.1:3307/statistics?useUnicode=true&characterEncoding=utf8 | ||
| 42 | spring.datasource.username=root | 47 | spring.datasource.username=root | 
| 43 | spring.datasource.password= | 48 | spring.datasource.password= | 
| 44 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver | 49 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver | 
| @@ -3,31 +3,38 @@ | @@ -3,31 +3,38 @@ | ||
| 3 | <mapper namespace="com.tianbo.warehouse.dao.PERMISSIONMapper" > | 3 | <mapper namespace="com.tianbo.warehouse.dao.PERMISSIONMapper" > | 
| 4 | <resultMap id="BaseResultMap" type="com.tianbo.warehouse.model.PERMISSION" > | 4 | <resultMap id="BaseResultMap" type="com.tianbo.warehouse.model.PERMISSION" > | 
| 5 | <id column="permission_id" property="permissionId" jdbcType="INTEGER" /> | 5 | <id column="permission_id" property="permissionId" jdbcType="INTEGER" /> | 
| 6 | - <result column="permission_name" property="permissionName" jdbcType="VARCHAR" /> | ||
| 7 | - <result column="permission_sign" property="permissionSign" jdbcType="VARCHAR" /> | 6 | + <result column="name" property="name" jdbcType="VARCHAR" /> | 
| 7 | + <result column="permission_order" property="permissionOrder" jdbcType="VARCHAR" /> | ||
| 8 | <result column="description" property="description" jdbcType="VARCHAR" /> | 8 | <result column="description" property="description" jdbcType="VARCHAR" /> | 
| 9 | - <result column="group_name" property="groupName" jdbcType="VARCHAR" /> | 9 | + <result column="ismenu" property="ismenu" jdbcType="BOOLEAN" /> | 
| 10 | + <result column="hidden" property="hidden" jdbcType="BOOLEAN" /> | ||
| 10 | <result column="parent_id" property="parentId" jdbcType="INTEGER" /> | 11 | <result column="parent_id" property="parentId" jdbcType="INTEGER" /> | 
| 11 | <result column="path" property="path" jdbcType="VARCHAR" /> | 12 | <result column="path" property="path" jdbcType="VARCHAR" /> | 
| 12 | <result column="url" property="url" jdbcType="VARCHAR" /> | 13 | <result column="url" property="url" jdbcType="VARCHAR" /> | 
| 13 | - <result column="ext1" property="ext1" jdbcType="VARCHAR" /> | ||
| 14 | - <result column="ext2" property="ext2" jdbcType="VARCHAR" /> | ||
| 15 | - <result column="ext3" property="ext3" jdbcType="VARCHAR" /> | 14 | + <result column="method" property="method" jdbcType="VARCHAR" /> | 
| 15 | + <result column="iconCls" property="iconCls" jdbcType="VARCHAR" /> | ||
| 16 | + <result column="component" property="component" jdbcType="VARCHAR" /> | ||
| 16 | </resultMap> | 17 | </resultMap> | 
| 17 | <sql id="Base_Column_List" > | 18 | <sql id="Base_Column_List" > | 
| 18 | - permission_id, permission_name, permission_sign, description, group_name, parent_id, | ||
| 19 | - path, url, ext1, ext2, ext3 | 19 | + permission_id, name, permission_order, description, ismenu,hidden,parent_id, | 
| 20 | + path, url, method, iconCls, component | ||
| 20 | </sql> | 21 | </sql> | 
| 21 | <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > | 22 | <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > | 
| 22 | select | 23 | select | 
| 23 | <include refid="Base_Column_List" /> | 24 | <include refid="Base_Column_List" /> | 
| 24 | from permission | 25 | from permission | 
| 25 | - where permission_id = #{permissionId,jdbcType=INTEGER} | 26 | + where permission_id = #{permissionId,jdbcType=INTEGER} ORDER BY permission_order | 
| 26 | </select> | 27 | </select> | 
| 27 | <select id="findAll" resultMap="BaseResultMap" > | 28 | <select id="findAll" resultMap="BaseResultMap" > | 
| 28 | select | 29 | select | 
| 29 | <include refid="Base_Column_List" /> | 30 | <include refid="Base_Column_List" /> | 
| 30 | - from permission | 31 | + from permission ORDER BY permission_order | 
| 32 | + </select> | ||
| 33 | + | ||
| 34 | + <select id="getAllMenus" resultMap="BaseResultMap" > | ||
| 35 | + select | ||
| 36 | + <include refid="Base_Column_List" /> | ||
| 37 | + from permission where ismenu is TRUE ORDER BY permission_order | ||
| 31 | </select> | 38 | </select> | 
| 32 | <select id="findRoleListByUrl" resultType="java.lang.String" parameterType="java.lang.String"> | 39 | <select id="findRoleListByUrl" resultType="java.lang.String" parameterType="java.lang.String"> | 
| 33 | SELECT | 40 | SELECT | 
| @@ -36,7 +43,7 @@ FROM | @@ -36,7 +43,7 @@ FROM | ||
| 36 | permission P | 43 | permission P | 
| 37 | LEFT JOIN role_permission RP ON P.permission_id = RP.permission_id | 44 | LEFT JOIN role_permission RP ON P.permission_id = RP.permission_id | 
| 38 | LEFT JOIN ROLE R ON R.ROLE_ID= RP.ROLE_ID | 45 | LEFT JOIN ROLE R ON R.ROLE_ID= RP.ROLE_ID | 
| 39 | -where P.url = #{permissionUrl,jdbcType=VARCHAR} | 46 | +where P.url = #{permissionUrl,jdbcType=VARCHAR} ORDER BY permission_order | 
| 40 | </select> | 47 | </select> | 
| 41 | <select id="findByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap"> | 48 | <select id="findByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap"> | 
| 42 | SELECT | 49 | SELECT | 
| @@ -65,21 +72,21 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} | @@ -65,21 +72,21 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} | ||
| 65 | UR.USER_ID = #{userId,jdbcType=INTEGER} | 72 | UR.USER_ID = #{userId,jdbcType=INTEGER} | 
| 66 | ) | 73 | ) | 
| 67 | ) | 74 | ) | 
| 68 | - ) | 75 | + ) ORDER BY permission_order | 
| 69 | </select> | 76 | </select> | 
| 70 | <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > | 77 | <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > | 
| 71 | delete from permission | 78 | delete from permission | 
| 72 | where permission_id = #{permissionId,jdbcType=INTEGER} | 79 | where permission_id = #{permissionId,jdbcType=INTEGER} | 
| 73 | </delete> | 80 | </delete> | 
| 74 | <insert id="insert" parameterType="com.tianbo.warehouse.model.PERMISSION" > | 81 | <insert id="insert" parameterType="com.tianbo.warehouse.model.PERMISSION" > | 
| 75 | - insert into permission (permission_id, permission_name, permission_sign, | ||
| 76 | - description, group_name, parent_id, | ||
| 77 | - path, url, ext1, ext2, | ||
| 78 | - ext3) | ||
| 79 | - values (#{permissionId,jdbcType=INTEGER}, #{permissionName,jdbcType=VARCHAR}, #{permissionSign,jdbcType=VARCHAR}, | ||
| 80 | - #{description,jdbcType=VARCHAR}, #{groupName,jdbcType=VARCHAR}, #{parentId,jdbcType=INTEGER}, | ||
| 81 | - #{path,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, #{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, | ||
| 82 | - #{ext3,jdbcType=VARCHAR}) | 82 | + insert into permission (permission_id, name, permission_order, | 
| 83 | + description, ismenu,hidden, parent_id, | ||
| 84 | + path, url, method, iconCls, | ||
| 85 | + component) | ||
| 86 | + values (#{permissionId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{permissionOrder,jdbcType=VARCHAR}, | ||
| 87 | + #{description,jdbcType=VARCHAR}, #{ismenu,jdbcType=BOOLEAN},#{hidden,jdbcType=BOOLEAN},#{parentId,jdbcType=INTEGER}, | ||
| 88 | + #{path,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, #{method,jdbcType=VARCHAR}, #{iconCls,jdbcType=VARCHAR}, | ||
| 89 | + #{component,jdbcType=VARCHAR}) | ||
| 83 | </insert> | 90 | </insert> | 
| 84 | <insert id="insertSelective" parameterType="com.tianbo.warehouse.model.PERMISSION" > | 91 | <insert id="insertSelective" parameterType="com.tianbo.warehouse.model.PERMISSION" > | 
| 85 | insert into permission | 92 | insert into permission | 
| @@ -87,17 +94,20 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} | @@ -87,17 +94,20 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} | ||
| 87 | <if test="permissionId != null" > | 94 | <if test="permissionId != null" > | 
| 88 | permission_id, | 95 | permission_id, | 
| 89 | </if> | 96 | </if> | 
| 90 | - <if test="permissionName != null" > | ||
| 91 | - permission_name, | 97 | + <if test="name != null" > | 
| 98 | + name, | ||
| 92 | </if> | 99 | </if> | 
| 93 | - <if test="permissionSign != null" > | ||
| 94 | - permission_sign, | 100 | + <if test="permissionOrder != null" > | 
| 101 | + permission_order, | ||
| 95 | </if> | 102 | </if> | 
| 96 | <if test="description != null" > | 103 | <if test="description != null" > | 
| 97 | description, | 104 | description, | 
| 98 | </if> | 105 | </if> | 
| 99 | - <if test="groupName != null" > | ||
| 100 | - group_name, | 106 | + <if test="ismenu != null" > | 
| 107 | + ismenu, | ||
| 108 | + </if> | ||
| 109 | + <if test="hidden != null" > | ||
| 110 | + hidden, | ||
| 101 | </if> | 111 | </if> | 
| 102 | <if test="parentId != null" > | 112 | <if test="parentId != null" > | 
| 103 | parent_id, | 113 | parent_id, | 
| @@ -108,31 +118,34 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} | @@ -108,31 +118,34 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} | ||
| 108 | <if test="url != null" > | 118 | <if test="url != null" > | 
| 109 | url, | 119 | url, | 
| 110 | </if> | 120 | </if> | 
| 111 | - <if test="ext1 != null" > | ||
| 112 | - ext1, | 121 | + <if test="method != null" > | 
| 122 | + method, | ||
| 113 | </if> | 123 | </if> | 
| 114 | - <if test="ext2 != null" > | ||
| 115 | - ext2, | 124 | + <if test="iconCls != null" > | 
| 125 | + iconCls, | ||
| 116 | </if> | 126 | </if> | 
| 117 | - <if test="ext3 != null" > | ||
| 118 | - ext3, | 127 | + <if test="component != null" > | 
| 128 | + component, | ||
| 119 | </if> | 129 | </if> | 
| 120 | </trim> | 130 | </trim> | 
| 121 | <trim prefix="values (" suffix=")" suffixOverrides="," > | 131 | <trim prefix="values (" suffix=")" suffixOverrides="," > | 
| 122 | <if test="permissionId != null" > | 132 | <if test="permissionId != null" > | 
| 123 | #{permissionId,jdbcType=INTEGER}, | 133 | #{permissionId,jdbcType=INTEGER}, | 
| 124 | </if> | 134 | </if> | 
| 125 | - <if test="permissionName != null" > | ||
| 126 | - #{permissionName,jdbcType=VARCHAR}, | 135 | + <if test="name != null" > | 
| 136 | + #{name,jdbcType=VARCHAR}, | ||
| 127 | </if> | 137 | </if> | 
| 128 | - <if test="permissionSign != null" > | ||
| 129 | - #{permissionSign,jdbcType=VARCHAR}, | 138 | + <if test="permissionOrder != null" > | 
| 139 | + #{permissionOrder,jdbcType=VARCHAR}, | ||
| 130 | </if> | 140 | </if> | 
| 131 | <if test="description != null" > | 141 | <if test="description != null" > | 
| 132 | #{description,jdbcType=VARCHAR}, | 142 | #{description,jdbcType=VARCHAR}, | 
| 133 | </if> | 143 | </if> | 
| 134 | - <if test="groupName != null" > | ||
| 135 | - #{groupName,jdbcType=VARCHAR}, | 144 | + <if test="ismenu != null" > | 
| 145 | + #{ismenu,jdbcType=BOOLEAN}, | ||
| 146 | + </if> | ||
| 147 | + <if test="hidden != null" > | ||
| 148 | + #{hidden,jdbcType=BOOLEAN}, | ||
| 136 | </if> | 149 | </if> | 
| 137 | <if test="parentId != null" > | 150 | <if test="parentId != null" > | 
| 138 | #{parentId,jdbcType=INTEGER}, | 151 | #{parentId,jdbcType=INTEGER}, | 
| @@ -143,31 +156,34 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} | @@ -143,31 +156,34 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} | ||
| 143 | <if test="url != null" > | 156 | <if test="url != null" > | 
| 144 | #{url,jdbcType=VARCHAR}, | 157 | #{url,jdbcType=VARCHAR}, | 
| 145 | </if> | 158 | </if> | 
| 146 | - <if test="ext1 != null" > | ||
| 147 | - #{ext1,jdbcType=VARCHAR}, | 159 | + <if test="method != null" > | 
| 160 | + #{method,jdbcType=VARCHAR}, | ||
| 148 | </if> | 161 | </if> | 
| 149 | - <if test="ext2 != null" > | ||
| 150 | - #{ext2,jdbcType=VARCHAR}, | 162 | + <if test="iconCls != null" > | 
| 163 | + #{iconCls,jdbcType=VARCHAR}, | ||
| 151 | </if> | 164 | </if> | 
| 152 | - <if test="ext3 != null" > | ||
| 153 | - #{ext3,jdbcType=VARCHAR}, | 165 | + <if test="component != null" > | 
| 166 | + #{component,jdbcType=VARCHAR}, | ||
| 154 | </if> | 167 | </if> | 
| 155 | </trim> | 168 | </trim> | 
| 156 | </insert> | 169 | </insert> | 
| 157 | <update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.PERMISSION" > | 170 | <update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.PERMISSION" > | 
| 158 | update permission | 171 | update permission | 
| 159 | <set > | 172 | <set > | 
| 160 | - <if test="permissionName != null" > | ||
| 161 | - permission_name = #{permissionName,jdbcType=VARCHAR}, | 173 | + <if test="name != null" > | 
| 174 | + name = #{name,jdbcType=VARCHAR}, | ||
| 162 | </if> | 175 | </if> | 
| 163 | - <if test="permissionSign != null" > | ||
| 164 | - permission_sign = #{permissionSign,jdbcType=VARCHAR}, | 176 | + <if test="permissionOrder != null" > | 
| 177 | + permission_order = #{permissionOrder,jdbcType=VARCHAR}, | ||
| 165 | </if> | 178 | </if> | 
| 166 | <if test="description != null" > | 179 | <if test="description != null" > | 
| 167 | description = #{description,jdbcType=VARCHAR}, | 180 | description = #{description,jdbcType=VARCHAR}, | 
| 168 | </if> | 181 | </if> | 
| 169 | - <if test="groupName != null" > | ||
| 170 | - group_name = #{groupName,jdbcType=VARCHAR}, | 182 | + <if test="ismenu != null" > | 
| 183 | + ismenu = #{ismenu,jdbcType=BOOLEAN}, | ||
| 184 | + </if> | ||
| 185 | + <if test="hidden != null" > | ||
| 186 | + hidden = #{hidden,jdbcType=BOOLEAN}, | ||
| 171 | </if> | 187 | </if> | 
| 172 | <if test="parentId != null" > | 188 | <if test="parentId != null" > | 
| 173 | parent_id = #{parentId,jdbcType=INTEGER}, | 189 | parent_id = #{parentId,jdbcType=INTEGER}, | 
| @@ -178,30 +194,31 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} | @@ -178,30 +194,31 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} | ||
| 178 | <if test="url != null" > | 194 | <if test="url != null" > | 
| 179 | url = #{url,jdbcType=VARCHAR}, | 195 | url = #{url,jdbcType=VARCHAR}, | 
| 180 | </if> | 196 | </if> | 
| 181 | - <if test="ext1 != null" > | ||
| 182 | - ext1 = #{ext1,jdbcType=VARCHAR}, | 197 | + <if test="method != null" > | 
| 198 | + method = #{method,jdbcType=VARCHAR}, | ||
| 183 | </if> | 199 | </if> | 
| 184 | - <if test="ext2 != null" > | ||
| 185 | - ext2 = #{ext2,jdbcType=VARCHAR}, | 200 | + <if test="iconCls != null" > | 
| 201 | + iconCls = #{iconCls,jdbcType=VARCHAR}, | ||
| 186 | </if> | 202 | </if> | 
| 187 | - <if test="ext3 != null" > | ||
| 188 | - ext3 = #{ext3,jdbcType=VARCHAR}, | 203 | + <if test="component != null" > | 
| 204 | + component = #{component,jdbcType=VARCHAR}, | ||
| 189 | </if> | 205 | </if> | 
| 190 | </set> | 206 | </set> | 
| 191 | where permission_id = #{permissionId,jdbcType=INTEGER} | 207 | where permission_id = #{permissionId,jdbcType=INTEGER} | 
| 192 | </update> | 208 | </update> | 
| 193 | <update id="updateByPrimaryKey" parameterType="com.tianbo.warehouse.model.PERMISSION" > | 209 | <update id="updateByPrimaryKey" parameterType="com.tianbo.warehouse.model.PERMISSION" > | 
| 194 | update permission | 210 | update permission | 
| 195 | - set permission_name = #{permissionName,jdbcType=VARCHAR}, | ||
| 196 | - permission_sign = #{permissionSign,jdbcType=VARCHAR}, | 211 | + set name = #{name,jdbcType=VARCHAR}, | 
| 212 | + permission_order = #{permissionOrder,jdbcType=VARCHAR}, | ||
| 197 | description = #{description,jdbcType=VARCHAR}, | 213 | description = #{description,jdbcType=VARCHAR}, | 
| 198 | - group_name = #{groupName,jdbcType=VARCHAR}, | 214 | + ismenu = #{ismenu,jdbcType=BOOLEAN}, | 
| 215 | + hidden = #{hidden,jdbcType=BOOLEAN}, | ||
| 199 | parent_id = #{parentId,jdbcType=INTEGER}, | 216 | parent_id = #{parentId,jdbcType=INTEGER}, | 
| 200 | path = #{path,jdbcType=VARCHAR}, | 217 | path = #{path,jdbcType=VARCHAR}, | 
| 201 | url = #{url,jdbcType=VARCHAR}, | 218 | url = #{url,jdbcType=VARCHAR}, | 
| 202 | - ext1 = #{ext1,jdbcType=VARCHAR}, | ||
| 203 | - ext2 = #{ext2,jdbcType=VARCHAR}, | ||
| 204 | - ext3 = #{ext3,jdbcType=VARCHAR} | 219 | + method = #{method,jdbcType=VARCHAR}, | 
| 220 | + iconCls = #{iconCls,jdbcType=VARCHAR}, | ||
| 221 | + component = #{component,jdbcType=VARCHAR} | ||
| 205 | where permission_id = #{permissionId,jdbcType=INTEGER} | 222 | where permission_id = #{permissionId,jdbcType=INTEGER} | 
| 206 | </update> | 223 | </update> | 
| 207 | </mapper> | 224 | </mapper> | 
| @@ -13,13 +13,13 @@ | @@ -13,13 +13,13 @@ | ||
| 13 | <result column="creatTime" property="creattime" jdbcType="TIMESTAMP" /> | 13 | <result column="creatTime" property="creattime" jdbcType="TIMESTAMP" /> | 
| 14 | <result column="updateTime" property="updatetime" jdbcType="TIMESTAMP" /> | 14 | <result column="updateTime" property="updatetime" jdbcType="TIMESTAMP" /> | 
| 15 | <result column="userFace" property="userface" jdbcType="VARCHAR" /> | 15 | <result column="userFace" property="userface" jdbcType="VARCHAR" /> | 
| 16 | - <result column="ext1" property="ext1" jdbcType="VARCHAR" /> | ||
| 17 | - <result column="ext2" property="ext2" jdbcType="VARCHAR" /> | ||
| 18 | - <result column="ext3" property="ext3" jdbcType="VARCHAR" /> | 16 | + <result column="realName" property="realname" jdbcType="VARCHAR" /> | 
| 17 | + <result column="email" property="email" jdbcType="VARCHAR" /> | ||
| 18 | + <result column="age" property="age" jdbcType="INTEGER" /> | ||
| 19 | </resultMap> | 19 | </resultMap> | 
| 20 | <sql id="Base_Column_List" > | 20 | <sql id="Base_Column_List" > | 
| 21 | user_id, username, password, birthday, sex, address, state, mobilePhone, creatTime, | 21 | user_id, username, password, birthday, sex, address, state, mobilePhone, creatTime, | 
| 22 | - updateTime, userFace, ext1, ext2, ext3 | 22 | + updateTime, userFace, realName, email, age | 
| 23 | </sql> | 23 | </sql> | 
| 24 | <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > | 24 | <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > | 
| 25 | select | 25 | select | 
| @@ -46,13 +46,13 @@ | @@ -46,13 +46,13 @@ | ||
| 46 | insert into users (user_id, username, password, | 46 | insert into users (user_id, username, password, | 
| 47 | birthday, sex, address, | 47 | birthday, sex, address, | 
| 48 | state, mobilePhone, creatTime, | 48 | state, mobilePhone, creatTime, | 
| 49 | - updateTime, userFace, ext1, | ||
| 50 | - ext2, ext3) | 49 | + updateTime, userFace, realName, | 
| 50 | + email, age) | ||
| 51 | values (#{userId,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, | 51 | values (#{userId,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, | 
| 52 | #{birthday,jdbcType=TIMESTAMP}, #{sex,jdbcType=CHAR}, #{address,jdbcType=VARCHAR}, | 52 | #{birthday,jdbcType=TIMESTAMP}, #{sex,jdbcType=CHAR}, #{address,jdbcType=VARCHAR}, | 
| 53 | #{state,jdbcType=BIT}, #{mobilephone,jdbcType=VARCHAR}, #{creattime,jdbcType=TIMESTAMP}, | 53 | #{state,jdbcType=BIT}, #{mobilephone,jdbcType=VARCHAR}, #{creattime,jdbcType=TIMESTAMP}, | 
| 54 | - #{updatetime,jdbcType=TIMESTAMP}, #{userface,jdbcType=VARCHAR}, #{ext1,jdbcType=VARCHAR}, | ||
| 55 | - #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR}) | 54 | + #{updatetime,jdbcType=TIMESTAMP}, #{userface,jdbcType=VARCHAR}, #{realname,jdbcType=VARCHAR}, | 
| 55 | + #{email,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER}) | ||
| 56 | </insert> | 56 | </insert> | 
| 57 | <insert id="insertSelective" parameterType="com.tianbo.warehouse.model.USERS" > | 57 | <insert id="insertSelective" parameterType="com.tianbo.warehouse.model.USERS" > | 
| 58 | insert into users | 58 | insert into users | 
| @@ -90,14 +90,14 @@ | @@ -90,14 +90,14 @@ | ||
| 90 | <if test="userface != null" > | 90 | <if test="userface != null" > | 
| 91 | userFace, | 91 | userFace, | 
| 92 | </if> | 92 | </if> | 
| 93 | - <if test="ext1 != null" > | ||
| 94 | - ext1, | 93 | + <if test="realname != null" > | 
| 94 | + realname, | ||
| 95 | </if> | 95 | </if> | 
| 96 | - <if test="ext2 != null" > | ||
| 97 | - ext2, | 96 | + <if test="email != null" > | 
| 97 | + email, | ||
| 98 | </if> | 98 | </if> | 
| 99 | - <if test="ext3 != null" > | ||
| 100 | - ext3, | 99 | + <if test="age != null" > | 
| 100 | + age, | ||
| 101 | </if> | 101 | </if> | 
| 102 | </trim> | 102 | </trim> | 
| 103 | <trim prefix="values (" suffix=")" suffixOverrides="," > | 103 | <trim prefix="values (" suffix=")" suffixOverrides="," > | 
| @@ -134,23 +134,20 @@ | @@ -134,23 +134,20 @@ | ||
| 134 | <if test="userface != null" > | 134 | <if test="userface != null" > | 
| 135 | #{userface,jdbcType=VARCHAR}, | 135 | #{userface,jdbcType=VARCHAR}, | 
| 136 | </if> | 136 | </if> | 
| 137 | - <if test="ext1 != null" > | ||
| 138 | - #{ext1,jdbcType=VARCHAR}, | 137 | + <if test="realname != null" > | 
| 138 | + #{realname,jdbcType=VARCHAR}, | ||
| 139 | </if> | 139 | </if> | 
| 140 | - <if test="ext2 != null" > | ||
| 141 | - #{ext2,jdbcType=VARCHAR}, | 140 | + <if test="email != null" > | 
| 141 | + #{email,jdbcType=VARCHAR}, | ||
| 142 | </if> | 142 | </if> | 
| 143 | - <if test="ext3 != null" > | ||
| 144 | - #{ext3,jdbcType=VARCHAR}, | 143 | + <if test="age != null" > | 
| 144 | + #{age,jdbcType=INTEGER}, | ||
| 145 | </if> | 145 | </if> | 
| 146 | </trim> | 146 | </trim> | 
| 147 | </insert> | 147 | </insert> | 
| 148 | <update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.USERS" > | 148 | <update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.USERS" > | 
| 149 | update users | 149 | update users | 
| 150 | <set > | 150 | <set > | 
| 151 | - <if test="username != null" > | ||
| 152 | - username = #{username,jdbcType=VARCHAR}, | ||
| 153 | - </if> | ||
| 154 | <if test="password != null" > | 151 | <if test="password != null" > | 
| 155 | password = #{password,jdbcType=VARCHAR}, | 152 | password = #{password,jdbcType=VARCHAR}, | 
| 156 | </if> | 153 | </if> | 
| @@ -178,22 +175,21 @@ | @@ -178,22 +175,21 @@ | ||
| 178 | <if test="userface != null" > | 175 | <if test="userface != null" > | 
| 179 | userFace = #{userface,jdbcType=VARCHAR}, | 176 | userFace = #{userface,jdbcType=VARCHAR}, | 
| 180 | </if> | 177 | </if> | 
| 181 | - <if test="ext1 != null" > | ||
| 182 | - ext1 = #{ext1,jdbcType=VARCHAR}, | 178 | + <if test="realname != null" > | 
| 179 | + realname = #{realname,jdbcType=VARCHAR}, | ||
| 183 | </if> | 180 | </if> | 
| 184 | - <if test="ext2 != null" > | ||
| 185 | - ext2 = #{ext2,jdbcType=VARCHAR}, | 181 | + <if test="email != null" > | 
| 182 | + email = #{email,jdbcType=VARCHAR}, | ||
| 186 | </if> | 183 | </if> | 
| 187 | - <if test="ext3 != null" > | ||
| 188 | - ext3 = #{ext3,jdbcType=VARCHAR}, | 184 | + <if test="age != null" > | 
| 185 | + age = #{age,jdbcType=INTEGER}, | ||
| 189 | </if> | 186 | </if> | 
| 190 | </set> | 187 | </set> | 
| 191 | where user_id = #{userId,jdbcType=INTEGER} | 188 | where user_id = #{userId,jdbcType=INTEGER} | 
| 192 | </update> | 189 | </update> | 
| 193 | <update id="updateByPrimaryKey" parameterType="com.tianbo.warehouse.model.USERS" > | 190 | <update id="updateByPrimaryKey" parameterType="com.tianbo.warehouse.model.USERS" > | 
| 194 | update users | 191 | update users | 
| 195 | - set username = #{username,jdbcType=VARCHAR}, | ||
| 196 | - password = #{password,jdbcType=VARCHAR}, | 192 | + set password = #{password,jdbcType=VARCHAR}, | 
| 197 | birthday = #{birthday,jdbcType=TIMESTAMP}, | 193 | birthday = #{birthday,jdbcType=TIMESTAMP}, | 
| 198 | sex = #{sex,jdbcType=CHAR}, | 194 | sex = #{sex,jdbcType=CHAR}, | 
| 199 | address = #{address,jdbcType=VARCHAR}, | 195 | address = #{address,jdbcType=VARCHAR}, | 
| @@ -202,9 +198,9 @@ | @@ -202,9 +198,9 @@ | ||
| 202 | creatTime = #{creattime,jdbcType=TIMESTAMP}, | 198 | creatTime = #{creattime,jdbcType=TIMESTAMP}, | 
| 203 | updateTime = #{updatetime,jdbcType=TIMESTAMP}, | 199 | updateTime = #{updatetime,jdbcType=TIMESTAMP}, | 
| 204 | userFace = #{userface,jdbcType=VARCHAR}, | 200 | userFace = #{userface,jdbcType=VARCHAR}, | 
| 205 | - ext1 = #{ext1,jdbcType=VARCHAR}, | ||
| 206 | - ext2 = #{ext2,jdbcType=VARCHAR}, | ||
| 207 | - ext3 = #{ext3,jdbcType=VARCHAR} | 201 | + realName = #{realname,jdbcType=VARCHAR}, | 
| 202 | + email = #{email,jdbcType=VARCHAR}, | ||
| 203 | + age = #{age,jdbcType=INTEGER} | ||
| 208 | where user_id = #{userId,jdbcType=INTEGER} | 204 | where user_id = #{userId,jdbcType=INTEGER} | 
| 209 | </update> | 205 | </update> | 
| 210 | </mapper> | 206 | </mapper> | 
- 
请 注册 或 登录 后发表评论