gpt4 book ai didi

spring - 通过 @RequestMapping 名称构建的 URL 无法按自定义名称的预期工作

转载 作者:行者123 更新时间:2023-12-02 06:43:05 24 4
gpt4 key购买 nike

我有以下 Controller :

@Controller
@RequestMapping(value = "/admin/comments", name = "AdminCommentsController")
@Slf4j
public class CommentsController {

@Autowired
private PlaceService placeService;

@Autowired
private CommentRepository commentRepository;

@GetMapping("/awaiting-approval")
public String listAwaitingApproval(@PageableDefault(size = 50, page = 0) Pageable pageable, Model model) {
Page<Comment> comments = commentRepository.findByApprovedIsFalseOrApprovedIsNull(pageable);
model.addAttribute("page", comments);

return "admin/comments/awaitingApproval";
}
}

我想通过映射名称来在 View 中构建一个 URL:

<li>
<a th:href="${#mvc.url('AdminCommentsController#listAwaitingApproval')}" href="add.html">
Awaiting approval
</a>
</li>

但我遇到了一个异常(exception):

java.lang.IllegalArgumentException: Mapping mappingName not found: AdminCommentsController#listAwaitingApproval


从类型级别 @RequestMapping 中删除 name 属性将使 CC#listAwaitingApproval 工作,但它不应该与指定名称一起工作吗?

最佳答案

来自documentation :

public abstract String name

Assign a name to this mapping. Supportedat the type level as well as at the method level! When used on bothlevels, a combined name is derived by concatenation with "#" asseparator.

关键时刻是在两个级别上使用时

因此,您还应该为 @GetMapping 指定名称,它应该开始工作

关于spring - 通过 @RequestMapping 名称构建的 URL 无法按自定义名称的预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46766797/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com