转到一个页面而不是打开一个新标签

Go a page instead of opening a new tab

我在 spring 引导程序中使用 thymeleaf

当用户点击这个link我想转到一个页面

<td><a th:href="@{/editings/testament/} + ${testament.id}" target="_blank" rel="noopener noreferrer"><i class="bi bi-pencil-square"></i></a></td>

在我的控制器中我有

@PreAuthorize("hasAnyRole('ROLE_ADMIN', 'ROLE_USER') ")
@GetMapping(value = "/editings/testament/{testamentId}")
public String editTestament(Model model, @PathVariable Long testamentId) throws Exception {
    ....
    model.addAttribute("testamentId", testament.getId());
    model.addAttribute("testamentDocument", testament.getTestamentDocument());
    ...
    return "starter";
}

实际上,当用户单击 link 打开带有起始页的另一个选项卡时...

如何避免这种情况

所以页面在新选项卡中打开的原因是因为 a 标签上存在 target="_blank" 属性。

如果你删除它,你应该已经准备好了。无需编辑控制器即可实现此目的。这是阅读更多内容的资源:https://www.w3schools.com/tags/att_a_target.asp

希望你今天过得愉快!