springboot拦截器验证token实现登陆
作者:互联网
1.登录接口
controller层
@PostMapping
@ApiOperation(value="申请token")
public ResponseData<Map> applyToken(@RequestBody LoginUser loginUser){
Map<String, String> map = new HashMap<>();
map.put("token", loginService.applyAccessToken(loginUser));
return ResponseData.success().setData(map);
}
service层代码
public String applyAccessToken(LoginUser loginUser){
1.查询登录账号信息是否存在以及合法性
2.账户合法返回token,不合法报异常(使用jwt生成token)
}
jwt依赖
<dependencies>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.6.0</version>
</dependency>
</dependencies>
jwtUtil工具类
@Component
@ConfigurationProperties("jwt.config")
public class jwtUtil{
private String key ;
private long ttl;
//get,set方法
public String createJWT(String uname, String subject, String type) {
long
标签:map,拦截器,springboot,jwt,token,loginUser,public,String 来源: https://blog.csdn.net/xiaoxiamiqianqian/article/details/110262386