package com.learn.system;
import com.learn.common.interceptor.JwtInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
@Configuration
public class SystemConfig extends WebMvcConfigurationSupport {
@Autowired
private JwtInterceptor jwtInterceptor;
/**
* 添加拦截器的配置
*/
@Override
protected void addInterceptors(InterceptorRegistry registry) {
//1.添加自定义拦截器
registry.addInterceptor(jwtInterceptor).
addPathPatterns("/**").//2.指定拦截器的url地址
excludePathPatterns("/sys/login","/frame/register/**");//3.指定不拦截的url地址
}
}
package com.learn.system;
import com.learn.common.utils.IdWorker;
import com.learn.common.utils.JwtUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter;
//1.配置springboot的包扫描
@SpringBootApplication(scanBasePackages = "com.learn")
//2.配置jpa注解的扫描
@EntityScan(value="com.learn.domain.system")
public class SystemApplication {
/**
* 启动方法
*/
public static void main(String[] args) {
SpringApplication.run(SystemApplication.class,args);
}
@Bean
public IdWorker idWorker() {
return new IdWorker();
}
@Bean
public JwtUtils jwtUtils() {
return new JwtUtils();
}
//解决no session
@Bean
public OpenEntityManagerInViewFilter openEntityManagerInViewFilter() {
return new OpenEntityManagerInViewFilter();
}
}
localhost:9002/sys/login
{
"mobile":"18975979967",
"password":"123456"
}
localhost:9002/sys/profile
Bearer
Authorization
localhost:9002/sys/login
{
"mobile":"18975979967",
"password":"123456"
}
{
"success": true,
"code": 10000,
"message": "操作成功!",
"data": "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIxMjEwOTc5MTQ5MDMxNDQwMzg0Iiwic3ViIjoibGVvbiIsImlhdCI6MTU3Nzg0NjAxOCwiY29tcGFueUlkIjoiMSIsImFwaXMiOiIiLCJjb21wYW55TmFtZSI6IuS4reWbveWlveWjsOmfsyIsImV4cCI6MTU3Nzg0OTYxOH0.dQaKqwtyiCidHIMApUXeSltFNdrIO_HYhI_s1PJKS7s"
}
localhost:9002/sys/profile
Authorization
Bearer eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIxMjEwOTc5MTQ5MDMxNDQwMzg0Iiwic3ViIjoibGVvbiIsImlhdCI6MTU3Nzg0NjAxOCwiY29tcGFueUlkIjoiMSIsImFwaXMiOiIiLCJjb21wYW55TmFtZSI6IuS4reWbveWlveWjsOmfsyIsImV4cCI6MTU3Nzg0OTYxOH0.dQaKqwtyiCidHIMApUXeSltFNdrIO_HYhI_s1PJKS7s
{
"success": true,
"code": 10000,
"message": "操作成功!",
"data": {
"mobile": "18975979967",
"username": "leon",
"company": "中国好声音",
"roles": {
"apis": [
"API-USER-DELETE"
],
"menus": [
"啊啊啊",
"settings",
"12",
"test",
"permissions",
"departments",
"saas-clients",
"employees"
],
"points": [
"point-dept",
"POINT-USER-ADD",
"point-user-delete",
"POINT-USER-UPDATE"
]
}
}
}