服务器之家

服务器之家 > 正文

java实现遍历树形菜单两种实现代码分享

时间:2021-01-30 12:11     来源/作者:一步一步完善

文本主要向大家分享了java实现遍历树形菜单的实例代码,具体如下。

OpenSessionView实现:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package org.web;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.dao.BaseHibernateDao;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
public class OpenSessionView extends BaseHibernateDao implements Filter {
    /**(非 Javadoc)
     * <p>Title: destroy</p>
     * <p>Description(描述): </p>
     * @see javax.servlet.Filter#destroy()
     */
    @Override
        public void destroy() {
        // TODO Auto-generated method stub
    }
    /**(非 Javadoc)
     * <p>Title: doFilter</p>
     * <p>Description(描述): </p>
     * @param arg0
     * @param arg1
     * @param arg2
     * @throws IOException
     * @throws ServletException
     * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
     */
    @Override
        public void doFilter(ServletRequest arg0, ServletResponse arg1,
                FilterChain arg2) throws IOException, ServletException {
        Session session = null;
        Transaction tx = null;
        try {
            session = getSession();
            tx = session.beginTransaction();
            arg2.doFilter(arg0, arg1);
            tx.commit();
        }
        catch (Exception e) {
            e.printStackTrace();
            tx.rollback();
        }
        finally{
            closeSession();
        }
    }
    /**(非 Javadoc)
     * <p>Title: init</p>
     * <p>Description(描述): </p>
     * @param arg0
     * @throws ServletException
     * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
     */
    @Override
        public void init(FilterConfig arg0) throws ServletException {
        // TODO Auto-generated method stub
    }
}

TreeAction实现

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package org.web;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.Service.IVoteTreeService;
import org.Service.impl.VoteTreeServiceImpl;
import com.alibaba.fastjson.JSON;
import com.opensymphony.xwork2.ActionSupport;
public class TreeAction extends ActionSupport {
    private JSONArray treejson;
    private IVoteTreeService voteService = new VoteTreeServiceImpl();
    public String getTree(){
        treejson = voteService.getTreeJson();
        return SUCCESS;
    }
    public JSONArray getTreejson() {
        return treejson;
    }
    public void setTreejson(JSONArray treejson) {
        this.treejson = treejson;
    }
}

总结

以上就是本文关于java实现遍历树形菜单两种实现代码分享的全部内容,希望对大家有所帮助。如果有什么不足之处,欢迎留下您的宝贵意见,小编会及时回复大家的。感谢朋友们对本站的支持!

原文链接:http://blog.csdn.net/qq_34137397/article/details/72655078

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享 2020-04-07
返回顶部