@PreAuthorize("hasRole('admin')") @GetMapping("http://localhost:8081/") @ResponseBody public String findAllUser(Model model){ List<User> users = userService.findAllUser(); model.addAttribute("users",users); return "oss/peoples"; }中的oss/peoples为什么连接不了
时间: 2024-03-04 18:54:08 浏览: 94
根据代码片段,这个方法使用了@GetMapping注解,指定了请求的URL为"http://localhost:8081/",同时使用了@ResponseBody注解,表示返回的是一个字符串而不是视图。然而,方法的返回值是"oss/peoples",这个值实际上是用来渲染一个视图的,而不是直接返回给客户端的字符串。
因此,如果你在浏览器中访问"http://localhost:8081/",那么你将会得到一个字符串"oss/peoples",而不是一个视图。如果你想要渲染这个视图,你需要将方法的返回值修改为一个ModelAndView对象,然后在这个对象中设置视图的名称为"oss/peoples"。同时,你需要确保这个视图的路径和名称是正确的,并且这个视图已经存在于你的项目中。
相关问题
@PreAuthorize("hasRole('admin')") @GetMapping ("/findAllUser") @RequestMapping("/findAllUser") public ModelAndView findAllUser(Model model){ List<User> users = userService.findAllUser(); model.addAttribute("users",users); ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("/oss/peoples"); return modelAndView; }不好意思,你的请求路径可能错误了,请查看!
这段代码中存在两个请求路径注解,@GetMapping和@RequestMapping,建议只保留一个即可,同时需要确保请求路径的唯一性。针对这段代码,可以将其中一个请求路径注解删除,例如:
```
@PreAuthorize("hasRole('admin')")
@GetMapping("/findAllUser")
public ModelAndView findAllUser(Model model){
List<User> users = userService.findAllUser();
model.addAttribute("users",users);
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("/oss/peoples");
return modelAndView;
}
```
这样就可以保证请求路径的正确性了。
@ApiLog("根据Id获取请假数据") @ApiOperation(value = "根据Id获取请假数据") @PreAuthorize("hasAnyAuthority('test:two:day:view','test:two:day:add','test:two:day:edit')") @GetMapping("queryById") @ResponseBody public ResponseEntity<DayDTO> queryById(String id) { return ResponseEntity.ok(dayService.findById(id)); }
这段代码是一个基于Spring Boot的RESTful API接口。它使用了一些注解来定义接口的行为和权限控制。
- `@ApiLog` 注解用于记录接口的日志信息。
- `@ApiOperation` 注解用于定义接口的描述信息。
- `@PreAuthorize` 注解用于控制接口的访问权限,只有具有指定权限的用户才能访问该接口。
- `@GetMapping` 注解用于指定接口的请求方法为 GET 请求。
- `@ResponseBody` 注解用于将返回的对象直接作为响应体返回,而不是解析为视图。
- `public ResponseEntity<DayDTO> queryById(String id)` 是一个处理 GET 请求的方法,它接收一个名为 `id` 的参数,并返回一个 `ResponseEntity<DayDTO>` 对象。
在该方法中,它调用了 `dayService.findById(id)` 方法来根据 `id` 查询请假数据,并将查询结果包装在 `ResponseEntity` 对象中返回给调用方。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.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)