resultList = service.select(map, new HashMap<>()).getResultList();
时间: 2024-05-25 20:13:29 浏览: 21
这段代码看起来像是使用某个 ORM 框架进行数据库操作。其中 `service` 是一个服务类的对象,`select` 方法接收两个参数:查询条件和排序条件,均为 `Map` 类型。第二个参数是一个空的 `HashMap`,可能是为了满足方法重载所必须传递的。`getResultList()` 方法返回查询结果列表。
相关问题
@PostMapping("login") public Map<String, Object> login(@RequestBody Map<String, String> data, HttpServletRequest httpServletRequest) { log.info("[执行登录接口]"); String username = data.get("username"); String email = data.get("email"); String phone = data.get("phone"); String password = data.get("password"); List resultList = null; Map<String, String> map = new HashMap<>(); if(username != null && "".equals(username) == false){ map.put("username", username); resultList = service.select(map, new HashMap<>()).getResultList(); } else if(email != null && "".equals(email) == false){ map.put("email", email); resultList = service.select(map, new HashMap<>()).getResultList(); } else if(phone != null && "".equals(phone) == false){ map.put("phone", phone); resultList = service.select(map, new HashMap<>()).getResultList(); }else{ return error(30000, "账号或密码不能为空"); } if (resultList == null || password == null) { return error(30000, "账号或密码不能为空"); } //判断是否有这个用户 if (resultList.size()<=0){ return error(30000,"用户不存在"); }
这段代码是一个使用Spring MVC框架编写的Java后端接口,用于用户登录。该接口通过HTTP POST请求接受一个包含用户名、邮箱、电话和密码的JSON请求体,根据其中提供的账号信息查询数据库中的用户记录,判断用户是否存在并验证密码是否正确。最终返回一个JSON响应,包含成功或失败的状态码和相关信息。
优化这段代码 public static List<Map<String, String>> getConnectParamMapList(String connectParamsStr) { String[] split01 = StringUtils.split(connectParamsStr, '&'); LinkedList<Map<String, String>> resultList = new LinkedList<>(); for (String s : split01) { String[] split02 = StringUtils.split(s, '='); String connectParamName = split02[0]; String connectParamValue = split02[1]; Map<String, String> connectParamMap = new HashMap<>(); connectParamMap.put(connectParamName, connectParamValue); resultList.add(connectParamMap); } return resultList; }
'); List<Map<String, String>> connectParamMapList = new ArrayList<>();
for (String s : split01) {
String[] split02 = StringUtils.split(s, ',');
Map<String, String> connectParamMap = new HashMap<>();
for (String s1 : split02) {
String[] split03 = StringUtils.split(s1, '=');
connectParamMap.put(split03[0], split03[1]);
}
connectParamMapList.add(connectParamMap);
}
return connectParamMapList;
}
可以使用 Java 8 的 Stream API 来简化代码,如下所示:
public static List<Map<String, String>> getConnectParamMapList(String connectParamsStr) {
return Arrays.stream(connectParamsStr.split("\\r?\\n"))
.map(s -> Arrays.stream(s.split(","))
.map(s1 -> s1.split("="))
.collect(Collectors.toMap(s2 -> s2[0], s2 -> s2[1])))
.collect(Collectors.toList());
}
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)