MVC 패턴을 기본으로 하는 Springboot Project를 구성함
이클립스(또는 STS) 기준으로 함
File > New > Spring Starter Project
위와 같이 세팅 후 Next
Lombok, Spring Web
선택 (원하는 의존성 추가 가능) 후 next → Finish
# 사용할 포트 :: port
server.port = 9090
#spring :: 스프링 setting
spring.application.name=ila-pofol
spring.application.sql=mysql
방법은 두 가지 이다.
기본적으로 스프링 부트에서 web의존성 추가 후 localhost:9090
으로 접근하면 resources/static/index.html
을 읽게된다.
만약 resources/templates/index.html
로 위치하려면 스프링 부트에서 제공하는 WebMvcConfigurer
를 implements
한후 addResourceHandlers
를 override 해야한다.
package com.example.ilapofol.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class ViewConfiguration implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/templates/", "classpath:/static/");
}
}
application.properties
를 아래와같이 thymeleaf 추가
#port
server.port = 9090
#spring
spring.application.name=ila-pofol
spring.application.sql=mysql
#thymeleaf
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false
spring.thymeleaf.check-template-location=true
build.gradle
에 thymeleaf 의존성 추가
plugins {
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'java'
}
group = 'com.example.ila-pofol'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
// 타임리프 아래 3개 implementation 추가
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
create database ilapofol;
CREATE TABLE brewerypg (
id int(11) NOT NULL auto_increment PRIMARY KEY,
commend varchar(100) NOT NULL,
regularvisit char(1) CHECK (regularvisit in ('Y','N')),
time time NOT NULL,
brnm varchar(50) NOT NULL,
braddr varchar(50) NOT NULL,
brtel varchar(20) NOT NULL,
resevisit char(1) CHECK (resevisit in ('Y','N')),
placenm varchar(20) NOT NULL,
kind varchar(10),
programnm varchar(20),
cost int(10),
url varchar(20)
);
CREATE TABLE translang (
id int (11) NOT NULL auto_increment PRIMARY KEY,
langcode char(20),
langnm varchar(20))