怎么往redirect:/indexblog/{id}传@GetMapping("comment/{blogId}/{id}/delete")里的id,public String delete(@PathVariable Long blogId, @PathVariable Long id, Comment comment, RedirectAttributes attributes, Model model){ commentService.deleteComment(comment,i
时间: 2024-02-12 14:08:34 浏览: 24
在你的@GetMapping("comment/{blogId}/{id}/delete")中,id是指评论的id,而在redirect:/indexblog/{id}中的id是指博客的id。如果你想要在redirect中传递评论的id,可以将其作为参数添加到redirect中,如下所示:
```
redirect:/indexblog/{blogId}?commentId={id}
```
然后,在你的indexblog页面中,可以通过request.getParameter("commentId")来获取评论的id。注意,这种方式只适用于传递一个或少量的参数,如果需要传递多个参数,建议使用其他方式,如Session或者ModelAndView等。
相关问题
@GetMapping("/{id}") 泛型用不了
泛型是 Java 语言的一个特性,用于在编译时期提供类型安全检查。在你提供的 `@GetMapping("/{id}")` 注解中,并不包含泛型的使用。
`@GetMapping("/{id}")` 是 Spring Framework 提供的注解,用于将 HTTP GET 请求映射到指定的处理方法上。其中的 `{id}` 表示一个路径参数,用于接收请求中的 id 值。
如果你想在方法中使用泛型,可以在方法的参数类型或返回值类型上进行泛型声明。例如:
```java
@GetMapping("/{id}")
public ResponseEntity<Student> getStudentById(@PathVariable Long id) {
// 根据 id 查询学生信息
Student student = studentService.findById(id);
// 返回包含学生信息的 ResponseEntity
return ResponseEntity.ok(student);
}
```
在上述示例中,`ResponseEntity<Student>` 使用了泛型,表示返回的响应体中包含一个 Student 对象。
@GetMapping("/{id}")
这个是一个 Spring Boot 框架中的 RESTful API 的注解,用于处理 HTTP GET 请求。其中 `{id}` 表示请求路径中的参数,可以通过在方法中加入 `@PathVariable` 注解来获取。例如:
```
@GetMapping("/{id}")
public String getItemById(@PathVariable Long id) {
// 处理逻辑
}
```
当我们请求 `/123` 这个路径时,Spring Boot 会调用 `getItemById` 方法,参数 `id` 的值为 `123`。