这是获取数据源
public List<Map<String, Object>> maplist(Map<String,String[]> map,PageBean pageBean) throws Exception{
String sql="select * from t_easyui_menu where true";
String Menuid = JsonUtil.getprepmeval(map, "Menuid");
if(StringUtils.isNotBlank(Menuid)) {
sql+=" and parentid in ("+Menuid+")";
}else {
sql+=" and parentid=-1";
}
return super.executeQuery(sql, pageBean);
}
public void mapToTreeNode(Map<String,Object> map,TreeNode node) throws Exception {
node.setId(map.get("Menuid").toString());
node.setText(map.get("Menuname").toString());
node.setAttributes(map);
Map<String,String[]> mappar=new HashMap<>();
mappar.put("Menuid", new String[]{node.getId()});
List<Map<String, Object>> maplist = this.maplist(mappar, null);
List<TreeNode> treelist=new ArrayList<>();
this.maplistToTreelist(maplist, treelist);
node.setChildren(treelist);
}
public void maplistToTreelist (List<Map<String,Object>> maplist,List<TreeNode> treelist) throws Exception {
TreeNode node=null;
for (Map<String,Object> map : maplist) {
node=new TreeNode();
this.mapToTreeNode(map, node);
treelist.add(node);
}
}
public List<TreeNode> menuTree(Map<String,String[]> map,PageBean pageBean) throws Exception{
List<Map<String, Object>> maplist = this.maplist(map, pageBean);
List<TreeNode> treelist=new ArrayList<>();
this.maplistToTreelist(maplist, treelist);
return treelist;
}
public List<Map<String, Object>> login1(Map<String, String[]> map,PageBean pageBean) throws Exception{
String sql="select * from t_easyui_user_version1 where true";
String uid=JsonUtil.getprepmeval(map, "uid");
String upwd=JsonUtil.getprepmeval(map, "upwd");
if(StringUtils.isNotBlank(uid)) {
sql+=" and uid="+uid;
}
if(StringUtils.isNotBlank(upwd)) {
sql+=" and upwd="+upwd;
}
return super.executeQuery(sql, pageBean);
}
public List<Map<String, Object>> login2(Map<String, String[]> map,PageBean pageBean) throws Exception{
String sql="select * from t_easyui_user_version2 where true";
String uid=JsonUtil.getprepmeval(map, "uid");
String upwd=JsonUtil.getprepmeval(map, "upwd");
if(StringUtils.isNotBlank(uid)) {
sql+=" and uid="+uid;
}
if(StringUtils.isNotBlank(upwd)) {
sql+=" and upwd="+upwd;
}
return super.executeQuery(sql, pageBean);
}
public List<Map<String, Object>> getMenuidbyuid(Map<String, String[]> map,PageBean pageBean) throws Exception{
String sql="select * from t_easyui_usermenu where true";
String uid=JsonUtil.getprepmeval(map, "uid");
if(StringUtils.isNotBlank(uid)) {
sql+=" and uid="+uid;
}
return super.executeQuery(sql, pageBean);
}
//dao包从这里开始
public List<Map<String, Object>> login3(Map<String, String[]> map,PageBean pageBean) throws Exception{
String sql="select * from t_easyui_user where true";
String uid=JsonUtil.getprepmeval(map, "uid");
String upwd=JsonUtil.getprepmeval(map, "upwd");
if(StringUtils.isNotBlank(uid)) {
sql+=" and uid="+uid;
}
if(StringUtils.isNotBlank(upwd)) {
sql+=" and upwd="+upwd;
}
return super.executeQuery(sql, pageBean);
}
public List<Map<String, Object>> getMenuidbypid(Map<String, String[]> map,PageBean pageBean) throws Exception{
String sql="select * from t_easyui_partmenu where true";
String pid=JsonUtil.getprepmeval(map, "pid");
if(StringUtils.isNotBlank(pid)) {
sql+=" and pid="+pid;
}
return super.executeQuery(sql, pageBean);
}
public int update(Map<String, String[]> map) throws SQLException {
String sql="update t_easyui_user_version2 set uid=?,uname=?,upwd=? where SerialNo=?";
return super.executeUpdate(sql, new String[] {"uid","uname","upwd","SerialNo"}, map);
}
public int add(Map<String, String[]> map) throws SQLException {
String sql="insert into t_easyui_user_version2 values("+this.getMaxID()+",?,?,?)";
return super.executeUpdate(sql, new String[] {"uid","uname","upwd"}, map);
}
public int delete(Map<String, String[]> map) throws SQLException {
String sql="delete from t_easyui_user_version2 where SerialNo=?";
return super.executeUpdate(sql, new String[] {"SerialNo"}, map);
}
public String getMaxID() throws SQLException {
String s="";
Connection con = DBAccess.getConnection();
PreparedStatement ps = con.prepareStatement("select max(SerialNo)+1 from t_easyui_user_version2");
ResultSet rs = ps.executeQuery();
if(rs.next()) {
s= rs.getString(1);
}
return s;
}
public final String login1(HttpServletRequest req,HttpServletResponse resp) {
try {
List<Map<String, Object>> login1 = this.dao.login1(req.getParameterMap(), null);
if(login1!=null && login1.size()>0) {
String Menuid = login1.get(0).get("Menuid").toString();
req.setAttribute("Menuid", Menuid);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "index";
}
public final String login2(HttpServletRequest req,HttpServletResponse resp) {
try {
List<Map<String, Object>> list = dao.login2(req.getParameterMap(), null);
if(list!=null && list.size()>0) {
Map<String, Object> map = list.get(0);
String uid = (String) map.get("uid");
Map<String, String[]> pmap=new HashMap<>();
pmap.put("uid", new String[] {uid});
List<Map<String, Object>> list2 = dao.getMenuidbyuid(pmap, null);
StringBuffer sb=new StringBuffer();
for (Map<String, Object> map2 : list2) {
sb.append(",").append(map2.get("menuId"));
}
req.getSession().setAttribute("Menuid", sb.toString().substring(1));
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "index";
}
//action从这里开始
public final String login3(HttpServletRequest req,HttpServletResponse resp) {
try {
List<Map<String, Object>> login3 = this.dao.login3(req.getParameterMap(), null);
if(login3!=null && login3.size()>0) {
String pid = login3.get(0).get("pid").toString();
Map<String, String[]> paMap=new HashMap<>();
paMap.put("pid",new String[] {pid});
List<Map<String, Object>> list = this.dao.getMenuidbypid(paMap, null);
StringBuffer sb=new StringBuffer();
for (Map<String, Object> map : list) {
sb.append(",").append(map.get("menuid"));
}
req.getSession().setAttribute("Menuid", sb.toString().substring(1));
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "index";
}
public final String list(HttpServletRequest req,HttpServletResponse resp) {
PageBean pageBean=new PageBean();
try {
pageBean.setRequest(req);
List<Map<String, Object>> list = this.dao.login2(req.getParameterMap(), pageBean);
Map<String, Object> paMap=new HashMap<>();
paMap.put("total", pageBean.getTotal());
paMap.put("rows", list);
ObjectMapper om=new ObjectMapper();
ResponseUtil.wrtie(resp, om.writeValueAsString(paMap));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public final String update(HttpServletRequest req,HttpServletResponse resp) {
try {
int n = this.dao.update(req.getParameterMap());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public final String add(HttpServletRequest req,HttpServletResponse resp) {
try {
int n = this.dao.add(req.getParameterMap());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public final String delete(HttpServletRequest req,HttpServletResponse resp) {
try {
int n = this.dao.delete(req.getParameterMap());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public final String menuTreelist(HttpServletRequest req,HttpServletResponse resp) {
List<TreeNode> menuTree=new ArrayList<>();
try {
menuTree = dao.menuTree(req.getParameterMap(), null);
ObjectMapper om=new ObjectMapper();
ResponseUtil.wrtie(resp, om.writeValueAsString(menuTree));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
将得到得数据源展示:
$(function() {
$('#menuTree').tree({
url:'menuAction.action?methodName=menuTreelist&Menuid='+$("#menu").val(),
onClick: function(node){
alert($("#menu").val());
}
});
})