springmvc+mabatis框架,显示权限模块的树状图
这是sql语句
SELECT M_ID as id, M_PID as pId, M_NAME as name, M_NODE as isParent,'true' checked, M_CODE,'true' open FROM T_MODULES t WHERE M_PID = #{NODE,jdbcType=VARCHAR} and M_ID in
(SELECT M_ID FROM T_ROLES_MODULES WHERE R_ID = #{RID,jdbcType=VARCHAR})
UNION
SELECT M_ID as id, M_PID as pId, M_NAME as name, M_NODE as isParent,'false' checked, M_CODE,'true' open FROM T_MODULES t WHERE M_PID = #{NODE,jdbcType=VARCHAR} and M_ID NOT IN
(SELECT M_ID FROM T_ROLES_MODULES WHERE R_ID = #{RID,jdbcType=VARCHAR}) ORDER BY M_CODE ASC
怎么才能显示数据
@ResponseBody
@RequestMapping("/selectNodeTree")
public void selectNodeTree(String RID,String NODE, HttpServletResponse response) {
try {
Map map = new HashMap();
map.put("RID", RID);
if(NODE == null || NODE.equals("")){
map.put("NODE", "0");
}
List treeList = modulesService.selectNodeTree(map);
JSONArray jsonarr = JSONArray.fromObject(treeList);
String s = jsonarr.toString();
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
response.setContentType("application/xml;");
out.print(s);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
控制层
function loadRoleModule(id){
r_id = id;
alert(id);
$("tree").empty();
var setting = {
check: {
enable: true
},
async: {
enable: true,
url : "./modules/selectNodeTree.do?RID="+id,
type:"post",
autoParam: ["id=node"],
dataFilter: null
},
view: {
dblClickExpand: false
}
};
//加载模块权限树
$.fn.zTree.init($("#tree"), setting);
}
jsp页面代码
文件已经创建但是各功能并未实现
JS解析数据出问题了
就是7条数据啊 但怎么显示成undefined了
是因为你的字段名打错了,可能是和你的数据库不对应也可能是和你的类的字段名不一样