1.参考
2.后台daoimpl无修改,有需要看前面的博客
3.action类(稍大程度的修改)
/**
*
*/
package com.jit.z2206.sue.md5webproject.action;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.jit.z2206.sue.md5webproject.model.Menu;
import com.jit.z2206.sue.md5webproject.service.MenuService;
import com.opensymphony.xwork2.ActionSupport;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
* @author sue wong
* 2017年7月26日上午9:15:46
* since v1.0
*/
public class MenuAction extends ActionSupport{
private JSONArray json;
private MenuService menuservice;
private Menu menu;
private List<Menu> list;
private JSONObject obj;
private JSONArray child;
/**
* @return the child
*/
public JSONArray getChild() {
return child;
}
/**
* @param child the child to set
*/
public void setChild(JSONArray child) {
this.child = child;
}
/**
* @return the obj
*/
public JSONObject getObj() {
return obj;
}
/**
* @param obj the obj to set
*/
public void setObj(JSONObject obj) {
this.obj = obj;
}
/**
* @return the menu
*/
public Menu getMenu() {
return menu;
}
/**
* @param menu the menu to set
*/
public void setMenu(Menu menu) {
this.menu = menu;
}
/**
* @return the json
*/
public JSONArray getJson() {
return json;
}
/**
* @param json the json to set
*/
public void setJson(JSONArray json) {
this.json = json;
}
/**
* @return the menuservice
*/
public MenuService getMenuservice() {
return menuservice;
}
/**
* @param menuservice the menuservice to set
*/
public void setMenuservice(MenuService menuservice) {
this.menuservice = menuservice;
}
public String execute()throws Exception{
JSONArray childMenu = new JSONArray();
if(menu.getId()==null){
menu.setId(0);
}
list=menuservice.findMenu(menu);
json=JSONArray.fromObject(list);
for(Menu m:list){
JSONObject jsonMenu=JSONObject.fromObject(m);
//System.out.println(m.getTid());
List<Menu> l=menuservice.findMenu(m);
JSONArray array=JSONArray.fromObject(l);
jsonMenu.put("children", array);
childMenu.add(jsonMenu);
}
child=childMenu;
System.out.println(child.toString());
/*Map<String,Object> map=new HashMap<String,Object>();
map.put("total", json.size());
map.put("rows",json);
obj=JSONObject.fromObject(map);
System.out.println(obj);*/
return "success";
}
}
4.前台无修改
5.数据库
6.效果图