利⽤map格式参数传值,接收拼接sql语句通过将值存⼊map
@RequestMapping(value="/list", method = RequestMethod.POST)
@ResponBody
public Map<String, Object> list(HttpServletRequest request) throws Throwable {
String pageNo = Parameter("pager.pageNo");
String pageSize = Parameter("pager.pageSize");
Map<String, Object> map = new HashMap<String, Object>();
String product_name = Parameter("product_name");
if(product_name!=null && !"null".equals(product_name) && !"".equals(product_name)){
map.put("product_name like", "%" + product_name + "%");
}
String basic_ller_name = Parameter("basic_ller_name");
if(basic_ller_name!=null && !"null".equals(basic_ller_name) && !"".equals(basic_ller_name)){
map.put("basic_ller_name like", "%" + basic_ller_name + "%");
容易的近义词}
List<Map<String, Object>> list = productService.findViewByMapPage(map, Integer.parInt(pageNo), Integer.parInt(pageSize)); int total = productService.findViewByMapCount(map);
// 页⾯需要显⽰的列名
String[] column = {
"product_id",
durex是什么意思"product_name",
"product_specifications",
"product_short_name",
"product_unit_name",
"basic_ller_name",
"product_sort_name",
"product_brand_name",
"product_image",
"product_origin",
"product_manufacturer",
"product_pinyin",
"product_ll_stop",
"product_buyer_stop",
"product_minus_stock",
时代周刊
"product_barcode_number",
"product_update",
};
return Public.listTojson(list, column, pageNo, pageSize, total);墨西哥世界杯
}
sql语句拼接利⽤迭代器将map循环
public List<Map<String, Object>> findViewByMapPage(Map<String, Object> map,
parallelsint pageNo, int pageSize) {
road manStringBuffer sql = new StringBuffer("lect * from " + TableName.product_view);
Iterator it = Set().iterator();
Object object[] = new Object[map.size()];
int i = 0;乌拉圭回合
if (map.size() > 0) {
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
String key = Key().toString();
Object value = Value();
if (i==0) {
sql.append(" where " + key + " ?");
object[i] = value;
} el if (i==1){
sql.append(" and " + key + " ?");
object[i] = value;
}
i++;
}
}
sql.append(" order by product_id desc");
return baDao.String(), object, this.findViewByMapCount(map), pageNo, pageSize, ProductServiceImpl.class); }
或者sql
public List<Map<String, Object>> findViewByMapPage(Map<String, Object> map,
int pageNo, int pageSize) {
StringBuffer sql = new StringBuffer("lect * from " + TableName.product_view);
Iterator it = Set().iterator();
Object[] object = new Object[map.size()];
int i = 0;
if (map.size() > 0) {
while (it.hasNext()) {
trevalMap.Entry entry = (Map.Entry) it.next();
String key = Key().toString();
Object value = Value();
sql.append(" where " + key + " ?");
object[i] = value;
bottledi++;
}
}
txusql.append(" order by product_id desc");
return baDao.String(), object, this.findViewByMapCount(map), pageNo, pageSize, ProductServiceImpl.class); }