EasyUI个人项目(一)
数据库表user表permission表role_permission表
登陆注册后端实体类dao层Action
前端xml文件register.jsp(注册)login.jsp(登陆)页面显示
登录后主界面后台实体类dao层Action
前端main.jsmainTemp.jsp页面显示
数据库表
user表
permission表
role_permission表
登陆注册
后端
实体类
package com
.rong
.entity
;
public class User {
private long id
;
private String name
;
private String pwd
;
private int type
;
public long getId() {
return id
;
}
public void setId(long id
) {
this.id
= id
;
}
public String
getName() {
return name
;
}
public void setName(String name
) {
this.name
= name
;
}
public String
getPwd() {
return pwd
;
}
public void setPwd(String pwd
) {
this.pwd
= pwd
;
}
public int getType() {
return type
;
}
public void setType(int type
) {
this.type
= type
;
}
@Override
public String
toString() {
return "User [id=" + id
+ ", name=" + name
+ ", pwd=" + pwd
+ ", type=" + type
+ "]";
}
public User(long id
, String name
, String pwd
, int type
) {
super();
this.id
= id
;
this.name
= name
;
this.pwd
= pwd
;
this.type
= type
;
}
public User() {
super();
}
}
dao层
package com
.rong
.dao
;
import java
.util
.List
;
import com
.rong
.entity
.Book
;
import com
.rong
.entity
.User
;
import com
.rong
.utils
.BaseDao
;
import com
.rong
.utils
.PageBean
;
import com
.rong
.utils
.PinYinUtil
;
import com
.rong
.utils
.StringUtils
;
public class UserDao extends BaseDao<User>{
public User
Login(User user
) throws Exception
{
String name
=user
.getName();
String pwd
=user
.getPwd();
String sql
="select * from t_easyui_user where true";
if(StringUtils
.isNotBlank(name
)) {
sql
+=" and name='"+name
+"'";
}
if(StringUtils
.isNotBlank(pwd
)) {
sql
+=" and pwd='"+pwd
+"'";
}
List
<User> list
=super.executeQuery(sql
, null
, User
.class);
if(list
.size()==0) {
return null
;
}
return list
.get(0);
}
public int add(User user
) throws Exception
{
String sql
="insert into t_easyui_user(name,pwd) values(?,?)";
return super.executeUpdate(sql
, user
,new String[] {"name","pwd"});
}
}
Action
package com
.rong
.web
;
import javax
.servlet
.http
.HttpServletRequest
;
import javax
.servlet
.http
.HttpServletResponse
;
import com
.rong
.dao
.UserDao
;
import com
.rong
.entity
.User
;
import com
.rong
.framework
.ActionSupport
;
import com
.rong
.framework
.ModelDriven
;
public class UserAction extends ActionSupport implements ModelDriven<User>{
private User user
=new User();
private UserDao userdao
=new UserDao();
@Override
public User
getModel() {
return user
;
}
public String
login(HttpServletRequest req
,HttpServletResponse resp
) {
try {
System
.out
.println("login");
User current
=this.userdao
.Login(user
);
if(current
==null
) {
return "mainTemp";
}
req
.getSession().setAttribute("currentUser", current
);
} catch (Exception e
) {
e
.printStackTrace();
}
return "mainTemp";
}
public String
add(HttpServletRequest req
,HttpServletResponse resp
) {
try {
this.userdao
.add(user
);
} catch (Exception e
) {
e
.printStackTrace();
}
return "login";
}
}
前端
xml文件
register.jsp(注册)
<%@ page language
="java" contentType
="text/html; charset=UTF-8"
pageEncoding
="UTF-8"%>
<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http
-equiv
="Content-Type" content
="text/html; charset=UTF-8">
<title>注册
</title
>
</head
>
<body>
<form
class="form-signin" action
="${pageContext.request.contextPath}/user.action?methodName=add" method
="post">
<h1
class="h3 mb-3">注册书城用户
</h1
>
<label
for="name">账号
</label
>
<input type
="text"
id
="name" name
="name" class="form-control" placeholder
="请输入账号"
required autofocus
>
<label
for="pwd">密码
</label
>
<input type
="password" id
="pwd" name
="pwd" class="form-control"
placeholder
="请输入密码" required
>
<input type
="submit" id
="login" value
="注册"/>
</form
>
</body
>
</html
>
login.jsp(登陆)
<%@ page language
="java" contentType
="text/html; charset=UTF-8"
pageEncoding
="UTF-8"%>
<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http
-equiv
="Content-Type" content
="text/html; charset=UTF-8">
<link rel
="stylesheet" type
="text/css"
href
="${pageContext.request.contextPath}/static/js/jquery-easyui-1.5.1/themes/default/easyui.css">
<link rel
="stylesheet" type
="text/css"
href
="${pageContext.request.contextPath}/static/js/jquery-easyui-1.5.1/themes/default/easyui.css">
<script type
="text/javascript"
src
="${pageContext.request.contextPath}/static/js/jquery-easyui-1.5.1/jquery.min.js"></script
>
<script type
="text/javascript"
src
="${pageContext.request.contextPath}/static/js/jquery-easyui-1.5.1/jquery.easyui.min.js"></script
>
<title>Insert title here
</title
>
</head
>
<body
class="text-center">
<form
class="form-signin" action
="${pageContext.request.contextPath}/user.action?methodName=login" method
="post">
<h1
class="h3 mb-3">用户登录
</h1
>
<label
for="name">账号
</label
>
<input type
="text"
id
="name" name
="name" class="form-control" placeholder
="请输入账号"
required autofocus
>
<label
for="pwd">密码
</label
>
<input type
="password" id
="pwd" name
="pwd" class="form-control"
placeholder
="请输入密码" required
>
<input type
="submit" id
="login" value
="登陆"/>
</form
>
</body
>
</html
>
页面显示
登陆(登陆成功后是跳下面的界面) 注册
登录后主界面
后台
实体类
permission
package com
.rong
.entity
;
public class Permission {
private long id
;
private String name
;
private String description
;
private String url
;
private long pid
;
private int ismenu
;
private long displayno
;
public long getId() {
return id
;
}
public void setId(long id
) {
this.id
= id
;
}
public String
getName() {
return name
;
}
public void setName(String name
) {
this.name
= name
;
}
public String
getDescription() {
return description
;
}
public void setDescription(String description
) {
this.description
= description
;
}
public String
getUrl() {
return url
;
}
public void setUrl(String url
) {
this.url
= url
;
}
public long getPid() {
return pid
;
}
public void setPid(long pid
) {
this.pid
= pid
;
}
public int getIsmenu() {
return ismenu
;
}
public void setIsmenu(int ismenu
) {
this.ismenu
= ismenu
;
}
public long getDisplayon() {
return displayno
;
}
public void setDisplayon(long displayno
) {
this.displayno
= displayno
;
}
@Override
public String
toString() {
return "Permission [id=" + id
+ ", name=" + name
+ ", description=" + description
+ ", url=" + url
+ ", pid="
+ pid
+ ", ismenu=" + ismenu
+ ", displayon=" + displayno
+ "]";
}
public Permission() {
super();
}
public Permission(long id
, String name
, String description
, String url
, long pid
, int ismenu
, long displayno
) {
super();
this.id
= id
;
this.name
= name
;
this.description
= description
;
this.url
= url
;
this.pid
= pid
;
this.ismenu
= ismenu
;
this.displayno
= displayno
;
}
}
rolepermission
package com
.rong
.entity
;
public class RolePermission {
private long rid
;
private long pid
;
public long getRid() {
return rid
;
}
public void setRid(long rid
) {
this.rid
= rid
;
}
public long getPid() {
return pid
;
}
public void setPid(long pid
) {
this.pid
= pid
;
}
public RolePermission(long rid
, long pid
) {
super();
this.rid
= rid
;
this.pid
= pid
;
}
public RolePermission() {
super();
}
}
dao层
permissiondao
package com
.rong
.dao
;
import java
.util
.ArrayList
;
import java
.util
.HashMap
;
import java
.util
.List
;
import java
.util
.Map
;
import com
.rong
.entity
.Permission
;
import com
.rong
.utils
.BaseDao
;
import com
.rong
.utils
.BuildTree
;
import com
.rong
.utils
.PageBean
;
import com
.rong
.vo
.TreeVo
;
public class PermissionDao extends BaseDao<Permission>{
public List
<Permission> list() throws Exception
{
String sql
="select * from t_easyui_permission where true";
return super.executeQuery(sql
,null
, Permission
.class);
}
public List
<Permission> menuTrees(String type
) throws Exception
{
String sql
="select * from t_easyui_permission where id in ("+type
+")";
return super.executeQuery(sql
,null
, Permission
.class);
}
public List
<TreeVo
<Permission>> topNodes(Permission permission
,PageBean pagebean
,String type
) throws Exception
{
List
<Permission> list
=this.menuTrees(type
);
List
<TreeVo
<Permission>> nodes
=new ArrayList<TreeVo
<Permission>>();
TreeVo treeVo
=null
;
for (Permission p
: list
) {
treeVo
=new TreeVo<>();
treeVo
.setId(p
.getId()+"");
treeVo
.setText(p
.getName());
treeVo
.setParentId(p
.getPid()+"");
Map
<String, Object> attributes
=new HashMap<String, Object>();
attributes
.put("self", p
);
treeVo
.setAttributes(attributes
);
nodes
.add(treeVo
);
}
return BuildTree
.buildList(nodes
,"0");
}
}
rolepermissiondao
package com
.rong
.dao
;
import java
.util
.List
;
import com
.rong
.entity
.RolePermission
;
import com
.rong
.utils
.BaseDao
;
public class RolePermissionDao extends BaseDao<RolePermission>{
public List
<RolePermission> list() throws Exception
{
String sql
="select * from t_easyui_role_permission where true";
return super.executeQuery(sql
,null
, RolePermission
.class);
}
public List
<RolePermission> getPids(long type
) throws Exception
{
String sql
="select * from t_easyui_role_permission where rid ="+type
;
return super.executeQuery(sql
, null
, RolePermission
.class);
}
}
Action
package com
.rong
.web
;
import java
.io
.IOException
;
import java
.sql
.SQLException
;
import java
.util
.List
;
import javax
.servlet
.http
.HttpServletRequest
;
import javax
.servlet
.http
.HttpServletResponse
;
import com
.fasterxml
.jackson
.databind
.ObjectMapper
;
import com
.rong
.dao
.PermissionDao
;
import com
.rong
.dao
.RolePermissionDao
;
import com
.rong
.entity
.Permission
;
import com
.rong
.entity
.RolePermission
;
import com
.rong
.entity
.User
;
import com
.rong
.framework
.ActionSupport
;
import com
.rong
.framework
.ModelDriven
;
import com
.rong
.utils
.ResponseUtil
;
import com
.rong
.vo
.TreeVo
;
public class PermissionAction extends ActionSupport implements ModelDriven<Permission> {
private Permission permission
=new Permission();
private RolePermissionDao roledao
=new RolePermissionDao();
private PermissionDao perdao
=new PermissionDao();
@Override
public Permission
getModel() {
return permission
;
}
public String
menuTrees(HttpServletRequest req
,HttpServletResponse resp
) throws IOException
{
try {
User curren
=(User
) req
.getSession().getAttribute("currentUser");
List
<RolePermission> pids
= roledao
.getPids(curren
.getType());
StringBuilder sb
= new StringBuilder();
for (RolePermission pid
: pids
) {
sb
.append(",").append(pid
.getPid());
}
List
<TreeVo
<Permission>> treevos
=this.perdao
.topNodes(null
, null
,sb
.substring(1));
ResponseUtil
.writeJson(resp
,treevos
);
} catch (InstantiationException e
) {
e
.printStackTrace();
} catch (IllegalAccessException e
) {
e
.printStackTrace();
} catch (SQLException e
) {
e
.printStackTrace();
} catch (Exception e
) {
e
.printStackTrace();
}
return null
;
}
public String
menuTree(HttpServletRequest req
,HttpServletResponse resp
) throws IOException
{
try {
ResponseUtil
.writeJson(resp
,this.perdao
.topNode(null
, null
));
} catch (InstantiationException e
) {
e
.printStackTrace();
} catch (IllegalAccessException e
) {
e
.printStackTrace();
} catch (SQLException e
) {
e
.printStackTrace();
} catch (Exception e
) {
e
.printStackTrace();
}
return null
;
}
}
前端
main.js
$
(function(){
var ctx
=$
("#ctx").val();
$
('#tt').tree({
url
:ctx
+'/permission.action?methodName=menuTrees',
onClick
: function(node
){
if($
('#tab').tabs('exists',node
.text
)){
$
('#tab').tabs('select',node
.text
);
}else{
var src
=node
.attributes
.self
.url
;
if(src
){
var content
='<iframe scrolling="no" frameborder="0" src="'+ctx
+src
+'" width="100%" height="100%"></iframe>';
$
('#tab').tabs('add',{
title
:node
.text
,
content
:content
,
closable
:true,
tools
:[{
iconCls
:'icon-mini-refresh',
handler
:function(){
alert('refresh');
}
}]
});
}
}
}
});
})
mainTemp.jsp
<%@ page language
="java" contentType
="text/html; charset=UTF-8"
pageEncoding
="UTF-8"%>
<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http
-equiv
="Content-Type" content
="text/html; charset=UTF-8">
<!-- 全局样式
-->
<link rel
="stylesheet" type
="text/css"
href
="${pageContext.request.contextPath}/static/js/jquery-easyui-1.5.1/themes/default/easyui.css">
<!-- 定义图标
-->
<link rel
="stylesheet" type
="text/css"
href
="${pageContext.request.contextPath}/static/js/jquery-easyui-1.5.1/themes/default/easyui.css">
<script type
="text/javascript"
src
="${pageContext.request.contextPath}/static/js/jquery-easyui-1.5.1/jquery.min.js"></script
>
<!-- 组件库源码
-js文件
-->
<script type
="text/javascript"
src
="${pageContext.request.contextPath}/static/js/jquery-easyui-1.5.1/jquery.easyui.min.js"></script
>
<script type
="text/javascript"
src
="${pageContext.request.contextPath}/static/js/main.js"></script
>
<title>登陆后的主界面
</title
>
</head
>
<input type
="hidden" id
="ctx" value
="${pageContext.request.contextPath}">
<body
class="easyui-layout">
<div data
-options
="region:'north',border:false"
style
="height: 60px; background: #B3DFDA; padding: 10px">xxx
管理系统
</div
>
<div data
-options
="region:'west',split:true,title:'West'"
style
="width: 150px; padding: 10px;">
<ul id
="tt"></ul
>
</div
>
<div
data
-options
="region:'east',split:true,collapsed:true,title:'East'"
style
="width: 100px; padding: 10px;">east region
</div
>
<div data
-options
="region:'south',border:false"
style
="height: 50px; background: #A9FACD; padding: 10px;">版权
</div
>
<div data
-options
="region:'center',title:'Center'">
<div id
="tab" class="easyui-tabs" style
="width: 100%; height: 100%;">
<div title
="首页" style
="padding: 20px; display: none;">欢迎来到网上书城
</div
>
</div
>
</div
>
</body
>
</html
>
页面显示
不同的用户登陆看到的是不一样的,分权限; 超管 普通用户