@RequestMapping("/getPage") @ResponseBody public Page<TbServiceAccept> getPage(HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model, Page<TbServiceAccept> page, TbServiceAccept tbServiceAccept) { Map<String, Object> map = new HashMap<String, Object>(); map.put("createtimeGt",tbServiceAccept.getCreatetimeGt()); map.put("createtimeLt",tbServiceAccept.getCreatetimeLt()); map.put("clientphone",tbServiceAccept.getClientphone()); map.put("receiver",tbServiceAccept.getReceiver()); map.put("crmnumber",tbServiceAccept.getCrmnumber()); page= tbServiceAcceptService.findByPage(map, page); for (TbServiceAccept tbServiceAccept1 : page.getItems()) { List<Map<String, Object>> usermap = tbUserInfoService.findCustom("select * from tb_User_Info where (username = #{p[0]} or phone =#{p[0]}) and isDelete = 0", new Object[]{tbServiceAccept1.getId()}); if (!usermap.isEmpty()) { tbServiceAccept1.setJson(new JSONObject().fluentPut("khPhone", usermap.get(0).get("khPhone"))); } } return page;怎么改,不要findCustom改为list并且不用map方法
时间: 2024-04-11 12:33:18 浏览: 177
@ResponseBody 和 @RequestBody 注解的区别
5星 · 资源好评率100%
您可以将`findCustom`方法替换为`list`方法,并且不使用`Map`来存储参数。下面是修改后的代码:
```java
@RequestMapping("/getPage")
@ResponseBody
public Page<TbServiceAccept> getPage(HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model, Page<TbServiceAccept> page, TbServiceAccept tbServiceAccept) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("createtimeGt", tbServiceAccept.getCreatetimeGt());
map.put("createtimeLt", tbServiceAccept.getCreatetimeLt());
map.put("clientphone", tbServiceAccept.getClientphone());
map.put("receiver", tbServiceAccept.getReceiver());
map.put("crmnumber", tbServiceAccept.getCrmnumber());
page = tbServiceAcceptService.findByPage(map, page);
for (TbServiceAccept tbServiceAccept1 : page.getItems()) {
List<TbUserInfo> userInfos = tbUserInfoService.list("select * from tb_User_Info where (username = ? or phone = ?) and isDelete = 0", new Object[]{tbServiceAccept1.getId(), tbServiceAccept1.getId()});
if (!userInfos.isEmpty()) {
TbUserInfo userInfo = userInfos.get(0);
tbServiceAccept1.setJson(new JSONObject().fluentPut("khPhone", userInfo.getKhPhone()));
}
}
return page;
}
```
这里使用`list`方法代替了`findCustom`方法,并直接传入参数数组作为查询条件。同时,使用`TbUserInfo`对象来存储查询结果,无需再使用`Map`。
阅读全文