Commit 8107cedb authored by liboyang's avatar liboyang

实现增加用户,角色和权限接口

parent c0495ad3
package com.yxproject.start;
//import com.yxproject.start.config.JerseyConfig;
import com.yxproject.start.config.JerseyConfig;
import org.glassfish.jersey.servlet.ServletContainer;
import org.glassfish.jersey.servlet.ServletProperties;
import org.springframework.boot.SpringApplication;
......@@ -17,13 +17,13 @@ import org.springframework.context.annotation.Bean;
public class Main{
// @Bean
// public ServletRegistrationBean jerseyServlet() {
// ServletRegistrationBean registration = new ServletRegistrationBean(new ServletContainer(), "/rest/*");
// registration.addInitParameter(ServletProperties.JAXRS_APPLICATION_CLASS,
// JerseyConfig.class.getName());
// return registration;
// }
@Bean
public ServletRegistrationBean jerseyServlet() {
ServletRegistrationBean registration = new ServletRegistrationBean(new ServletContainer(), "/rest/*");
registration.addInitParameter(ServletProperties.JAXRS_APPLICATION_CLASS,
JerseyConfig.class.getName());
return registration;
}
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
......
......@@ -24,11 +24,6 @@ public class ShiroApi {
//获取到用户信息;
Subject subject = SecurityUtils.getSubject();
UserInfo ui = (UserInfo) subject.getPrincipal();
for(SysRole role:ui.getRoleList()){
for(SysPermission memu:role.getPermissions()){
System.out.println(memu.getPermission()+","+memu.getUrl());
}
}
map.put("userInfo",ui);
return "/index";
}
......@@ -61,12 +56,35 @@ public class ShiroApi {
return "/login";
}
/**
* 角色添加;
* @return
*/
@RequestMapping("/roleAdd")
@RequiresPermissions("role.add")//权限管理;
public String roleAdd(Map<String,Object> map){
Subject subject = SecurityUtils.getSubject();
UserInfo ui = (UserInfo) subject.getPrincipal();
map.put("userInfo",ui);
return "roleAdd";
}
/**
* 权限添加;
* @return
*/
@RequestMapping("/permissionAdd")
@RequiresPermissions("permission.add")//权限管理;
public String permissionAdd(){
return "permissionAdd";
}
/**
* 用户添加;
* @return
*/
@RequestMapping("/userAdd")
@RequiresPermissions("userInfo.del")//权限管理;
@RequiresPermissions("userInfo.add")//权限管理;
public String userInfoAdd(){
return "userInfoAdd";
}
......
package com.yxproject.start.api;
import com.yxproject.start.entity.SysPermission;
import com.yxproject.start.entity.SysRole;
import com.yxproject.start.entity.UserInfo;
import com.yxproject.start.service.SysPermissionService;
import com.yxproject.start.service.SysRoleService;
import com.yxproject.start.service.UserInfoService;
import com.yxproject.start.service.impl.UserInfoServiceImpl;
import com.yxproject.start.utils.Md5Utils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
......@@ -13,97 +16,106 @@ import org.apache.shiro.authz.Permission;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.*;
@Controller
/**
* @author Administrator
*/
@Controller
public class UserInfoApi {
@Autowired
private SysPermissionService sysPermissionService;
// @RequestMapping("login")
// @Produces(MediaType.APPLICATION_JSON)
// public Map<String, Object> submitLogin(@QueryParam("username") String username, @QueryParam("password") String password) {
// Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
// Subject currentUser = SecurityUtils.getSubject();
//
// // 把用户名和密码封装为 UsernamePasswordToken 对象
// UsernamePasswordToken token = new UsernamePasswordToken(username, password);
// try {
// currentUser.login(token);
// resultMap.put("status", 200);
// resultMap.put("message", "登录成功");
// } catch (UnknownAccountException e) {
// resultMap.put("status", 500);
// resultMap.put("message", "账号不存在!");
// }catch(IncorrectCredentialsException e1){
// resultMap.put("status", 501);
// resultMap.put("message", "密码错误!");
// }catch (Exception e) {
// resultMap.put("status", 500);
// resultMap.put("message", "账号不存在");
// }
//
// return resultMap;
// }
@Autowired
private UserInfoService userInfoService;
@Autowired
private SysRoleService sysRoleService;
@RequestMapping("login")
@Produces(MediaType.APPLICATION_JSON)
public Map<String, Object> submitLogin(@QueryParam("username") String username, @QueryParam("password") String password) {
Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
Subject currentUser = SecurityUtils.getSubject();
// 把用户名和密码封装为 UsernamePasswordToken 对象
UsernamePasswordToken token = new UsernamePasswordToken(username, password);
try {
currentUser.login(token);
resultMap.put("status", 200);
resultMap.put("message", "登录成功");
} catch (UnknownAccountException e) {
resultMap.put("status", 500);
resultMap.put("message", "账号不存在!");
}catch(IncorrectCredentialsException e1){
resultMap.put("status", 501);
resultMap.put("message", "密码错误!");
}catch (Exception e) {
resultMap.put("status", 500);
resultMap.put("message", "账号不存在");
}
return resultMap;
}
@RequestMapping(value="/permissionAdd",method= RequestMethod.POST)
@RequiresPermissions("userInfo.add")
@RequiresPermissions("permission.add")
@ResponseBody
public String userAdd(@ModelAttribute SysPermission sysPermission) {
// Map<String, Object> resultMap = new HashMap<String, Object>();
// String name = sysPermission.getName();
// String resourceType = sysPermission.getResourceType();
// String url = sysPermission.getUrl();
// String permission =sysPermission.getPermission();
// long parentId = sysPermission.getParentId();
// String parentIds = sysPermission.getParentIds();
// resultMap.put("id",4);
// resultMap.put("name",name);
// resultMap.put("resourceType",resourceType);
// resultMap.put("url",url);
// resultMap.put("permission",permission);
// resultMap.put("parentId",parentId);
// resultMap.put("parentIds",parentIds);
// resultMap.put("available",false);
// System.out.println(resultMap.toString());
System.out.println("?????");
sysPermissionService.addPermission(sysPermission);
return "yes";
public Map<String, String> userAdd(@ModelAttribute SysPermission sysPermission) {
Map<String,String> map = new HashMap<>();
boolean flag = false;
flag = sysPermissionService.addPermission(sysPermission);
if (flag){
map.put("resultMsg","添加成功");
}else {
map.put("resultMsg","添加失败");
}
return map;
}
// /**
// * 用户添加;
// * @return
// */
// @RequestMapping(value = "/userAdd",method = RequestMethod.POST)
// @RequiresPermissions("userInfo.add")//权限管理;
// public String userInfoAdd(@QueryParam("username") String username, @QueryParam("password") String password){
// System.out.println("username------"+username+" -----password-----"+password);
// UserInfoService systemUserService = new UserInfoServiceImpl();
// int i = systemUserService.addUsername(new UserInfo());
//// int i = 0;
// System.out.println(i+"------返回值");
// return i+"userInfoAdd";
// }
//
/**
* 用户添加;
* @return
*/
@RequestMapping(value = "/userInfoAdd",method = RequestMethod.POST)
@RequiresPermissions("userInfo.add")
@ResponseBody
public Map<String, String> userInfoAdd(@ModelAttribute UserInfo userInfo){
String pwd = userInfo.getPassword();
String salt = UUID.randomUUID().toString();
userInfo.setPassword(Md5Utils.entryptPassword(pwd,salt));
userInfo.setSalt(salt);
Map<String,String> map = new HashMap<>();
System.out.println(userInfo.getUsername());
System.out.println(userInfo.getPassword());
System.out.println(userInfo.getSalt());
boolean flag = false;
flag = userInfoService.addUser(userInfo);
if (flag){
map.put("resultMsg","添加成功");
}else {
map.put("resultMsg","添加失败");
}
return map;
}
// /**
// * 用户删除;
// * @return
......@@ -134,5 +146,24 @@ public class UserInfoApi {
// return i+"userInfoAdd";
// }
@RequestMapping(value="/roleInfoAdd",method= RequestMethod.POST)
@RequiresPermissions("role.add")
@ResponseBody
public Map<String, String> roleAdd(@ModelAttribute SysRole sysRole) {
Map<String,String> map = new HashMap<>();
boolean flag = false;
flag = sysRoleService.addRole(sysRole);
System.out.println(sysRole.getId());
if (flag){
map.put("resultMsg","添加成功");
}else {
map.put("resultMsg","添加失败");
}
return map;
}
}
//package com.yxproject.start.config;
//
//import com.yxproject.start.api.UserInfoApi;
//import org.glassfish.jersey.server.ResourceConfig;
//
//public class JerseyConfig extends ResourceConfig {
// public JerseyConfig() {
// register(UserInfoApi.class);
// }
//}
package com.yxproject.start.config;
import com.yxproject.start.api.UserInfoApi;
import org.glassfish.jersey.server.ResourceConfig;
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() {
register(UserInfoApi.class);
}
}
......@@ -3,6 +3,7 @@ package com.yxproject.start.config;
import com.yxproject.start.entity.SysPermission;
import com.yxproject.start.entity.SysRole;
import com.yxproject.start.entity.UserInfo;
import com.yxproject.start.service.LoginService;
import com.yxproject.start.service.UserInfoService;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
......@@ -12,6 +13,7 @@ import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -21,7 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
public class MyShiroRealm extends AuthorizingRealm {
@Autowired
private UserInfoService userInfoService;
private LoginService loginService;
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
System.out.println(principals.getPrimaryPrincipal());
......@@ -53,13 +55,14 @@ public class MyShiroRealm extends AuthorizingRealm {
System.out.println(token.getCredentials().toString());
//通过username从数据库中查找 User对象,如果找到,没找到.
//实际项目中,这里可以根据实际情况做缓存,如果不做,Shiro自己也是有时间间隔机制,2分钟内不会重复执行该方法
UserInfo user = userInfoService.findByUsername(username);
UserInfo user = loginService.findByUsername(username);
if(user == null){
return null;
}
SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
user,
user.getPassword(),
ByteSource.Util.bytes(user.getSalt()),
getName()
);
return authenticationInfo;
......
......@@ -58,7 +58,7 @@ public class ShiroConfig {
//散列算法:这里使用MD5算法;
hashedCredentialsMatcher.setHashAlgorithmName("md5");
//散列的次数,比如散列两次,相当于 md5("");
hashedCredentialsMatcher.setHashIterations(1);
hashedCredentialsMatcher.setHashIterations(1024);
return hashedCredentialsMatcher;
}
......
......@@ -4,24 +4,41 @@ import javax.persistence.*;
import java.io.Serializable;
import java.util.List;
/**
* @author liboyang
*/
@Entity
@Table(name="SYS_PERMISSION")
public class SysPermission implements Serializable {
@Id
@GeneratedValue
//主键.
@GeneratedValue(strategy = GenerationType.IDENTITY)
/**
* 主键.
*/
private Integer id;
//名称.
/**
* 名称.
*/
private String name;
@Column(columnDefinition="enum('menu','button')")
//资源类型,[menu|button]
/**
* 资源类型
*/
private String resourceType;
//资源路径.
/**
* 资源路径.
*/
private String url;
//权限字符串,menu例子:role:*,button例子:role:create,role:update,role:delete,role:view
/**
* 权限字符串,menu例子:role:*,button例子:role:create,role:update,role:delete,role:view
*/
private String permission;
//父编号
/**
* 父编号
*/
private Long parentId;
//父编号列表
/**
* 父编号列表
*/
private String parentIds;
private Boolean available = Boolean.FALSE;
@ManyToMany
......
......@@ -3,24 +3,49 @@ package com.yxproject.start.entity;
import javax.persistence.*;
import java.util.List;
/**
* @author liboyang
*/
@Entity
@Table(name="SYS_ROLE")
public class SysRole {
@Id
@GeneratedValue
private Integer id; // 编号
private String role; // 角色标识程序中判断使用,如"admin",这个是唯一的:
private String description; // 角色描述,UI界面显示使用
private Boolean available = Boolean.FALSE; // 是否可用,如果不可用将不会添加给用户
//角色 -- 权限关系:多对多关系;
/**
* 编号
*/
private Integer id;
/**
* 角色标识程序中判断使用,如"admin",这个是唯一的:
*/
private String role;
/**
* 角色描述,UI界面显示使用
*/
private String description;
/**
* 是否可用,如果不可用将不会添加给用户
*/
private Boolean available = Boolean.FALSE;
/**
* 角色 -- 权限关系:多对多关系;
*/
@ManyToMany(fetch= FetchType.EAGER)
@JoinTable(name="SysRolePermission",joinColumns={@JoinColumn(name="roleId")},inverseJoinColumns={@JoinColumn(name="permissionId")})
private List<SysPermission> permissions;
// 用户 - 角色关系定义;
/**
* 用户 - 角色关系定义;
*/
@ManyToMany
@JoinTable(name="SysUserRole",joinColumns={@JoinColumn(name="roleId")},inverseJoinColumns={@JoinColumn(name="uId")})
private List<UserInfo> userInfos;// 一个角色对应多个用户
@JoinTable(name="SysUserRole",joinColumns={@JoinColumn(name="roleId")},inverseJoinColumns={@JoinColumn(name="userId")})
/**
* 一个角色对应多个用户
*/
private List<UserInfo> userInfos;
public Integer getId() {
return id;
......@@ -46,7 +71,7 @@ public class SysRole {
this.description = description;
}
public Boolean getAvailable() {
public Boolean getAvailable(boolean b) {
return available;
}
......
package com.yxproject.start.entity;
import com.yxproject.start.entity.SysRole;
import javax.persistence.*;
import java.io.Serializable;
import java.util.List;
/**
* @author liboyang
*/
@Entity
@Table(name="USER_INFO")
public class UserInfo implements Serializable {
@Id
@GeneratedValue
private Integer uId;
private Integer id;
@Column(unique =true)
private String username;//帐号
private String name;//名称(昵称或者真实姓名,不同系统不同定义)
private String password; //密码;
private String salt;//加密密码的盐
private byte state;//用户状态,0:创建未认证(比如没有激活,没有输入验证码等等)--等待验证的用户 , 1:正常状态,2:用户被锁定.
@ManyToMany(fetch= FetchType.EAGER)//立即从数据库中进行加载数据;
@JoinTable(name = "SysUserRole", joinColumns = { @JoinColumn(name = "uId") }, inverseJoinColumns ={@JoinColumn(name = "roleId") })
private List<SysRole> roleList;// 一个用户具有多个角色
public Integer getUid() {
return uId;
private String username;
private String name;
private String password;
private String salt;
private byte state;
@ManyToMany(fetch= FetchType.EAGER)
@JoinTable(name = "SysUserRole", joinColumns = { @JoinColumn(name = "userId") }, inverseJoinColumns ={@JoinColumn(name = "roleId") })
private List<SysRole> roleList;
public Integer getId() {
return id;
}
public void setUid(Integer uid) {
this.uId = uId;
public void setUid(Integer id) {
this.id = id;
}
public String getUsername() {
......
package com.yxproject.start.mapper;
import com.yxproject.start.entity.UserInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import java.util.Map;
/**
* @author Administrator
*/
@Repository
public interface LoginMapper extends CrudRepository<UserInfo,Long> {
/**
* 通过用户名查询用户信息
* @param username
* @return
*/
public UserInfo findUserByUsername(String username);
}
......@@ -12,9 +12,12 @@ import java.util.Map;
* @author Administrator
*/
@Mapper
@Repository
public interface SysPermissionMapper {
// @Insert("INSERT INTO sys_permission (id,available,name,parent_id,parent_ids,permission,resource_type,url)\n" +
// "VALUES (PERMISSION_seq.nextval,false,'用户删除',1,'0/1','userInfo:del','button','userInfo/userDel')")
/**
* 新增权限
* @param sysPermission
*/
@Insert("INSERT INTO sys_permission (id,available,name,parent_id,parent_ids,permission,resource_type,url)\n" +
"VALUES (PERMISSION_seq.nextval,0,#{name},#{parentId},#{parentIds},#{permission},#{resourceType},#{url})")
public void addPermissionByMap(SysPermission sysPermission);
}
package com.yxproject.start.mapper;
import com.yxproject.start.entity.SysRole;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
/**
* @author liboyang
*/
@Mapper
public interface SysRoleMapper {
/**
* 添加角色
* @param sysRole
*/
@Insert({"INSERT INTO DAHAI.SYS_ROLE(ID,AVAILABLE,DESCRIPTION,ROLE)\n" +
"VALUES(PERMISSION_seq.nextval,0,#{description},#{role})"})
public void addRoleByMap(SysRole sysRole);
}
package com.yxproject.start.mapper;
import com.yxproject.start.entity.UserInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import java.util.Map;
/**
* @author Administrator
* @author liboyang
*/
@Mapper
@Repository
public interface UserInfoMapper extends CrudRepository<UserInfo,Long> {
public UserInfo findUserByUsername(String username);
// public int addUserInfo(UserInfo userInfo);
public interface UserInfoMapper {
/**
* 新增用户
* @param userinfo
*/
@Insert("INSERT INTO DAHAI.USER_INFO(ID, NAME, PASSWORD, STATE, USERNAME, SALT) " +
"VALUES(USER_INFO_seq.nextval,#{name},#{password},0,#{username},#{salt})\n")
public void saveUserInfo(UserInfo userinfo);
// public int delUserInfo(int userInfoID);
// public int updateUserInfo(UserInfo userInfo);
}
package com.yxproject.start.service;
import com.yxproject.start.entity.UserInfo;
/**
* @author liboyang
*/
public interface LoginService {
/**
* 查询用户
* @param username
* @return
*/
public UserInfo findByUsername(String username);
}
......@@ -7,7 +7,7 @@ import java.util.Map;
public interface SysPermissionService {
public void addPermission(SysPermission sysPermission);
public boolean addPermission(SysPermission sysPermission);
}
package com.yxproject.start.service;
import com.yxproject.start.entity.SysRole;
/**
* @author liboyang
*/
public interface SysRoleService {
/**
* 角色添加
* @param sysRole
* @return
*/
public boolean addRole(SysRole sysRole);
}
......@@ -4,12 +4,16 @@ import com.yxproject.start.entity.UserInfo;
import java.util.Map;
/**
* @author liboyang
*/
public interface UserInfoService {
// public UserInfo findUserRoleMenu(Map<String,String> map);
public UserInfo findByUsername(String username);
// int addUsername( UserInfo userInfo);
/**
* 新增用户
* @param userinfo
* @return
*/
public boolean addUser(UserInfo userinfo);
// int delUsername( UserInfo userInfo);
// int updateUsername(UserInfo userInfo);
}
package com.yxproject.start.service.impl;
import com.yxproject.start.entity.UserInfo;
import com.yxproject.start.mapper.LoginMapper;
import com.yxproject.start.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author liboyang
*/
@Service
public class LoginServiceImpl implements LoginService {
@Autowired
private LoginMapper loginMapper;
@Override
public UserInfo findByUsername(String username) {
UserInfo user = loginMapper.findUserByUsername(username);
return user;
}
}
......@@ -18,9 +18,9 @@ public class SysPermissionServiceImpl implements SysPermissionService{
private SysPermissionMapper sysPermissionMapper;
@Override
public void addPermission(SysPermission sysPermission) {
public boolean addPermission(SysPermission sysPermission) {
sysPermissionMapper.addPermissionByMap(sysPermission);
return true;
}
......
package com.yxproject.start.service.impl;
import com.yxproject.start.entity.SysRole;
import com.yxproject.start.mapper.SysRoleMapper;
import com.yxproject.start.service.SysRoleService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
* @author liboyang
*/
@Service
@Transactional(rollbackFor=Exception.class)
public class SysRoleServiceImpl implements SysRoleService {
@Autowired
private SysRoleMapper sysRoleMapper;
@Override
public boolean addRole(SysRole sysRole) {
sysRoleMapper.addRoleByMap(sysRole);
return true;
}
}
package com.yxproject.start.service.impl;
import com.yxproject.start.entity.UserInfo;
import com.yxproject.start.mapper.LoginMapper;
import com.yxproject.start.mapper.UserInfoMapper;
import com.yxproject.start.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -16,18 +17,11 @@ public class UserInfoServiceImpl implements UserInfoService {
private UserInfoMapper userInfoMapper;
@Override
public UserInfo findByUsername(String username) {
UserInfo user = userInfoMapper.findUserByUsername(username);
return user;
public boolean addUser(UserInfo userinfo) {
System.out.println("SystemUserService.addUser(UserInfo userInfo)");
userInfoMapper.saveUserInfo(userinfo);
return true;
}
// @Override
// public int addUsername(UserInfo userInfo) {
// System.out.println("SystemUserService.addUsername(UserInfo userInfo)");
// userInfoMapper.addUserInfo(userInfo);
// return 1;
// }
//
// @Override
// public int delUsername(UserInfo userInfo) {
......
#spring集成Mybatis环境
mybatis.type-aliases-package=com.yx_project.start.entity
#加载Mybatis配置文件
mybatis.mapper-locations = classpath:mapper/*Mapper.xml
mybatis.config-location = classpath:mapper/config/mybatis-config.xml
#mybatis.mapper-locations = classpath:mapper/*Mapper.xml
#mybatis.config-location = classpath:mapper/config/mybatis-config.xml
#配置数据库
......@@ -10,11 +10,17 @@ spring.datasource.driver-class-name= oracle.jdbc.driver.OracleDriver
spring.datasource.url = jdbc:oracle:thin:@192.168.10.208:1521:GTYX
spring.datasource.username = dahai
spring.datasource.password = dahai
#spring.datasource.schema = classpath:database/import.sql
#配置mysql数据库
#spring.datasource.driver-class-name= com.mysql.jdbc.Driver
#spring.datasource.url = jdbc:mysql://localhost:3306/test
#spring.datasource.username = root
#spring.datasource.password = root
#自动根据实体类生成数据库表
spring.jpa.hibernate.ddl-auto= update
spring.jpa.show-sql=true
# thymeleaf
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yxproject.start.mapper.SysPermissionMapper">
<resultMap id="PermissionMap" type="com.yxproject.start.entity.SysPermission">
<id column="id" property="id" />
<result column="name" property="name"/>
<result column="resource_type" property="resourceType"/>
<result column="url" property="url"/>
<result column="permission" property="permission"/>
<result column="parent_id" property="parentId"/>
<result column="parent_ids" property="parentIds"/>
<result column="available" property="available"/>
</resultMap>
<!--<?xml version="1.0" encoding="UTF-8" ?>-->
<!--<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >-->
<!--<mapper namespace="com.yxproject.start.mapper.SysPermissionMapper">-->
<!--&lt;!&ndash;<resultMap id="PermissionMap" type="com.yxproject.start.entity.SysPermission">&ndash;&gt;-->
<!--&lt;!&ndash;<id column="id" property="id" />&ndash;&gt;-->
<!--&lt;!&ndash;<result column="name" property="name"/>&ndash;&gt;-->
<!--&lt;!&ndash;<result column="resource_type" property="resourceType"/>&ndash;&gt;-->
<!--&lt;!&ndash;<result column="url" property="url"/>&ndash;&gt;-->
<!--&lt;!&ndash;<result column="permission" property="permission"/>&ndash;&gt;-->
<!--&lt;!&ndash;<result column="parent_id" property="parentId"/>&ndash;&gt;-->
<!--&lt;!&ndash;<result column="parent_ids" property="parentIds"/>&ndash;&gt;-->
<!--&lt;!&ndash;<result column="available" property="available"/>&ndash;&gt;-->
<!--&lt;!&ndash;</resultMap>&ndash;&gt;-->
<insert id="addPermissionByMap" parameterType="com.yxproject.start.entity.SysPermission">
Insert into DAHAI.SYS_PERMISSION (ID,AVAILABLE,NAME,PARENT_ID,PARENT_IDS,PERMISSION,RESOURCE_TYPE,URL) values (PERMISSION_seq.nextval,0,#{name},#{parentId},#{parentIds},#{permission},#{resourceType},#{url})
</insert>
</mapper>
\ No newline at end of file
<!--&lt;!&ndash;<insert id="addPermissionByMap" parameterType="com.yxproject.start.entity.SysPermission">&ndash;&gt;-->
<!--&lt;!&ndash;Insert into DAHAI.SYS_PERMISSION (ID,AVAILABLE,NAME,PARENT_ID,PARENT_IDS,PERMISSION,RESOURCE_TYPE,URL) values (PERMISSION_seq.nextval,0,#{name},#{parentId},#{parentIds},#{permission},#{resourceType},#{url})&ndash;&gt;-->
<!--&lt;!&ndash;</insert>&ndash;&gt;-->
<!--</mapper>-->
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yxproject.start.mapper.UserInfoMapper">
<!--&lt;!&ndash;用户&ndash;&gt;-->
<!--<resultMap id="UserRoleMenuMap" type="com.yxproject.start.entity.UserInfo">-->
<!--<id property="uid" column="uid"/>-->
<!--<result column="username" property="username"/>-->
<!--<result column="password" property="password"/>-->
<!--<result column="state" property="state"/>-->
<!--<result column="name" property="name"/>-->
<!--&lt;!&ndash;角色集合&ndash;&gt;-->
<!--<collection property="roleList" ofType="com.yxproject.start.entity.SysRole">-->
<!--<id column="id" property="rid" />-->
<!--<result column="description" property="description"/>-->
<!--<result column="role" property="role"/>-->
<!--&lt;!&ndash;权限集合&ndash;&gt;-->
<!--<collection property="permissions" ofType="com.yxproject.start.entity.SysPermission">-->
<!--<id column="id" property="pid" />-->
<!--<result column="name" property="pname"/>-->
<!--<result column="url" property="url"/>-->
<!--</collection>-->
<!--</collection>-->
<!--</resultMap>-->
<!--<select id="findUserByUsername" resultMap="UserRoleMenuMap" parameterType="string">-->
<!--select user_info.uid,user_info.username,user_info.password,user_info.name,sys_role.id as rid,sys_role.role,sys_role.description,-->
<!--sys_permission.id as pid,sys_permission.name as pname,sys_permission.url-->
<!--from user_info-->
<!--left join sys_user_role on user_info.uid = sys_user_role.uid-->
<!--left join sys_role on sys_user_role.role_id= sys_role.id-->
<!--left join sys_role_permission on sys_role.id = sys_role_permission.permission_id-->
<!--left join sys_permission on sys_role_permission.permission_id = sys_permission.id-->
<!--where username=#{username}-->
<!--</select>-->
<!--<?xml version="1.0" encoding="UTF-8" ?>-->
<!--<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >-->
<!--<mapper namespace="com.yxproject.start.mapper.UserInfoMapper">-->
<!--&lt;!&ndash;&lt;!&ndash;用户&ndash;&gt;&ndash;&gt;-->
<!--&lt;!&ndash;<resultMap id="UserRoleMenuMap" type="com.yxproject.start.entity.UserInfo">&ndash;&gt;-->
<!--&lt;!&ndash;<id property="uid" column="uid"/>&ndash;&gt;-->
<!--&lt;!&ndash;<result column="username" property="username"/>&ndash;&gt;-->
<!--&lt;!&ndash;<result column="password" property="password"/>&ndash;&gt;-->
<!--&lt;!&ndash;<result column="state" property="state"/>&ndash;&gt;-->
<!--&lt;!&ndash;<result column="name" property="name"/>&ndash;&gt;-->
<!--&lt;!&ndash;&lt;!&ndash;角色集合&ndash;&gt;&ndash;&gt;-->
<!--&lt;!&ndash;<collection property="roleList" ofType="com.yxproject.start.entity.SysRole">&ndash;&gt;-->
<!--&lt;!&ndash;<id column="id" property="rid" />&ndash;&gt;-->
<!--&lt;!&ndash;<result column="description" property="description"/>&ndash;&gt;-->
<!--&lt;!&ndash;<result column="role" property="role"/>&ndash;&gt;-->
<!--&lt;!&ndash;&lt;!&ndash;权限集合&ndash;&gt;&ndash;&gt;-->
<!--&lt;!&ndash;<collection property="permissions" ofType="com.yxproject.start.entity.SysPermission">&ndash;&gt;-->
<!--&lt;!&ndash;<id column="id" property="pid" />&ndash;&gt;-->
<!--&lt;!&ndash;<result column="name" property="pname"/>&ndash;&gt;-->
<!--&lt;!&ndash;<result column="url" property="url"/>&ndash;&gt;-->
<!--&lt;!&ndash;</collection>&ndash;&gt;-->
<!--&lt;!&ndash;</collection>&ndash;&gt;-->
<!--&lt;!&ndash;</resultMap>&ndash;&gt;-->
<!--&lt;!&ndash;<select id="findUserByUsername" resultMap="UserRoleMenuMap" parameterType="string">&ndash;&gt;-->
<!--&lt;!&ndash;select user_info.uid,user_info.username,user_info.password,user_info.name,sys_role.id as rid,sys_role.role,sys_role.description,&ndash;&gt;-->
<!--&lt;!&ndash;sys_permission.id as pid,sys_permission.name as pname,sys_permission.url&ndash;&gt;-->
<!--&lt;!&ndash;from user_info&ndash;&gt;-->
<!--&lt;!&ndash;left join sys_user_role on user_info.uid = sys_user_role.uid&ndash;&gt;-->
<!--&lt;!&ndash;left join sys_role on sys_user_role.role_id= sys_role.id&ndash;&gt;-->
<!--&lt;!&ndash;left join sys_role_permission on sys_role.id = sys_role_permission.permission_id&ndash;&gt;-->
<!--&lt;!&ndash;left join sys_permission on sys_role_permission.permission_id = sys_permission.id&ndash;&gt;-->
<!--&lt;!&ndash;where username=#{username}&ndash;&gt;-->
<!--&lt;!&ndash;</select>&ndash;&gt;-->
<!--<insert id = "addUserInfo" parameterType = "map" statementType = "PREPARED" keyProperty = "u_id" useGeneratedKeys = "true" >-->
<!--insert into USER_INFO (`u_id`,`username`,`name`,`password`,`salt`,`state`) VALUES (USER_INFO_seq.nextval, 'admin', '管理员', 'd3c59d25033dbf980d29554025c23a75', '8d78869f470951332959580424d4bf4f', 0)-->
<!--</insert>-->
<!--&lt;!&ndash;<insert id = "addUserInfo" parameterType = "map" statementType = "PREPARED" keyProperty = "u_id" useGeneratedKeys = "true" >&ndash;&gt;-->
<!--&lt;!&ndash;insert into USER_INFO (`u_id`,`username`,`name`,`password`,`salt`,`state`) VALUES (USER_INFO_seq.nextval, 'admin', '管理员', 'd3c59d25033dbf980d29554025c23a75', '8d78869f470951332959580424d4bf4f', 0)&ndash;&gt;-->
<!--&lt;!&ndash;</insert>&ndash;&gt;-->
<!--<update id = "delUserInfo" parameterType = "int" >-->
<!--update user_info set STATE = 1 where u_id =#{uId}-->
<!--</update>-->
<!--&lt;!&ndash;<update id = "delUserInfo" parameterType = "int" >&ndash;&gt;-->
<!--&lt;!&ndash;update user_info set STATE = 1 where u_id =#{uId}&ndash;&gt;-->
<!--&lt;!&ndash;</update>&ndash;&gt;-->
<!--<update id = "updateUserInfo" parameterType = "map" >-->
<!--update user_info set username =#{username},name =#{name},password =#{password} where u_id =#{uId}-->
<!--</update>-->
<!--&lt;!&ndash;<update id = "updateUserInfo" parameterType = "map" >&ndash;&gt;-->
<!--&lt;!&ndash;update user_info set username =#{username},name =#{name},password =#{password} where u_id =#{uId}&ndash;&gt;-->
<!--&lt;!&ndash;</update>&ndash;&gt;-->
<!--<select id="findUserByUsername" resultMap="UserRoleMenuMap" parameterType="string">-->
<!--select user_info.uid,user_info.username,user_info.password,user_info.name,sys_role.id as rid,sys_role.role,sys_role.description,-->
<!--sys_permission.id as pid,sys_permission.name as pname,sys_permission.url-->
<!--from user_info-->
<!--left join sys_user_role on user_info.uid = sys_user_role.uid-->
<!--left join sys_role on sys_user_role.role_id= sys_role.id-->
<!--left join sys_role_permission on sys_role.id = sys_role_permission.permission_id-->
<!--left join sys_permission on sys_role_permission.permission_id = sys_permission.id-->
<!--where username=#{username}-->
<!--</select>-->
<!--&lt;!&ndash;<select id="findUserByUsername" resultMap="UserRoleMenuMap" parameterType="string">&ndash;&gt;-->
<!--&lt;!&ndash;select user_info.uid,user_info.username,user_info.password,user_info.name,sys_role.id as rid,sys_role.role,sys_role.description,&ndash;&gt;-->
<!--&lt;!&ndash;sys_permission.id as pid,sys_permission.name as pname,sys_permission.url&ndash;&gt;-->
<!--&lt;!&ndash;from user_info&ndash;&gt;-->
<!--&lt;!&ndash;left join sys_user_role on user_info.uid = sys_user_role.uid&ndash;&gt;-->
<!--&lt;!&ndash;left join sys_role on sys_user_role.role_id= sys_role.id&ndash;&gt;-->
<!--&lt;!&ndash;left join sys_role_permission on sys_role.id = sys_role_permission.permission_id&ndash;&gt;-->
<!--&lt;!&ndash;left join sys_permission on sys_role_permission.permission_id = sys_permission.id&ndash;&gt;-->
<!--&lt;!&ndash;where username=#{username}&ndash;&gt;-->
<!--&lt;!&ndash;</select>&ndash;&gt;-->
<!--<select id="findUserByUsername" resultType="com.yxproject.start.entity.SystemUserEntity" parameterType="String">-->
<!--select * from "SYSTEM_USER" where username=#{username}-->
<!--</select>-->
</mapper>
\ No newline at end of file
<!--&lt;!&ndash;<select id="findUserByUsername" resultType="com.yxproject.start.entity.SystemUserEntity" parameterType="String">&ndash;&gt;-->
<!--&lt;!&ndash;select * from "SYSTEM_USER" where username=#{username}&ndash;&gt;-->
<!--&lt;!&ndash;</select>&ndash;&gt;-->
<!--</mapper>-->
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
</configuration>
\ No newline at end of file
<!--<?xml version="1.0" encoding="UTF-8"?>-->
<!--<!DOCTYPE configuration-->
<!--PUBLIC "-//mybatis.org//DTD Config 3.0//EN"-->
<!--"http://mybatis.org/dtd/mybatis-3-config.dtd">-->
<!--<configuration> -->
<!---->
<!--</configuration>-->
\ No newline at end of file
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="Thymeleaf"
xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<html xmlns:shiro="http://www.w3.org/1999/xhtml" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8"/>
<title>Insert title here</title>
......@@ -25,6 +24,9 @@
<p shiro:hasPermission="userInfo.add">
<a href="/userAdd">用户添加</a>
</p>
<p shiro:hasPermission="permission.add">
<a href="/permissionAdd">权限添加</a>
</p>
<hr />
......
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="Thymeleaf"
xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Login</title>
<!--<link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap.theme.min.css}"/>-->
<link rel="stylesheet" type="text/css" href="../static/css/bootstrap.theme.min.css"/>
<link rel="stylesheet" type="text/css" href="../static/css/bootstrap.min.css"/>
<script type="text/javascript" src="../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../static/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap.theme.min.css}"/>
<link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap.min.css}"/>
<script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap.min.js}"></script>
<script type="text/javascript">
$(function () {
var dheight = $(document).height();
......@@ -18,7 +16,7 @@
})
</script>
</head>
<body background="images\body_bg5.jpg">
<body background="@{/images/body_bg5.jpg}">
错误信息:<h4 th:text="${msg}"></h4>
<div class="container">
<div id="login" class="row">
......
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Add</title>
</head>
<body>
<h3>权限添加界面</h3>
<form action="" th:action="@{/permissionAdd}" method="post">
<p>名称:<input type="text" name="name" value="名称"/></p>
<p>资源类型:<input type="radio" name="resourceType" value="menu"/>menu
<input type="radio" name="resourceType" value="button"/>button</p>
<p>资源路径:<input type="text" name="url" value="userAdd"/></p>
<p>权限字符串:<input type="text" name="permission" value="userInfo.add"/></p>
<p>父编号:<input type="text" name="parentId" value="1"/></p>
<p>父编号列表:<input type="text" name="parentIds" value="0/1"/></p>
<p><input type="submit" value="添加"/></p>
</form>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Add</title>
</head>
<body>
<h3>角色添加界面</h3>
<form action="" th:action="@{/roleInfoAdd}" method="post">
<p>角色名称:<input type="text" name="role" value="vip"/></p>
<p>角色描述:<input type="text" name="description" value="会员"/></p>
<p>分配权限:<span th:each="roleList:${userInfo.roleList}">
<span th:each="permList:${roleList.permissions}">
<input type="checkbox" name="permissions" value="${permList.id}"><span th:text="${permList.name}"></span>
</span>
</span>
</p>
<p><input type="submit" value="添加"/></p>
</form>
</body>
</html>
\ No newline at end of file
......@@ -6,14 +6,10 @@
</head>
<body>
<h3>用户添加界面</h3>
<form action="" th:action="@{/permissionAdd}" method="post">
<p>名称:<input type="text" name="name" value="名称"/></p>
<p>资源类型:<input type="radio" name="resourceType" value="menu"/>menu
<input type="radio" name="resourceType" value="button"/>button</p>
<p>资源路径:<input type="text" name="url" value="userAdd"/></p>
<p>权限字符串:<input type="text" name="permission" value="userInfo.add"/></p>
<p>父编号:<input type="text" name="parentId" value="1"/></p>
<p>父编号列表:<input type="text" name="parentIds" value="0/1"/></p>
<form action="" th:action="@{/userInfoAdd}" method="post">
<p>用户名:<input type="text" name="username" value="用户名"/></p>
<p>名称:<input type="text" name="name" value="会员"/></p>
<p>密码:<input type="password" name="password" value="123456"/></p>
<p><input type="submit" value="添加"/></p>
</form>
</body>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment