系统资源包括目录、菜单、按钮,资源存在上下级关系,单表外键关联自己,达到上下级关系。
CREATE TABLE `resources` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`parentId` int(11) NULL DEFAULT NULL,
`resKey` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`type` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`resUrl` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`level` int(11) NULL DEFAULT NULL,
`description` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 43 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
$(function() {
grid = window.lanyuan.ui.lyGrid({
id : 'paging',
l_column : [ {
colkey : "id",
name : "id",
width : "50px",
hide : true
}, {
colkey : "name",
name : "菜单名称",
align : 'left'
}, {
colkey : "type",
name : "菜单类型",
width : "70px",
}, {
colkey : "resUrl",
name : "URL地址"
}, {
colkey : "description",
name : "描述"
} ],
jsonUrl : '${ctx}/background/resources/resources.html',
checkbox : true,
usePage : false,
records : "resourceslists",
treeGrid : {
tree : true,
name : 'name'
}
});
说明:
1、页面初始化lyGrid加载表格数据。
2、定义后台调用查询列表接口。
/**
* 加载资源列表
**/
@ResponseBody
@RequestMapping("resources")
public Map<String, Object> resourcess(Resources resources, HttpServletRequest request) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
List<Resources> rs;
if (PropertiesUtils.findPropertiesKey("rootName").equals(Common.findAuthenticatedUsername())) {
rs = resourcesService.queryAll(resources);
} else {
rs = resourcesService.findAccountResourcess(Common.findUserSessionId(request));
}
List<TreeObject> treeObjects = new ArrayList<TreeObject>();
for (Resources res : rs) {//转换为树对象
TreeObject t = new TreeObject();
PropertyUtils.copyProperties(t, res);
treeObjects.add(t);
}
List<TreeObject> ns = TreeUtil.getChildResourcess(treeObjects, 0);
map.put("resourceslists", ns);
return map;
}
说明:
1、若登录者是超级管理员,则加载所有资源。
2、若非超级管理员,则只加载该帐号角色的资源列表。
3、组织资源数据成树结构,返回页面渲染。
<select id="queryAll" resultType="com.lanyuan.entity.Resources" parameterType="com.lanyuan.entity.Resources">
SELECT
<include refid="selectId" />
FROM sys_res
<where>
<if test="name != null and name != ''">
AND name like '%${name}%'
</if>
<if test="parentId != null">
AND parentId =#{parentId}
</if>
</where>
order by level asc
</select>
软件定制及其他业务
请加微信号:13128600812
公众号: