package xin.merlin.myblog_server.config; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; import xin.merlin.myblog_server.entity.User; import xin.merlin.myblog_server.service.impl.UserServiceImpl; import java.util.ArrayList; @Service public class LoginDetails implements UserDetailsService { @Autowired private UserServiceImpl userServiceImpl; @Override public CustomUserDetails loadUserByUsername(String u_account) throws UsernameNotFoundException { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("account", u_account); User user = userServiceImpl.getOne(queryWrapper); if(user == null) return null; return new CustomUserDetails(user.getAccount(), user.getPassword(),user.getId(),new ArrayList<>()); } }