언어·프레임워크/Spring Boot

[Spring Boot][문제해결] DB에 값을 저장할 때 유니코드로 저장되는 문제

DandyNow 2022. 8. 25. 00:23
728x90
반응형

[그림 1] DB에 유니코드로 저장됨

 

[그림 2] 콘솔창에도 유니코드로 표기됨

 

Spring Boot, Gradle, JPA, MySQL 환경에서 DB에 값을 저장하였다. 영문의 경우에는 영문으로 표시되었는데 한글의 경우에는 유니코드로 저장되는 문제가 생겼다. 이 문제는 게시글 작성, 수정하는 jsp 파일에 UTF-8 설정이 되어 있지 않음으로 인한 것이었다. 아래 코드는 게시글을 작성하는 화면인 create.jsp 코드이며 최 상단에 UTF-8 설정을 해주었다.

 

create.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html lang="ko">
<head>
    <style>
        table{
            width: 60%;
            border-collapse: collapse;
        }
        th{
            border-bottom: 1px solid;
            border-bottom: 2px solid;
        }
        td{
            text-align: center;
            padding: 7px 0 11px;
            border-bottom: 1px solid;
        }
    </style>
</head>
<body>
    <h1> Board</h1>
    <br/>
    <div class="container">
        <table class="table table-hover table table-striped">
            <tr>
                <th>PostId</th>
                <th>NickName</th>
                <th>Title</th>
                <th>Content</th>
                <th>Edit</th>
                <th>Delete</th>
            </tr>

            <c:forEach items="${postList}" var="post">
                <tr>
                    <td>${post.getSeq()}</td>
                    <td>${post.getWriter()}</td>
                    <td>${post.getTitle()}</td>
                    <td>${post.getContent()}</td>
                    <td><a href="updateView/${post.getSeq()}">수정</a></td>
                    <td><a href="delete/${post.getSeq()}">삭제</a></td>
                </tr>
            </c:forEach>
        </table>
        <br/>
        <a href="createView">새 글 작성</a>
    </div>

</body>
</html>

 

728x90
반응형