Compare commits

..

2 Commits

Author SHA1 Message Date
FOAM 8497f61842 Merge remote-tracking branch 'origin/main' 2024-03-20 15:36:41 +08:00
FOAM 7a658ce8b2 SQL查询 2024-03-19 11:32:34 +08:00
1 changed files with 11 additions and 20 deletions

View File

@ -49,28 +49,19 @@ public class DcxServiceImpl implements DcxService {
+ "it.name" + "it.name"
+ " from Item it "; + " from Item it ";
sql += ") AS subquery "; sql += ") AS subquery ";
String sqlCount = "select count(id) " + sql; String sqlCount = "select count(id) as nums " + sql;
sql = "select * " + sql + " WHERE RowNum BETWEEN " + (pageNum-1) * pageSize + " AND " + (pageNum) * pageSize; sql = "select * " + sql + " WHERE RowNum BETWEEN " + (pageNum-1) * pageSize + " AND " + (pageNum) * pageSize;
log.info("sqlCount:"+sqlCount); //查询单数据
log.info("sql:"+sql); Map<String,Object> listCount = jdbcTemplate.queryForMap(sqlCount, new HashMap<>());
//查询单挑数据
Map<String,Object> userMap2 = jdbcTemplate.queryForMap("select * from Container where ID=1", new HashMap<>());
//查询多条数据据 //查询多条数据据
List<Map<String,Object>> userMap = jdbcTemplate.queryForList("select * from Container ", new HashMap<>()); List<Map<String,Object>> maps = jdbcTemplate.queryForList(sql, new HashMap<>());
System.out.println(userMap);
/*List<Object[]> list=entity.createNativeQuery(sql).getResultList();
List listCount=entity.createNativeQuery(sqlCount).getResultList();
JSONArray data = new JSONArray(); JSONArray data = new JSONArray();
for(Object[] obj:list){ for(Map<String,Object> m:maps){
int i=0; int i=0;
JSONObject d = new JSONObject(); JSONObject d = new JSONObject();
d.put("id",obj[i++]==null?"":obj[i-1]); d.put("id",m.get("id"));
d.put("userNo",obj[i++]==null?"":obj[i-1]); d.put("userNo",m.get("code"));
d.put("userName", obj[i++]==null?"":obj[i-1]); d.put("userName", m.get("name"));
d.put("passWord","123456"); d.put("passWord","123456");
d.put("age",19); d.put("age",19);
d.put("sex",1); d.put("sex",1);
@ -78,8 +69,8 @@ public class DcxServiceImpl implements DcxService {
d.put("roleId", 2); d.put("roleId", 2);
d.put("isValid", false); d.put("isValid", false);
data.add(d); data.add(d);
}*/ }
return Result.success(userMap.size(),userMap); return Result.success(Long.parseLong(listCount.get("nums").toString()),data);
} }
} }