拦截器ok

This commit is contained in:
tortoise 2024-08-12 14:53:59 +08:00
parent efeabfc238
commit c5358cd33e
3 changed files with 9 additions and 2 deletions

View File

@ -19,7 +19,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupp
protected void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(jwtInterceptor())
.addPathPatterns("/**")
.excludePathPatterns("/login"); // 排除不需要验证的路径
.excludePathPatterns("/user/login"); // 排除不需要验证的路径
super.addInterceptors(registry);
}

View File

@ -59,7 +59,7 @@ public class JwtInterceptor implements HandlerInterceptor {
throw new ServiceException("401", "请登录");
}
User user = userMapper.selectByUserId(Integer.parseInt(userId));
User user = userMapper.selectById(Integer.parseInt(userId));
if (user == null) {
throw new ServiceException("401", "请登录");
}

View File

@ -55,6 +55,13 @@ public interface UserMapper extends BaseMapper<User> {
@Select("SELECT id, user_id, username, password, name, email, `group` from user WHERE user_id = #{userId}")
User selectByUserId(Integer userId);
/**
* 根据iD查询用户信息
* @param
* @return 用户对象
*/
@Select("SELECT id, user_id, username, password, name, email, `group` from user WHERE id = #{Id}")
User selectById(Integer Id);
/**
* 查询所有用户信息
* @return 用户列表