springboot GetMapping 使用Map<String,List<Long>>接收参数
时间: 2023-11-11 13:50:49 浏览: 45
可以使用@RequestParam注解来接收Map<String,List<Long>>类型的参数,示例代码如下:
```
@GetMapping("/test")
public void test(@RequestParam Map<String,List<Long>> paramMap) {
// 处理参数
}
```
在请求时,可以通过类似以下的URL来传递参数:
```
http://localhost:8080/test?param1=1,2,3¶m2=4,5,6
```
其中,param1和param2是Map中的键,后面跟着的是逗号分隔的值列表。在方法中,可以通过paramMap.get("param1")来获取对应的值列表。
相关问题
@GetMapping("/list") //要传的参数 用户名和电话不是必须的 pagesize和pageno是必须的 因为没有数据时候也得显示在前端界面上 public Result<Map<String,Object>> getUserList(@RequestParam(value = "username",required = false) String username, @RequestParam(value = "phone",required = false) String phone, @RequestParam(value = "pageNo") Long pageNo, @RequestParam(value = "pageSize") Long pageSize){ }
这段代码是一个使用Spring Boot的注解`@GetMapping`来定义一个获取用户列表的接口。该接口接受一些参数作为查询条件,并返回一个包含用户列表的结果对象。
在这个接口中,有四个参数:
1. `username`和`phone`参数是可选的,使用`@RequestParam`注解来标识。这意味着你可以选择是否传递它们作为查询条件。如果不传递这两个参数,默认值为`null`。
2. `pageNo`和`pageSize`参数是必需的,使用`@RequestParam`注解来标识,并且没有设置`required = false`。这意味着你必须传递这两个参数作为分页信息,否则接口将会返回错误。
返回结果类型是一个包含用户列表的`Map<String, Object>`类型的结果对象。你可以根据实际需求选择其他适合的返回类型。
你可以根据实际情况使用这个接口来获取用户列表,并根据传递的参数进行查询和分页操作。
@PostMapping("/queryLicenseReminder") public ApiResult queryLicenseReminder() { Long retailShopId = AccessContext.get().getRetailShopId(); Map<String, List> map = new HashMap<>(3); if (retailShopId != null) { List<GspCompanyLicenseVO> gspCompanyLicenseList = gspCompanyLicenseService.queryLicenseReminder(retailShopId); List<GspUserLicenseVO> gspUserLicenseList = gspUserLicenseService.queryLicenseReminder(retailShopId); List<RetailShopLicenseVO> retailShopLicenseVOList = retailShopLicenseService.queryLicenseReminder(retailShopId); map.put("gspCompanyLicenseList", gspCompanyLicenseList); map.put("gspUserLicenseList", gspUserLicenseList); map.put("retailLicenseList", retailShopLicenseVOList); } return ApiResult.success(map); }改为查询所有门店不按照门店ID查询
可以将原先的 `Long retailShopId = AccessContext.get().getRetailShopId();` 改为获取所有门店的 ID 列表,然后遍历这些门店 ID,逐个查询每个门店的 License Reminder,将每个门店的查询结果存储到一个 List 中,最后将这个 List 作为整个 API 的返回值即可。具体实现可以参考下面的代码:
```
@GetMapping("/queryLicenseReminder")
public ApiResult queryLicenseReminder() {
List<Long> retailShopIdList = retailShopService.getAllRetailShopIds(); // 获取所有门店的 ID 列表
List<Map<String, List>> resultList = new ArrayList<>(); // 存储所有门店的查询结果
for (Long retailShopId : retailShopIdList) {
Map<String, List> map = new HashMap<>(3);
List<GspCompanyLicenseVO> gspCompanyLicenseList = gspCompanyLicenseService.queryLicenseReminder(retailShopId);
List<GspUserLicenseVO> gspUserLicenseList = gspUserLicenseService.queryLicenseReminder(retailShopId);
List<RetailShopLicenseVO> retailShopLicenseVOList = retailShopLicenseService.queryLicenseReminder(retailShopId);
map.put("gspCompanyLicenseList", gspCompanyLicenseList);
map.put("gspUserLicenseList", gspUserLicenseList);
map.put("retailLicenseList", retailShopLicenseVOList);
resultList.add(map);
}
return ApiResult.success(resultList);
}
```