November 07, 2021
해당 게시물은 이 강의를 보고 제작하게되었습니다.
create user 'kbox'@'%' identified by '1234';
GRANT ALL PRIVILEGES ON *.* TO 'kbox'@'%';
create database security;
use security;
server:
port: 8080
servlet:
context-path: /
encoding:
charset: UTF-8
enabled: true
force: true
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/security?serverTimezone=Asia/Seoul
username: kbox
password: 1234
# 생략 가능
# mvc:
# view:
# prefix: /templates/
# suffix: .mustache
jpa:
hibernate:
ddl-auto: create #create update none
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
show-sql: true
package com.kbox.security1.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller // View를 리턴하겠다
public class IndexController {
// localhost:8080/
// localhost:8080
@GetMapping({"","/"})
public String index() {
// 머스태치 기본폴더 src/main/resources/
// viewReslover 설정 : templates (prefix), .mustach(suffix) 생략 가능
return "index"; // src/main/resources/templates/index.mustach
}
}
package com.kbox.security1.config;
import org.springframework.boot.web.servlet.view.MustacheViewResolver;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebMvcConfig implements WebMvcConfigurer{
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
MustacheViewResolver resolver = new MustacheViewResolver();
resolver.setCharset("UTF-8");
resolver.setContentType("text/html; charset=UTF-8");
resolver.setPrefix("classpath:/templates/");
resolver.setSuffix(".html");
registry.viewResolver(resolver);
}
}