package com.oep.backend.serviceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.oep.backend.mapper.AccountMapper;
import com.oep.backend.pojo.Account;
import com.oep.backend.serviceImpl.utils.UserDetailsImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
@Autowired
private AccountMapper accountMapper;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("username",username);
Account account = accountMapper.selectOne(queryWrapper);
if(account == null) {
throw new RuntimeException("用户不存在");
}
return new UserDetailsImpl(account); // 重点在这里
}
}
标签:src,core,com,springframework,import,org,UserDetailsServiceImpl,serviceImpl,backe
From: https://www.cnblogs.com/twinkler/p/18012425