本文主要是介绍SpringBoot打造企业级进销存储系统 第七讲,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
@Transientprivate String roles; // 所拥有的角色
package com.java1234.entity;import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;import org.hibernate.validator.constraints.NotEmpty;/*** 用户实体* @author Administrator**/
@Entity
@Table(name="t_user")
public class User {@Id@GeneratedValueprivate Integer id; // 编号@NotEmpty(message="请输入用户名!")@Column(length=50)private String userName; // 用户名@NotEmpty(message="请输入密码!")@Column(length=50)private String password; // 密码@Column(length=50)private String trueName; // 真实姓名@Column(length=1000)private String remarks; // 备注@Transientprivate String roles; // 所拥有的角色public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public String getTrueName() {return trueName;}public void setTrueName(String trueName) {this.trueName = trueName;}public String getRemarks() {return remarks;}public void setRemarks(String remarks) {this.remarks = remarks;}public String getRoles() {return roles;}public void setRoles(String roles) {this.roles = roles;}}
package com.java1234.controller.admin;import java.util.HashMap;
import java.util.List;
import java.util.Map;import javax.annotation.Resource;import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;import com.java1234.entity.Role;
import com.java1234.entity.User;
import com.java1234.service.RoleService;
import com.java1234.service.UserService;@Controller
@RequestMapping("/admin/user")
public class UserAdminController {@Resourceprivate UserService userService;@Resourceprivate RoleService roleService;/*** 分页查询用户信息* @param user* @param page* @param rows* @return* @throws Exception*/@ResponseBody@RequestMapping("/list")public Map<String,Object> list(User user,@RequestParam(value="page",required=false)Integer page,@RequestParam(value="rows",required=false)Integer rows)throws Exception{Map<String,Object> resultMap=new HashMap<>();List<User> userList=userService.list(user, page, rows, Direction.ASC, "id");for(User u:userList){List<Role> roleList=roleService.findByUserId(u.getId());StringBuffer sb=new StringBuffer();for(Role r:roleList){sb.append(","+r.getName());}u.setRoles(sb.toString().replaceFirst(",", ""));}Long total=userService.getCount(user);resultMap.put("rows", userList);resultMap.put("total", total);return resultMap;}}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户管理</title>
<link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/default/easyui.css"></link>
<link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.3.3/themes/icon.css"></link>
<script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="/static/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/static/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">function formatEdit(val,row){return "<a href=''><img style='margin-top:4px' src='/static/images/edit.gif'/></a>";}function searchUser(){$("#dg").datagrid('load',{"userName":$("#s_userName").val()});}
</script>
</head>
<body style="margin: 1px"><table id="dg" title="用户管理" class="easyui-datagrid"fitColumns="true" pagination="true" rownumbers="true" singleSelect="true"url="/admin/user/list" fit="true" toolbar="#tb"><thead><th field="id" width="20" align="center">编号</th><th field="userName" width="50" align="center">用户名</th><th field="password" width="50" align="center">密码</th><th field="trueName" width="50" align="center">真实姓名</th><th field="remarks" width="80" align="center">备注</th><th field="roles" width="150" align="center">拥有角色</th><th field="aa" width="50" align="center" formatter="formatEdit">角色设置</th></thead></table><div id="tb"><div><a href="javascript:openUserAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a><a href="javascript:openUserModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a><a href="javascript:deleteUser()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a></div><div> 用户名: <input type="text" id="s_userName" size="20" onkeydown="if(event.keyCode==13) searchUser()"/><a href="javascript:searchUser()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a></div></div>
</body>
</html>
这篇关于SpringBoot打造企业级进销存储系统 第七讲的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!