技术测试管理系统旨在管理自己所用的技术,通俗说就是毫无关联的技术放在一个系统里。目的看着自己技术成长,作为技术笔记。与同道共享、共勉!
效果图:
必备文件:
在
http://blog.youkuaiyun.com/app_xiaozeng/article/details/38644949 文中提到必备文件的基础上 +
json-lib-2.1-jdk15.jar
技术用处:easyUI动态获取数据库数据
所用技术:
前端:easyui-datagrid
后台:JSONObject
code:
//easyUI数据集到前端需转化成JSON格式[{"total":15,"rows":[xxx,xxx]}]
public void getStudents() {
int page, rows;
String total = "0";
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.registerJsonValueProcessor(Date.class , new DateJsonValueProcessor());//原本时分秒是数组分开的,现将时间转化为字符串格式
Map
map = new HashMap
();
map.put("name", request.getParameter("name")==null?"":request.getParameter("name"));
map.put("phone", request.getParameter("phone")==null?"":request.getParameter("phone"));
map.put("page", request.getParameter("page"));
map.put("rows", request.getParameter("rows"));
map.put("sort", request.getParameter("sort"));
map.put("order", request.getParameter("order"));
List list = this.studentService.getStudents(map);
total = list.get(0).toString();
list.remove(0);
JSONObject jo = null;
JSONArray jsonArray = new JSONArray();
JSONObject result = null;
Map
jsonMap = new HashMap
();
for(int i=0; i
package com.zwb.easyUI.util;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;
public class DateJsonValueProcessor implements JsonValueProcessor {
private String format ="yyyy-MM-dd HH:mm:ss";
public Object processArrayValue(Object value, JsonConfig config) {
return process(value);
}
public Object processObjectValue(String key, Object value, JsonConfig config) {
return process(value);
}
private Object process(Object value){
if(value instanceof Date){
SimpleDateFormat sdf = new SimpleDateFormat(format,Locale.SIMPLIFIED_CHINESE);
return sdf.format(value);
}
return value == null ? "" : value.toString();
}
}
select distinct new Map(
student.id as id,
student.name as name,
student.address as address,
student.phone as phone,
student.email as email,
to_char(student.createData, 'yyyy-mm-dd') as createData,
card.cardnum as cardnum
)
from Student student
left join student.studentCardJoin card
left join student.outLessonJoin outlesson
where student.name like '%' || :name || '%'
order by student.id
技术难点:
1、刚开始加载数据的时候,出现输出2次SQL的语句,是因为有些人同时使用
<table
class
=
"easyui-datagrid"
>
和$('#dg').datagrid({...}),去掉
class
=
"easyui-datagrid"便可
;
2、后台返回格式必须是[{"total":15,"rows":[xxx,xxx]}]的json格式,可利用JSONObject转换;
3、使用JSONObject.fromObject(list.get(i))时,如遇到时间格式,JSONObject会将时间转换为时、分、秒数组。可在sql处理to_char(student.createData, 'yyyy-mm-dd') as createData或在JSONObject转换时处理时间格式的数据jo = JSONObject.fromObject(list.get(i), jsonConfig);
下礼拜日更新计划:技术测试管理系统之easyUI数据分页