spring+srpingmvc+hibernate实现动态ztree生成树状图效果

网友投稿 402 2023-07-12

spring+srpingmvc+hibernate实现动态ztree生成树状图效果

spring+srpingmvc+hibernate实现动态ztree生成树状图效果

ztree生成树状图

ztree官网

前台

导入js和css包

-

前端页面 ztree.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" isELIgnored="false" %>

后台

ztree所需实体类

package com.shp.dev.common;

public class Ztree {

private String id;

private String pId;

private String name;

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getpId() {

return pId;

}

public void setpId(String pId) {

this.pId = pId;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public Ztree() {

}

public Ztree(String id, String pId, String name) {

this.id = id;

this.pId = pId;

IZjoOEAM this.name = name;

}

@Override

public String toString() {

return "Ztree{" +

"id='" + id + '\'' +

", pId='" + pId + '\'' +

", name='" + name + '\'' +

'}';

}

}

dao接口

package com.shp.dev.menu.dao;

import com.shp.dev.menu.pojo.Menu;

import java.util.List;

public interface MenuDao {

List

}

dao的实现类

package com.shp.dev.menu.dao;

import com.shp.dev.menu.pojo.Menu;

import org.hibernate.SessionFactory;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("menuDao")

public class MenuDaoImpl implements MenuDao{

@Autowired

private SessionFactory sessionFactory;

@Override

public List

return sessionFactory.getCurrentSession().createQuery("from Menu").list();

}

}

业务接口

package com.shp.dev.menu.service;

import com.shp.dev.menu.pojo.Menu;

import java.util.List;

public interface MenuService {

List

}

业务实现层

package com.shp.dev.menu.service;

import com.shp.dev.menu.dao.MenuDao;

import com.shp.dev.menu.pojo.Menu;

import com.shp.dev.role.dao.RoleDao;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("menuService")

public class MenuServiceImpl implements MenuService{

//@Transactional(readOnly = true)//只读事务

// @Transactional(rollbackFor = Exception.class)//启动事务,所有异常都回滚

@Autowired

private MenuDao menuDao;

@Override

@Transactional(readOnly = true)//只读事务

public List

return menuDao.queryAll();

}

}

控制层

package com.shp.dev.menu.web;

import com.shp.dev.common.Ztree;

import com.shp.dev.menu.pojo.Menu;

import com.shp.dev.menu.service.MenuService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;

import java.util.List;

@Controller

@RequestMapping("/menu")

public class MenuController {

@Autowired

private MenuService menuService;

@RequestMapping("/findZtree")

@ResponseBody // 返回json对象

public List findZtree(){

List menus=new ArrayList();

List

for (Menu m : query) {

menus.add(new Ztree(m.getId(),m.getParent_id(),m.getName()));

}

return menus;

}

}

总结

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Mybatis 缓存原理及失效情况解析
下一篇:Spring Boot项目中定制PropertyEditors方法
相关文章

 发表评论

暂时没有评论,来抢沙发吧~