Spring Menu Configuration

2019-09-04 14:20发布

I am working with the spring MVC 4 and configuring the menu in my home page which is to be shown based on role which i have define. So in my menu-config.xml i am defining as

<Menu name="Company" title="menu.companyTitle" page="/xxx/yyy/zzzz">
   <Item name="NewCompanyRequest" roles="ROLE_ADMIN,ROLE_USER" title="menu.NewCompanyRequest" page="/admin/companyRequestList" />
   <Item name="editCompanies" roles="ROLE_ADMIN" title="menu.editCompanies" page="/xx/yyy/ccc" />
</menu>
<Menu name="Exchaged" title="menu.admin.aboutCompany" page="/exchaged" roles="ROLE_ADMIN,ROLE_USER"/>  

Means the above item name editCompanies should be visible to ADMIN user only and it is working fine but in UI it disturbed the next menu Exchaged and bring in one.

I have tried to number of steps but din't work and not found solution.

1条回答
等我变得足够好
2楼-- · 2019-09-04 14:58

First of all, You are using wrong closing tag for Your <Menu> tag. I have corrected it and You can see it below code.

Next, You cannot add roles attribute in <Item> tag. You have to give this attribute in <Menu> tag instead. So, Your menu should be like below:

<Menu name="Company" title="menu.companyTitle" page="#" roles="ROLE_ADMIN,ROLE_USER">
    <Item name="NewCompanyRequest"  title="menu.NewCompanyRequest" page="/admin/companyRequestList" />
    <Item name="editCompanies" title="menu.editCompanies" page="/xx/yyy/ccc" />
</Menu> ...

or like below:

<Menu name="Company" title="menu.companyTitle" page="/xxx/yyy/zzzz" roles="ROLE_ADMIN">
    <Item name="NewCompanyRequest"  title="menu.NewCompanyRequest" page="/admin/companyRequestList" />
    <Item name="editCompanies" title="menu.editCompanies" page="/xx/yyy/ccc" />
</Menu> ...

or You can make dropdown menus separate menu and give separate role permission like below:

<Menu name="NewCompanyRequest" roles="ROLE_ADMIN,ROLE_USER" title="menu.NewCompanyRequest" page="/admin/companyRequestList" />
<Menu name="editCompanies" roles="ROLE_ADMIN" title="menu.editCompanies" page="/xx/yyy/ccc" />
查看更多
登录 后发表回答