'thymeleaf 한글'에 해당되는 글 1건

# [Spring MVC] thymeleaf 적용하기

1. pom.xml 

<dependency>
	<groupId>org.thymeleaf</groupId>
	<artifactId>thymeleaf-spring5</artifactId>
	<version>3.0.11.RELEASE</version>
</dependency>

2. servlet-context.xml 설정 

 # 만약 thymelead 한글 깨진 다면,  아래의 UTF-8 들어간 부분을 확인하시길 바랍니다.

<beans:property name="characterEncoding" value="UTF-8" />

<beans:property name="fileEncoding" value="UTF-8" />

	<!-- 기존 jsp로 화면 설계 부분 -->
	<!-- 
	<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
		<beans:property name="prefix" value="/WEB-INF/views/" /> <beans:property 
		name="suffix" value=".jsp" /> </beans:bean> 
	-->
	
	<!-- thymeleaf 설정 부분  -->
	<beans:bean id="templateResolver"
		class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
		<beans:property name="prefix" value="/WEB-INF/views/" />
		<beans:property name="suffix" value=".html" />
		<beans:property name="templateMode" value="HTML5" />
		<beans:property name="cacheable" value="false" />
		<beans:property name="characterEncoding" value="UTF-8" />
	</beans:bean>

	<beans:bean id="templateEngine"
		class="org.thymeleaf.spring5.SpringTemplateEngine">
		<beans:property name="templateResolver"
			ref="templateResolver" />
	</beans:bean>

	<beans:bean
		class="org.thymeleaf.spring5.view.ThymeleafViewResolver">
		<beans:property name="templateEngine"
			ref="templateEngine" />
		<beans:property name="characterEncoding" value="UTF-8" />
	</beans:bean>

	<beans:bean
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<beans:property name="location"
			value="/resources/config/application.config" />
		<beans:property name="fileEncoding" value="UTF-8" />
	</beans:bean>
	<!-- thymeleaf 설정 부분  -->

3. 페이지 

<!DOCTYPE html>

<!-- thymelead 불러오기 -->
<html lang="ko" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
	<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>파일업로드</title>
</head>

<body>
	<div th:if="${msg!=null}" style="">
		<h1>파일 업로드 결과</h1>
		<h2 th:text="${msg}">${msg}</h2>
	</div>

	<h1>단일 파일 보내기</h1>
	<form method="post" enctype="multipart/form-data" action="" th:action="@{fileUpload}">
		<label>file : </label> <input type="file" name="file"> <label>name
			: </label> <input type="text" name="name"> <input type="submit" value="upload">
	</form>

	<h2>여러개 파일 보내기</h2>
	<form method="post" enctype='multipart/form-data' action="" th:action="@{multiFileUpload}">
		<label>files : </label> <input type="file" name="files" multiple>
		<label>name : </label> <input type="text" name="name"> <input type="submit" value="upload">
	</form>

    <div id="root">
        
    </div>
    <!-- <script src="../resources/dist/app.js"></script> -->
    <script src="../dist/app.js"></script>
</body>

</html>
블로그 이미지

미나미나미

,