先贴个效果图:
用easyui-layout布局主框架,index.jsp内容如下:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path ;
%>
家庭财务管理系统
家庭财务管理系统
下面来看左菜单的实现。
package system.homebank.controller;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import system.homebank.entity.Menu;
import system.homebank.service.MenuService;
import system.homebank.utils.MenuUtils;
@Controller
public class HomePageController
{
@Resource
private MenuService service;
@RequestMapping("/home.do")
public String forward(Model model)
{
List
MenuService接口中主要提供菜单数据的读取。
MenuUtils.buildMenus(list)将菜单数据解析成html串。
下面看MenuUtils.java:
package system.homebank.utils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import system.homebank.entity.Menu;
import system.homebank.model.TreeNode;
public class MenuUtils
{
public static String buildMenus(List
package system.homebank.model;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class TreeNode implements Serializable
{
private static final long serialVersionUID = 2235783844919124916L;
private String id;
private String text;
private Attributes attributes;
private String parentid;
private List children;
public TreeNode()
{
}
public TreeNode(Integer id, String text,String url, Integer parentid)
{
this.id = id.toString();
this.text = text;
this.attributes = new Attributes();
this.attributes.setUrl(url);
this.parentid = parentid.toString();
}
public void addChild(TreeNode child)
{
if (this.children == null)
{
this.children = new ArrayList();
}
this.children.add(child);
}
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public String getText()
{
return text;
}
public void setText(String text)
{
this.text = text;
}
public Attributes getAttributes()
{
return attributes;
}
public void setAttributes(Attributes attributes)
{
this.attributes = attributes;
}
public String getParentid()
{
return parentid;
}
public void setParentid(String parentid)
{
this.parentid = parentid;
}
public List getChildren()
{
return children;
}
public void setChildren(List children)
{
this.children = children;
}
}
以上为实现左菜单的主要代码。
菜单表的设计如下:
CREATE TABLE `menu` (
`id` decimal(4,0) NOT NULL,
`menuname` varchar(50) NOT NULL,
`url` varchar(100) DEFAULT NULL,
`parentid` decimal(4,0) DEFAULT NULL,
PRIMARY KEY (`id`)
)