Skip to content

Commit 8940eb5

Browse files
author
marker
committed
菜单细节微调
1 parent 209c1c5 commit 8940eb5

8 files changed

Lines changed: 68 additions & 17 deletions

File tree

database/update.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ ALTER TABLE `mr_taolu`
3131

3232

3333

34+
-- 20170519
35+
ALTER TABLE `db_mrcms`.`mr_user_menu` ADD COLUMN `end` int AFTER `type`;
36+

src/main/java/org/marker/mushroom/beans/Menu.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class Menu implements Serializable {
2020
/** UUID唯一码 */
2121
private String type;
2222
private int sort = 0;
23+
/** 是否是同级节点的结尾 */
24+
private int end = 0;
2325
private String description;
2426

2527
public String getName() {
@@ -71,7 +73,13 @@ public String getType() {
7173
public void setType(String type) {
7274
this.type = type;
7375
}
74-
75-
76-
76+
77+
78+
public int getEnd() {
79+
return end;
80+
}
81+
82+
public void setEnd(int end) {
83+
this.end = end;
84+
}
7785
}

src/main/java/org/marker/mushroom/controller/MenuController.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import org.springframework.web.bind.annotation.ResponseBody;
1212
import org.springframework.web.servlet.ModelAndView;
1313

14+
import java.util.List;
15+
import java.util.Map;
16+
1417

1518
/**
1619
* 菜单管理
@@ -20,6 +23,10 @@
2023
@RequestMapping("/admin/menu")
2124
public class MenuController extends SupportController {
2225

26+
@Autowired private IMenuDao menuDao;
27+
28+
29+
2330
public MenuController() {
2431
this.viewPath = "/admin/menu/";
2532
}
@@ -45,7 +52,15 @@ public ModelAndView edit(@RequestParam("id") long id){
4552
@ResponseBody
4653
@RequestMapping("/update")
4754
public Object update(Menu menu,@RequestParam("id") int id){
48-
menu.setId(id);// 不能注入
55+
menu.setId(id);// 不能注入
56+
57+
int parentId = menu.getPid();
58+
59+
Menu maxMenu = menuDao.findChildMaxSortMenuByPId(parentId);
60+
if(maxMenu != null && (maxMenu.getSort() <= menu.getSort())){
61+
menu.setEnd(1);
62+
}
63+
4964
if(commonDao.update(menu)){
5065
return new ResultMessage(true, "更新成功!");
5166
}else{
@@ -63,9 +78,6 @@ public Object save(Menu menu){
6378
return new ResultMessage(false,"保存失败!");
6479
}
6580
}
66-
@Autowired private IMenuDao menuDao;
67-
68-
6981
//删除文章
7082
@ResponseBody
7183
@RequestMapping("/delete")
@@ -93,16 +105,22 @@ public Object delete(@RequestParam("rid") String rid){
93105

94106
/**
95107
* 用户组列表
96-
*
97-
* @param request
108+
*
98109
* @return
99110
*/
100111
@RequestMapping("/list")
101112
public ModelAndView list( ) {
102113
ModelAndView view = new ModelAndView(this.viewPath + "list");
103114
StringBuilder sql = new StringBuilder();
104115
sql.append("select * from ").append(getPrefix()).append("user_menu order by sort");
105-
view.addObject("menus", commonDao.queryForList(sql.toString()));
116+
List<Map<String,Object>> list = commonDao.queryForList(sql.toString());
117+
118+
119+
120+
121+
122+
123+
view.addObject("menus", list );
106124
return view;
107125
}
108126

src/main/java/org/marker/mushroom/dao/IMenuDao.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,11 @@ public interface IMenuDao extends ISupportDao{
6666
* @return
6767
*/
6868
boolean checkType(String type);
69-
69+
70+
/**
71+
* 查询最大排序的
72+
* @param parentId
73+
* @return
74+
*/
75+
Menu findChildMaxSortMenuByPId(int parentId);
7076
}

src/main/java/org/marker/mushroom/dao/impl/MenuDaoImpl.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,17 @@ public boolean checkType(String type) {
125125
return false;
126126
}
127127

128-
129-
130-
131-
128+
@Override
129+
public Menu findChildMaxSortMenuByPId(int parentId) {
130+
StringBuilder sql = new StringBuilder();
131+
sql.append("select * from ").append(dbConfig.getPrefix()).append("user_menu where pid=? order by sort desc limit 1");
132+
try{
133+
return this.jdbcTemplate.queryForObject(sql.toString(), new RowMapperMenu(), parentId);
134+
}catch(Exception e){
135+
logger.error("", e);
136+
}
137+
return null;
138+
}
139+
140+
132141
}

src/main/java/org/marker/mushroom/dao/mapper/ObjectRowMapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public Menu mapRow(ResultSet rs, int arg1) throws SQLException {
5454
menu.setIcon(rs.getString("icon"));
5555
menu.setSort(rs.getInt("sort"));
5656
menu.setUrl(rs.getString("url"));
57+
menu.setEnd(rs.getInt("end"));
58+
menu.setDescription(rs.getString("description"));
59+
menu.setType(rs.getString("type"));
5760
return menu;
5861
}
5962
}

src/main/webapp/WEB-INF/content/admin/menu/list.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
<#if id = menu.pid>
3232
<tr>
3333
<td>
34-
<#if temp gt 0 ><#list 1..temp as x>&nbsp; &nbsp;</#list></#if> <i class="fa ${menu.icon!}"></i> ${menu.name!}
34+
<#if temp gt 0 ><#list 1..temp as x>&nbsp; &nbsp;</#list>
35+
<#if menu.end == 1><#else></#if>
36+
37+
38+
</#if> <i class="fa ${menu.icon!}"></i> ${menu.name!}
3539
</td>
3640
<td>${menu.url!} </td>
3741
<td class="tac">${menu.sort?c} </td>

src/main/webapp/WEB-INF/content/admin/system/dbinfo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<li class="tab_index" onclick="setTabContent(this);"><h3>数据库配置</h3></li>
55
<li onclick="setTabContent(this);"><h3>连接池配置</h3></li>
66
</ul>
7-
<button class="btn_tabbar" onclick="submitActionForm(this);" return="system/dbinfo.do">保 存</button>
7+
<!--<button class="btn_tabbar" onclick="submitActionForm(this);" return="system/dbinfo.do">保 存</button>-->
88
</div>
99
<form id="myForm" action="system/savedbinfo.do" method="post">
1010
<div class="tab_content">

0 commit comments

Comments
 (0)