|
楼主 |
发表于 2016-11-22 14:18:41
|
显示全部楼层
//查询货品档案信息
public static JSONObject getitem(JSONObject params, ActionContext context) throws SQLException, NamingException, java.sql.SQLException {
String item_para = params.getString("item_para");
String server_db = params.getString("server_db");
Integer limit = params.getInteger("limit"); // 分页查询的行数
Integer offset = params.getInteger("offset"); // 分页查询的行偏移
String item_img= params.getString("item_img");
Table table = null;
Connection conn = context.getConnection(server_db);
String sql = "";
try{
sql ="SELECT code,name,size,dir_path,file_name,'"+ item_img+"'+ isnull(dir_path,'')+'/'+isnull(file_name,'') as pic_url "
+ " FROM t_bd_item ";
if(item_para!=null&&item_para.trim().length()>0){
sql = sql + " where code like ? or name like ? or size like ? " ;
}
sql = sql + " order by category_code,name";
Object total=null;
if(item_para!=null&&item_para.trim().length()>0){
// 存放SQL中的参数值
List<Object> sqlParams = new ArrayList<Object>();
// 增加参数值,参数的个数和顺序必须与过滤条件的?相匹配
for (int i = 0; i < 3; i++) {
sqlParams.add(getParaFormatWithFix(item_para));
}
table = DataUtils.queryData(conn, sql, sqlParams, null, offset, limit);
String totalSQL="select count(*) "
+ " FROM t_bd_item "
+ " where code like ? or name like ? or size like ? " ;
total=DataUtils.getValueBySQL(conn, totalSQL, sqlParams);
}else{
table = DataUtils.queryData(conn, sql, null, null, offset, limit);
String totalSQL="select count(*) "
+ " FROM t_bd_item " ;
total=DataUtils.getValueBySQL(conn, totalSQL, null);
}
if(total!=null){
table.setTotal(Integer.parseInt((total.toString())));
}else{
table.setTotal(0);
}
return Transform.tableToJson(table);
} finally {
conn.close();
}
} |
|