当前位置:网站首页>Customize MVC project login registration and tree menu
Customize MVC project login registration and tree menu
2022-07-25 17:01:00 【Sooner or later, I will go bald】
Easyui and mvc project 1_ Login registration permission tree display
One 、 Sign in and register
Import tomcat And what the project needs jar Package and previously written tool classes 
Set up the database User Corpses ( user )
package com.mjx.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 + "]";
}
}
Write login and Registered dao Method
package com.mjx.dao;
import java.util.List;
import com.mjx.entity.RolePermission;
import com.mjx.entity.User;
import com.zking.util.BaseDao;
import com.zking.util.PageBean;
public class UserDao extends BaseDao<User> {
// land
public User login(User user) throws Exception {
String sql = "select * from t_easyui_user where name='" + user.getName() + "'and pwd='" + user.getPwd() + "'";
return super.executeQuery(sql, User.class, null).get(0);
}
// register
public void add(User user) throws Exception {
String sql = "insert into t_easyui_user(name,pwd) values(?,?)";
super.executeUpdate(sql, user, new String[] { "name", "pwd" });
}
}
Write UserAction
package com.mjx.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mjx.dao.UserDao;
import com.mjx.entity.User;
import com.zking.framework.ActionSupport;
import com.zking.framework.ModelDriver;
public class UserAction extends ActionSupport implements ModelDriver<User> {
private User user = new User();
private UserDao userDao = new UserDao();
@Override
public User getModel() {
// TODO Auto-generated method stub
return user;
}
// Sign in
public String login(HttpServletRequest req, HttpServletResponse resp) {
try {
User u = userDao.login(user);
if (u == null) {
return "toLogin";
}
req.getSession().setAttribute("cuser", u);
} catch (Exception e) {
e.printStackTrace();
return "toLogin";
}
// As long as the database has this user , Just jump to the main interface
return "main";
}
// register
public String register(HttpServletRequest req, HttpServletResponse resp) {
try {
userDao.add(user);
req.setAttribute("msg", " Wrong user name or password ");
} catch (Exception e) {
e.printStackTrace();
return "toRegister";
}
// If the registration is successful , Jump to the login screen
return "toLogin";
}
}
modify xml file , Corresponding to the page to jump
<?xml version="1.0" encoding="UTF-8"?>
<config>
<action path="/user" type="com.dzl.web.UserAction">
<forward name="main" path="/bg/mainTemp.jsp" redirect="false" /> <!-- forward -->
<forward name="toLogin" path="/login.jsp" redirect="true" /> <!-- Redirect -->
<forward name="toRegister" path="/register.jsp" redirect="false" />
</action>
<action path="/Permission" type="com.dzl.web.PermissionAction">
<forward name="toLogin" path="/login.jsp" redirect="true" /> <!-- Redirect -->
</action>
</config>
And main.js
$(function(){
$("#bookMenus").tree({
url:$("#ctx").val()+"/Permission.action?methodName=tree"
})
})
Running results :

Two 、 Display of tree menu
PermissionAction
package com.mjx.web;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mjx.dao.PermissionDao;
import com.mjx.dao.RolePermissionDao;
import com.mjx.dao.UserDao;
import com.mjx.entity.Permission;
import com.mjx.entity.RolePermission;
import com.mjx.entity.User;
import com.zking.framework.ActionSupport;
import com.zking.framework.ModelDriver;
import com.zking.util.BuildTree;
import com.zking.util.ResponseUtil;
import com.zking.util.TreeVo;
public class PermissionAction extends ActionSupport implements ModelDriver<Permission> {
private Permission permission = new Permission();
private PermissionDao permissionDao = new PermissionDao();
private UserDao userDao = new UserDao();
private RolePermissionDao rolePermissionDao = new RolePermissionDao();
public Permission getModel() {
// TODO Auto-generated method stub
return permission;
}
public String tree(HttpServletRequest req, HttpServletResponse resp) {
try {
User cuser = (User) req.getSession().getAttribute("cuser");
if (cuser == null) {
return "toLogin";
}
int type = cuser.getType();
List<RolePermission> rolePermissions = rolePermissionDao.findRolePermission(type);
StringBuffer sb = new StringBuffer();
for (RolePermission rp : rolePermissions) {
sb.append(",").append(rp.getPid());
}
List<TreeVo<Permission>> treePlus = permissionDao.treePlus(sb.substring(1));
// List<TreeVo<Permission>> tree = permissionDao.tree(null, null);
ResponseUtil.writeJson(resp, treePlus);
} catch (Exception e) {
e.printStackTrace();
try {
ResponseUtil.write(resp, "0");
} catch (Exception e1) {
e1.printStackTrace();
}
}
return null;
}
}
PermissionDao
package com.mjx.dao;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.mjx.entity.Permission;
import com.zking.util.BaseDao;
import com.zking.util.BuildTree;
import com.zking.util.PageBean;
import com.zking.util.TreeVo;
public class PermissionDao extends BaseDao<Permission> {
/*
* become easyui Of tree Control json Format
* 1.jackson Bring in
* 2. Get Permission Of list aggregate , Query database first
* 3.List<Permission> convert to List<TreeVo>
* 4. Through tool class BuildTree Convert level data into level data
*
*/
// The second step
public List<Permission> list(Permission Permission, PageBean pageBean) throws Exception {
String sql = "select * from t_easyui_Permission where 1=1";
return super.executeQuery(sql, Permission.class, null);
}
// The third step
public List<TreeVo<Permission>> tree(Permission permission, PageBean pageBean) throws Exception {
List<Permission> listPermission = this.list(permission, pageBean);
List<TreeVo<Permission>> listVo = new ArrayList<TreeVo<Permission>>();
for (Permission p : listPermission) {
System.out.println(p);
TreeVo<Permission> vo=new TreeVo<>();
vo.setId(p.getId()+"");
vo.setText(p.getName());
vo.setParentId(p.getPid()+"");
Map<String, Object> map =new HashMap<String, Object>();
map.put("self", p);
vo.setAttributes(map);
listVo.add(vo);
}
return BuildTree.buildList(listVo,"0");
}
public List<TreeVo<Permission>> treePlus(String ids) throws Exception {
List<Permission> listPermission = this.listPlus(ids);
List<TreeVo<Permission>> listVo = new ArrayList<TreeVo<Permission>>();
for (Permission p : listPermission) {
System.out.println(p);
TreeVo<Permission> vo=new TreeVo<>();
vo.setId(p.getId()+"");
vo.setText(p.getName());
vo.setParentId(p.getPid()+"");
Map<String, Object> map =new HashMap<String, Object>();
map.put("self", p);
vo.setAttributes(map);
listVo.add(vo);
}
return BuildTree.buildList(listVo,"0");
}
public List<Permission> listPlus(String ids) throws Exception {
String sql = "select * from t_easyui_Permission where id in ("+ids+")";
return super.executeQuery(sql, Permission.class, null);
}
/* at present :
* It is to query all menu data to form a hierarchical structure of attributes
* 1.select * from t_easyui_Permission where 1=1 and id in( Merchant menu id/ Buyer menu id)
* 2. buyers / The menu of the merchant id It is in the role permission table t_easyui_role_permission In order to get , adopt user In the table TYPE Field to query
*
* */
// public static void main(String[] args) {
// PermissionDao p = new PermissionDao();
// try {
// List<TreeVo<Permission>> l = p.tree(null, null);
// for (TreeVo<Permission> t : l) {
// System.out.println(t);
// }
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
}
RolePermissionDao
package com.mjx.dao;
import java.util.List;
import com.mjx.entity.RolePermission;
import com.zking.util.BaseDao;
public class RolePermissionDao extends BaseDao<RolePermission> {
// adopt rid Find out the corresponding pid
public List<RolePermission> findRolePermission(int type) throws Exception {
String sql = "select * from t_easyui_role_Permission where rid = "+type;
return super.executeQuery(sql, RolePermission.class, null);
}
}
Running results
The seller javaxl Sign in 
Ordinary buyers dzl Sign in 
边栏推荐
- What are the free low code development platforms?
- IaaS基础架构云 —— 云网络
- Rebudget汇报PPT
- Multi tenant software development architecture
- Jenkins' role based authorization strategy installation configuration
- [knowledge atlas] practice -- Practice of question and answer system based on medical knowledge atlas (Part5 end): information retrieval and result assembly
- [target detection] tph-yolov5: UAV target detection based on Transformer's improved yolov5
- 【数学建模绘图系列教程】二、折线图的绘制与优化
- ReBudget:通过运行时重新分配预算的方法,在基于市场的多核资源分配中权衡效率与公平性
- Fastadmin TP installation uses Baidu rich text editor ueeditor
猜你喜欢

Multi tenant software development architecture

【南京航空航天大学】考研初试复试资料分享

第六章 继承

Automatic reply of wechat official account development message

中国芯片自给率大幅提升,导致外国芯片库存高企而损失惨重,美国芯片可谓捧起石头砸自己的脚...

【小5聊】公众号排查<该公众号提供的服务出现故障,请稍后>

用秩讨论线性方程组的解/三个平面的位置关系

Chapter VI succession
![[Nanjing University of Aeronautics and Astronautics] information sharing for the first and second examinations of postgraduate entrance examination](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[Nanjing University of Aeronautics and Astronautics] information sharing for the first and second examinations of postgraduate entrance examination

复旦大学EMBA同学同行专题:始终将消费者的价值放在最重要的位置
随机推荐
新增批量删除
Mindoc makes mind map
WPF implements user avatar selector
MySQL之联表查询、常用函数、聚合函数
Homepage portal classification query
【小5聊】公众号排查<该公众号提供的服务出现故障,请稍后>
Slf4j and log4j2 process logs
谁动了我的内存,揭秘 OOM 崩溃下降 90% 的秘密
2022年最新北京建筑施工焊工(建筑特种作业)模拟题库及答案解析
数据分析与隐私安全成 Web3.0 成败关键因素,企业如何布局?
2D semantic segmentation -- deeplabv3plus reproduction
In the eyes of 100 users, there are 100 QQS
HCIP笔记十二天
文字翻译软件-文字批量翻译转换器免费
[target detection] yolov5 Runtong visdrone data set
Fudan University emba2022 graduation season - graduation does not forget the original intention and glory to embark on the journey again
Roson的Qt之旅#100 QML四种标准对话框(颜色、字体、文件、提升)
气数已尽!运营 23 年,昔日“国内第一大电商网站”黄了。。。
What are the free low code development platforms?
【目标检测】TPH-YOLOv5:基于transformer的改进yolov5的无人机目标检测