java實(shí)現(xiàn)遍歷樹形菜單兩種實(shí)現(xiàn)代碼分享
文本主要向大家分享了java實(shí)現(xiàn)遍歷樹形菜單的實(shí)例代碼,具體如下。
OpenSessionView實(shí)現(xiàn):
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實(shí)現(xiàn)
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;
}
}
總結(jié)
以上就是本文關(guān)于java實(shí)現(xiàn)遍歷樹形菜單兩種實(shí)現(xiàn)代碼分享的全部內(nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站:java中變量和常量詳解、淺談java中==以及equals方法的用法、創(chuàng)建并運(yùn)行一個(gè)java線程方法介紹等,如果有什么不足之處,歡迎留下您的寶貴意見,小編會(huì)及時(shí)回復(fù)大家的。感謝朋友們對(duì)本站的支持!
相關(guān)文章
詳解分別用Kotlin和java寫RecyclerView的示例
本篇文章主要介紹了詳解分別用Kotlin和java寫RecyclerView的示例,詳解分別用Kotlin和java寫RecyclerView的示例2017-12-12
SpringBoot使用CommandLineRunner和ApplicationRunner執(zhí)行初始化業(yè)務(wù)方式
這篇文章主要介紹了SpringBoot使用CommandLineRunner和ApplicationRunner執(zhí)行初始化業(yè)務(wù)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08
SpringBoot 將多個(gè)Excel打包下載的實(shí)現(xiàn)示例
本文主要介紹了SpringBoot 將多個(gè)Excel打包下載的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-12-12
Mybatis動(dòng)態(tài)Sql標(biāo)簽使用小結(jié)
本文主要介紹了Mybatis動(dòng)態(tài)Sql標(biāo)簽使用,常用的動(dòng)態(tài)sql標(biāo)簽包括?if、choose(when、otherwise)、trim(where、set)、foreach,下面就來介紹一下2024-04-04
線程池調(diào)用kafka發(fā)送消息產(chǎn)生的內(nèi)存泄漏問題排查解決
這篇文章主要為大家介紹了線程池調(diào)用kafka發(fā)送消息產(chǎn)生的內(nèi)存泄漏問題排查解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08
IDEA使用Tomcat運(yùn)行web項(xiàng)目教程分享
在非Spring Boot項(xiàng)目中運(yùn)行Nacos示例,需要手動(dòng)配置Tomcat容器,本文介紹了如何在IDEA中配置Tomcat,并詳細(xì)解決了配置過程中可能遇到的異常情況,步驟包括修改IDEA項(xiàng)目結(jié)構(gòu)、添加Web模塊、配置Artifacts和Tomcat Server2024-10-10

