- Understand and implement JWT.
- ... Spring Boot Excution.
- ... Inteceptor, Configurer.
- ... REST API.
- Spring Boot(Maven)
- MyBatis
- MySQL
- JWT
- REST API
- Swagger
HttpRequest -> Controller -> Service -> Mapper -> MySQL
Main Method in Spring Boot.
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
400, 401, 404, 500, etc... Handle exceptions and Return Httpstatus.
@RestControllerAdvice
@RestController
public class GlobalExceptionHandler implements ErrorController {
@ExceptionHandler(value = Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public void baseException (Exception e) {e.printStackTrace();}
}
JWT intercepts all requests.
@Component
public class JWTInterceptor implements HandlerInterceptor {
// Name of JWT
private static final String HEADER_user = "token_name";
@Override
public boolean preHandle (HttpServletRequest request, HttpServletResponse response, Object handler) {
}
}
Solve CORS Issues.
@Configuration
public class MVCConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedHeaders("*")
.exposedHeaders("token_name")
.allowedMethods("GET", "POST")
.allowCredentials(true)
.maxAge(3600);
}
}
Creating SQL Session.
@Configuration
public class SqlSession {
@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
Resource[] res = new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml");
sqlSessionFactoryBean.setMapperLocations(res);
sqlSessionFactoryBean.setTypeAliases(new Class<?>[] { UserModel.class, PostModel.class, ReplyModel.class, FileModel.class});
return sqlSessionFactoryBean.getObject();
}
}
Swagger Configure
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.nomsa.bbs.Controller"))
.paths(PathSelectors.any())
.build();
}
}
Column | Datatype | PK | NN | UQ | UN | AI | Default |
---|---|---|---|---|---|---|---|
index | INT(11) | Yes | Yes | Yes | Yes | ||
identification | VARCHAR(30) | Yes | Yes | ||||
password | VARCHAR(50) | Yes | |||||
name | VARCHAR(15) | Yes | |||||
available | CHAR(1) | Yes |
Column | Datatype | PK | NN | UQ | UN | AI | Default |
---|---|---|---|---|---|---|---|
index | INT(11) | Yes | Yes | Yes | Yes | ||
writer | INT(11) | Yes | Yes | ||||
created | DATETIME | Yes | CURRENT_TIMESTAMP | ||||
type | VARCHAR(15) | Yes | |||||
title | VARCHAR(100) | Yes | |||||
content | TEXT | Yes | |||||
available | CHAR(1) | Yes |
Column | Datatype | PK | NN | UQ | UN | AI | Default |
---|---|---|---|---|---|---|---|
index | INT(11) | Yes | Yes | Yes | Yes | ||
writer | INT(11) | Yes | Yes | ||||
created | DATETIME | Yes | CURRENT_TIMESTAMP | ||||
post | INT(11) | Yes | Yes | ||||
content | VARCHAR(300) | Yes | |||||
available | CHAR(1) | Yes |
Column | Datatype | PK | NN | UQ | UN | AI | Default |
---|---|---|---|---|---|---|---|
index | INT(11) | Yes | Yes | Yes | Yes | ||
post | INT(11) | Yes | Yes | ||||
name | VARCHAR(100) | Yes | |||||
size | INT(11) | Yes | Yes | ||||
bytes | LONGBLOB | Yes | |||||
available | CHAR(1) | Yes |
2018.08.06. JWT Util.
2018.08.07. Define REST API.
2018.08.08. Sign Up, Sing In.
2018.08.09. Post Write, Reply Write.
2018.08.10. Get Posts, Get Post.
2018.08.11. Problems during communication. (CORS)
2018.08.12. Solve CORS. Spring Boot excution problem when solving CORS.
2018.08.13. Solve Spring Boot excution.