目录
今天继续跟大家分享LayUi的知识以及实现会议OA系统的用户管理。
涉及到的知识点主要是LayUi的数据表格和弹出层,用来实现用户管理的增删改查。
一、后端
我们以t_oa_user表为例
1、实体类User
package com.zking.entity;
/**
* 朱佳音
* @author Administrator
*
*/
public class User {
private Long id;
private String name;
private String loginName;
private String pwd;
private Long rid;
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 getLoginName() {
return loginName;
}
public void setLoginName(String loginName) {
this.loginName = loginName;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public Long getRid() {
return rid;
}
public void setRid(Long rid) {
this.rid = rid;
}
public User() {
super();
// TODO Auto-generated constructor stub
}
@Override
public String toString() {
return "User [id=" + id + ", name=" + name + ", loginName=" + loginName + ", pwd=" + pwd + ", rid=" + rid + "]";
}
}
2、Dao层
package com.zking.dao;
import java.util.List;
import java.util.Map;
import com.zking.entity.User;
import com.zking.util.BaseDao;
import com.zking.util.PageBean;
import com.zking.util.StringUtils;
/**
* 朱佳音
* @author Administrator
*
*/
public class UserDao extends BaseDao<User> {
public List<User> list(User user, PageBean pageBean) throws Exception {
String sql = "select * from t_oa_user where 1=1 ";
String name = user.getName();
if (StringUtils.isNotBlank(name))
sql += " and name like '%" + name + "%'";
return super.executeQuery(sql, User.class, pageBean);
}
// 根据会议ID查询相关用户
public List<User> queryUserByMeetingId(Long meetingId) throws Exception{
String sql="select * from t_oa_user where FIND_IN_SET(id,"
+ "(select concat(canyuze,',',liexize,',',zhuchiren) "
+ "from t_oa_meeting_info where id="+meetingId+"))";
return super.executeQuery(sql, User.class, null);
}
// 获取用户多选框数据
public List<Map<String, Object>> queryUserAll(User user, PageBean pageBean) throws Exception {
String sql = "SELECT name,id as value from t_oa_user";
return super.executeQuery(sql, pageBean);
}
public List<Map<String, Object>> listUserRole(User user, PageBean pageBean) throws Exception {
String sql = "select *,\r\n" +
"(case rid\r\n" +
"when 1 then '管理人员'\r\n" +
"when 4 then '参与者'\r\n" +
"else '其他角色' end) as rname\r\n" +
"from t_oa_user ";
String name = user.getName();
if (StringUtils.isNotBlank(name))
sql += " and name like '%" + name + "%'";
return super.executeQuery(sql, pageBean);
}
public int add(User user) throws Exception {
String sql = "insert into t_oa_user(name,loginName,pwd) values(?,?,?)";
return super.executeUpdate(sql, user, new String[] {"name","loginName","pwd"});
}
public int edit(User user) throws Exception {
String sql = "update t_oa_user set name = ?,loginName = ?,pwd = ? where id = ?";
return super.executeUpdate(sql, user, new String[] {"name","loginName","pwd","id"});
}
public int del(User user) throws Exception {
String sql = "delete from t_oa_user where id = ?";
return super.executeUpdate(sql, user, new String[] {"id"});
}
public User login(User user, PageBean pageBean) throws Exception {
String loginName = user.getLoginName();
String pwd = user.getPwd();
String sql = "select * from t_oa_user where loginname = '" + loginName + "' and pwd = '"+pwd+"'";
List<User> users = super.executeQuery(sql, User.class, pageBean);
return users == null |