layui的增删改查

该博客详细介绍了如何利用layui框架进行增删改查功能的开发,包括实体类User和TreeNode的定义,UserDao接口的实现,工具类的使用,以及web层的BaseAction和UserAction控制器。同时,还涵盖了登录和用户管理的前后台JavaScript(login.js, userManagement.js)、JSP页面(login.jsp, userManagement.jsp)以及相关的配置文件如pop.xml、web.xml、struts-sy.xml等,最后展示了页面效果。" 92854864,7243283,Kirby:携程机票 Sketch 插件开发实践与设计系统,"['前端开发', '设计工具', 'UI设计', 'Sketch插件', 'Design System']
摘要由CSDN通过智能技术生成

实体类

User

public class User{
   	
	private String user_id;
	private String user_name;
	private String part_names;
	private String part_ids;

	
	
	public User(Map<String, Object> map) {
   
		super();
		this.user_id = map.get("user_id").toString();
		this.user_name = map.get("user_name").toString();
		this.part_names = map.get("part_names").toString();
		this.part_ids = map.get("part_ids").toString();
	}



	public String getUser_id() {
   
		return user_id;
	}



	public void setUser_id(String user_id) {
   
		this.user_id = user_id;
	}



	public String getUser_name() {
   
		return user_name;
	}



	public void setUser_name(String user_name) {
   
		this.user_name = user_name;
	}



	public String getPart_names() {
   
		return part_names;
	}



	public void setPart_names(String part_names) {
   
		this.part_names = part_names;
	}



	public String getPart_ids() {
   
		return part_ids;
	}



	public void setPart_ids(String part_ids) {
   
		this.part_ids = part_ids;
	}
	

TreeNode

public class TreeNode {
   
	private String id;
	private String name;
	private Map<String, Object> attributes = new HashMap<>();
	private List<TreeNode> children = new ArrayList<>();

	public String getId() {
   
		return id;
	}

	public void setId(String id) {
   
		this.id = id;
	}

	public String getName() {
   
		return name;
	}

	public void setName(String name) {
   
		this.name = name;
	}

	public Map<String, Object> getAttributes() {
   
		return attributes;
	}

	public void setAttributes(Map<String, Object> attributes) {
   
		this.attributes = attributes;
	}

	public List<TreeNode> getChildren() {
   
		return children;
	}

	public void setChildren(List<TreeNode> children) {
   
		this.children = children;
	}

	public TreeNode(String id, String text, Map<String, Object> attributes, List<TreeNode> children) {
   
		super();
		this.id = id;
		this.name = name;
		this.attributes = attributes;
		this.children = children;
	}

	public TreeNode() {
   
		super();
	}

	@Override
	public String toString() {
   
		return "TreeNode [id=" + id + ", name=" + name + ", attributes=" + attributes + ", children=" + children + "]";
	}

}

dao方法

UserDao

/**
 * 用户
 * 
 * @author 20190313
 *
 */
public class UserDao extends JsonBaseDao {
   

	/**
	 *登录
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	public User login(Map<String, String[]> paramMap) throws Exception {
   
		String user_id = JsonUtils.getParamVal(paramMap, "user_id");
		String sql = "select * from `user` where user_name = ? and  pwd = ? and statu = 1";
		List<Map<String, Object>> list = super.executeQuery(sql, new String[] {
   "user_name", "pwd"}, paramMap,
				null);
		if (list != null && list.size() > 0) {
   
			Map<String, Object> map = list.get(0);
			bindingStr(map.get("user_id").toString(), map);
			return new User(map);
		}
		return null;
	}

	/**
	 * 角色数据绑定
	 * 
	 * @return
	 */
	private void bindingStr(String user_id, Map<String, Object> map) throws Exception {
   
		String sql = "select a.part_id, a.part_name from part a, user_and_part b where a.part_id = b.part_id and b.user_id = "
				+ user_id;
		List<Map<String, Object>> list = super.executeQuery(sql, null);
		String part_names = "";
		String part_ids = "";
		for (Map<String, Object> m : list) {
   
			part_names += "," + m.get("part_name");
			part_ids += "," + m.get("part_id");
		}
		if (part_names.length() > 0) {
   
			part_ids = part_ids.substring(1);
			part_names = part_names.substring(1);
		}

		map.put("part_names", part_names);
		map.put("part_ids", part_ids);
	}

	/**
	 * 添加
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	public int add(Map<String, String[]> paramMap) throws Exception {
   
		String sql = "insert into `user` (user_name, pwd, statu)values (?, ?, 1)";
		int n = super.executeUpdate(sql, new String[] {
    "user_name", "pwd" }, paramMap);
		//获取当前插入id
		int maxId = executeByInteger("select max(user_id) from user ");
		// 角色数据插入
		String[] part_ids = JsonUtils.getParamVal(paramMap, "part_ids").split(",");
		bindingPart(maxId + "", part_ids);
		return n;
	}

	/**
	 *想用户角色表添加绑定数据(会将改用户以前的所有所有绑定信息删除)
	 * 
	 * @param user_id
	 * @param part_ids
	 */
	public void bindingPart(String user_id, String[] part_ids) {
   
		String sql = "delete from user_and_part where user_id = " + user_id;
		super.executeUpdate(sql);
		for (String part_id : part_ids) {
   
			super.executeUpdate("insert into user_and_part values(" + user_id + "," + part_id + ")");
		}
	}

	/**
	 * 删除
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	public int remove(Map<String, String[]> paramMap) throws Exception {
   
		String sql = "delete from `user` WHERE user_id = ?";
		// 删除用户绑定角色
		super.executeUpdate("delete from user_and_part where user_id =" + JsonUtils.getParamVal(paramMap, "user_id"));
		return super.executeUpdate(sql, new String[] {
    "user_id" }, paramMap);
	}

	/**
	 * 修改
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	public int edit(Map<String, String[]> paramMap) throws Exception {
   
		String sql = "update `user` set user_name = ?, pwd = ? where user_id = ?";
		int n = super.executeUpdate(sql, new String[] {
    "user_name", "pwd", "user_id" }, paramMap);
		String[] part_ids = JsonUtils.getParamVal(paramMap, "part_ids").split(",");
		bindingPart(JsonUtils.getParamVal(paramMap, "user_id"), part_ids);
		return n;
	}

	/**
	 * 修改状态
	 * 
	 * @param paramMap
	 * @return
	 * @throws Exception
	 */
	public int eidtStatu(Map<String, String[]> paramMap) throws Exception {
   
		String sql = "update `user` set statu = ? where user_id = ?";
		return super.executeUpdate(sql, new String[] {
    "statu", "user_id" }, paramMap);
	}


	/**
	 *  用户名是否重复
	 * 
	 * @return
	 */
	public boolean isName(Map<String, String[]> paramMap) throws Exception {
   
		List<Map<String, Object>> list = null;
		if(StringUtils.isNotBlank(JsonUtils.getParamVal(paramMap, "user_id"))) {
   
			String sql = "select user_id from user where user_id != ? and user_name = ?";
			 list = super.executeQuery(sql, new String[] {
    "user_id", "user_name" }, paramMap, null);		
		}else {
   
			String sql = "select user_id from user where user_name = ?";
			 list = super.executeQuery(sql, new String[] {
   "user_name" }, paramMap, null);		
		}	
		return list != null && list.size() > 0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值