【发布时间】:2021-05-30 14:16:42
【问题描述】:
我有必须通过 SpringSecurityUsername 获取映射的 ProfileController。
@Controller
public class ProfileController {
@GetMapping("/profile/{profileName}")
public String showProfilePage(@PathVariable("profileName")String profileName){
return "profile";
}
}
我在网站标题中有这样的动态链接,因此用户可以随时点击它
<a th:href="@{/profile/{name}(name=${username})}">profile</a>
所以如果我想使用链接,我必须在每个 classController 中找到每次用户
@Controller
public class SearchController {
@Autowired
UserService userService;
@GetMapping("/")
public String showIndexPage(Model model){
User user = userService.findUserByUsername(someNameFromSecurityHandler);
model.addAttribute("username",user.getUsername());
return "index";
}
每次我必须为此链接查找用户。如果我想优化这个东西,我必须做什么。因为我认为每次都在数据库中找到用户是个坏主意,因为人们通常不会使用个人资料页面,这只是额外的时间成本。我已经在每个控件类中创建了这段代码。
【问题讨论】:
标签: java html spring spring-mvc url