FeC*_*eCH 0 spring-mvc spring-security
我想在登录时获取userName信息.如果用户未登录,则if语句应跳过此操作.我认为暗示是我应该使用但当用户未登录时它当前抛出空指针.
@RequestMapping(value = "/", method = RequestMethod.GET)
public String displayHomePage(Model model, Principal user) {
if(!user.implies(null)){
String name = user.getName();
User currentUser = userService.getUserByName(name);
}
Run Code Online (Sandbox Code Playgroud)
该Principal参数变量是null,如果用户没有登录,那么请检查是否有这样的无效:
@RequestMapping(value = "/", method = RequestMethod.GET)
public String displayHomePage(Model model, Principal user) {
if (user != null) {
String name = user.getName();
// ...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1782 次 |
| 最近记录: |