分享方法 :为什么多了一个0,数据库里面的数据是没有0的,取出来的时候多了一个0,这是Oracle数据搞的鬼,解决代码如下
可参考
for (HessianLog hessianLog : hessianLogList) { Map<String, String> map = new HashMap<String, String>(); map.put("username",hessianLog.getUsername()); map.put("menuname",hessianLog.getMenu_name()); map.put("clientip",hessianLog.getClientip()); if(hessianLog.getIs_error_log()==1){ map.put("is_error_log","是"); } else{ map.put("is_error_log","否"); } DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss"); String rtnType = sdf.format(hessianLog.getDatetimenow()); map.put("datetimenow",rtnType); map.put("methodname",hessianLog.getMethodname()); map.put("fullclassname",hessianLog.getFullclassname()); map.put("error_message",hessianLog.getError_message()); map.put("menu_id",hessianLog.getMenu_id()+""); map.put("id",hessianLog.getId()+""); map.put("userid",hessianLog.getUserid()+""); map.put("org_id",hessianLog.getOrg_id()+""); listMap.add(map); }
//用户列表 List<User> list = userService.loadUserByOrgId(ss, ss.getBelongOrgId()); if(list == null) { return null; } List<Map<String,String>> listMap = new ArrayList<Map<String,String>>(); for (User user2 : list) { if(user2.getUser_type()==0|| user2.getUser_type()==1){ continue; } Map<String,String> map = null; user2.setPassword(null); try { //修改bug,sybase中读取空字符串会转换为空格 if(user2.getTelephone()!=null){ user2.setTelephone(user2.getTelephone().trim()); } map = BeanUtils.describe(user2); long belong_org = user2.getBelong_org(); int login_level = user2.getLogin_level(); int enabled = user2.getEnabled(); if(enabled == 1){ map.put("enabled_display", "是"); }else if(enabled == 0){ map.put("enabled_display", "否"); } if(login_level == 0){ map.put("login_level_display", "密码登陆"); }else if(login_level == 1){ map.put("login_level_display", "证书登陆"); } Organization org = orgService.loadOrgById(belong_org); map.put("belong_org_display", org.getName()); } catch (Exception e) { throw new RuntimeException(e); } DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss"); String startDate = sdf.format(user2.getStart_date()); String endDate = sdf.format(user2.getEnd_date()); map.put("start_date", startDate); map.put("end_date", endDate); listMap.add(map); } Map<String,List<Map<String,String>>> resultMap = new HashMap<String,List<Map<String,String>>>(); resultMap.put("data", listMap); JSONObject jo = JSONObject.fromObject(resultMap); this.actionWrite(jo.toString()); return null; }
上述两段代码都用了一个原理:在从数据库取出数据【多了一个0】之后,在写成JSON串在前台展现之前,将数据格式转换过来。而转换的地方都是在一个for循环的map下,因为时间对应的是用户(本例子),或者说,时间是谁的时间,然后
DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss"); //定义一个格式
String startDate = sdf.format(user2.getStart_date()); //将需要的数据经过格式转换转换为正确格式的数据
String endDate = sdf.format(user2.getEnd_date());
map.put("start_date", startDate); //在map中将装换好格式的数据,put进去
map.put("end_date", endDate); //map里面装的是键值对,用put后,数据将被替换掉
listMap.add(map);