我的实体类user实现了UserDetails,然后代码是这样的:
package com.yxl.stage.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.thymeleaf.util.StringUtils;
@Getter
@Setter
@TableName("user")
@ApiModel(value = "User对象", description = "")
public class User implements Serializable, UserDetails {
private static final long serialVersionUID = 1L;
@TableId(value = "u_id", type = IdType.AUTO)
private Integer uId;
@TableField("u_username")
private String uUsername;
@TableField("u_pwd")
private String uPwd;
@TableField("u_status")
private Integer uStatus;
@TableField("u_level")
private Integer uLevel;
@TableField("u_score")
private Integer uScore;
@TableField("u_name")
private String uName;
@TableField("u_email")
private String uEmail;
@TableField("u_phone")
private String uPhone;
@ApiModelProperty("0-女,1-男")
@TableField("u_sex")
private Integer uSex;
@TableField(exist = false)
private List<Role> roles;
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
List<SimpleGrantedAuthority> authorities = roles
.stream()
.map(role -> new SimpleGrantedAuthority(role.getName()))
.collect(Collectors.toList());
return authorities;
}
@Override
public String getPassword() {
return new BCryptPasswordEncoder().encode(uPwd);
}
@Override
public String getUsername() {
return uUsername;
}
@Override
public boolean isAccountNonExpired() {
return true;
}
@Override
public boolean isAccountNonLocked() {
return true;
}
@Override
public boolean isCredentialsNonExpired() {
return true;
}
@Override
public boolean isEnabled() {
if (uStatus == 1){
return true;
}
return false;
}
}
下面是报错信息
表里的数据也不空啊,为什么会是空指针呢?是写少了什么东西吗?还是哪里错了