Spring3MVC+MyBatis+ExtJs3整合开发系列之二:菜单模块演示
我又回来了,带来了Spring3MVC+MyBatis+ExtJs3整合开发系列之第二篇:菜单模块演示。
承接上篇Spring3MVC+MyBatis+ExtJs3整合开发系列之一:登录模块演示,本篇增加了菜单加载的功能到本项目中。
菜单模块结构图:

domain层
public class Menu implements Serializable {private static final long serialVersionUID = -2726709540069876682L;private Long id;private Long parent_id;private String name;private String image;private String url;private String qtip;private Integer sortNum;private String description;/** * true:默认为叶子结点,即子菜单 */private boolean leaf = true;private List<Menu> children;@Servicepublic class MenuService {@Autowiredprivate MenuMapper menuMapper;@Transactionalpublic List<Menu> getMenuListByUserId(Long userId) {Map<String,Object> param = new HashMap<String,Object>();List<Menu> mainMenuList = menuMapper.getMainMenuList(userId);Iterator<Menu> it = mainMenuList.iterator();//装载主菜单下所有的子菜单while(it.hasNext()) {Menu menu = it.next();//false:表示为主菜单menu.setLeaf(false);Long parentId = menu.getId();param.put("userId", userId);param.put("parentId", parentId);List<Menu> subMenuList = menuMapper.getSubMenuList(param);menu.setChildren(subMenuList);}return mainMenuList;}}@Controller@RequestMapping("/user")public class UserController {@Autowiredprivate UserService userService;@Autowiredprivate MenuService menuService;/** * 获取所有菜单 * @param request * @param response * @return */@RequestMapping(value="/Menus",method=RequestMethod.POST)public @ResponseBody Map<String,Object> getTopMenus(HttpServletRequest request, HttpServletResponse response){Map<String,Object> result = new HashMap<String,Object>();User user = (User)request.getSession().getAttribute("user");List<Menu> list = menuService.getMenuListByUserId(user.getId());result.put("success", "true");result.put("data", list);return result;}