重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

数据库控制动态菜单显示(SSM框架)

① 数据库设计:

创新互联建站从2013年开始,是专业互联网技术服务公司,拥有项目网站制作、做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元容城做网站,已为上家服务,为容城各地企业和个人服务,联系电话:18980820575

数据库映射的POJO类

@JsonIgnoreProperties(ignoreUnknown = true)
@Table(name="MENU")
public class Menu {
    @Id
    private String menuNumber;    //菜单编号         
    private String menuName;       //菜单名称
    private String menuUrl;            //菜单URL
    private String parentMenu;       //父级菜单
    private Integer menuPermissions; //菜单访问权限
    //Setter和Getter及toString()省略
    }

②通过mybaites访问数据的Mapper类

public interface MenuMapper {
     //通过菜单的父级菜单和菜单的权限获取菜单(初始化时要获取所有的一级菜单)
    @Select("select * from MENU where LENGTHB(Parent_Menu) = #{menulevel} and Menu_Permissions=#{permissions}")
    List selectMenuByLevelAndPer(@Param("menulevel")int menulevel,@Param("permissions")int permissions);
}

③服务层Service
``
@Service
public class MenuServiceImp implements MenuService{
    @Autowired
    private MenuMapper  menuMapper;
    @Override
    public List getMenuByParent(String parentMenu,Integer menuPermissions) {
        // TODO Auto-generated method stub
        Menu menu = new Menu();
        menu.setParentMenu(parentMenu);
        menu.setMenuPermissions(menuPermissions);
        List menuList = menuMapper.select(menu);  //“menuMapper.select(menu)” 函数通过JPA实现
        return menuList;
    }

    @Override
    public List getMenuByLevel(Integer menulevel,Integer menuPermissions) {
        // TODO Auto-generated method stub
        if(menulevel<=0) return null;
        //通过父级菜单查询
        System.out.println(menulevel+" ==== " + menuPermissions);
        if(menuPermissions==null)
            return menuMapper.selectMenuByLevel(menulevel);
        else
            return menuMapper.selectMenuByLevelAndPer(menulevel, menuPermissions);
    }
}

④控制器Controller

 @RequestMapping("/getMenuInit")
    public @ResponseBody List getMenuInit(Integer perminsion){
        System.out.println("getMenuInit" +"=="+ perminsion);
        //System.out.println(menuService.getAllMenu().toString());
        return menuService.getMenuByLevel(1, perminsion);
    }

    @RequestMapping("/getMenu")
    public @ResponseBody List getMenu(String parentMenu,Integer perminsion){
        System.out.println(" getMenu:" + parentMenu+" == "+ perminsion);
        //System.out.println(menuService.getAllMenu().toString());
        return menuService.getMenuByParent(parentMenu, perminsion);
    }

⑤前端页面设计
初始化调 jQuery函数:访问所有的一级菜单

 ` var flag=0;
   $("#showDiv").html("")
   $.ajax(
           {
           url:"/menu/getMenuInit",
           data:{"perminsion":"2"},
           type:"post",
           dataType:"json",
           success:function(data)
           {
               for(var i=0;i"
                      +""+
                      menu.menuName+
                      "")                
               }
            }
         })
     单击时调用函数
     ```
function getMenu(parentMenu,perminsion,divid){  
   var div = document.getElementById("showDiv").getElementsByTagName("li")[divid]
   if(parentMenu.length%2!=0)
       parentMenu="0"+parentMenu;

   if(div.getElementsByTagName("li").length>1){
       for(var i=0;i"+menu.menuName+"" 
               }
               div.innerHTML = HTML;
           }
     });

}

     ```

当前文章:数据库控制动态菜单显示(SSM框架)
本文URL:http://cqcxhl.cn/article/peddej.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP