Today Yewon Learned

[JAVA] Spring 다국어 변환 - 언어에 따라 DB컬럼 다르게 표출하기(1) 본문

JAVA

[JAVA] Spring 다국어 변환 - 언어에 따라 DB컬럼 다르게 표출하기(1)

데브워니 2022. 4. 19. 09:19

홈페이지 번역 작업을 하다보니, 데이터베이스에 공통코드로 묶은 데이터들을 언어에 따라 다르게 표출해야할 상황이 생겼다.

ex) 메뉴는 공통코드 리스트로 표출

 

먼저 DB에 언어별 컬럼을 생성해주었다.

 

공통코드 테이블

메뉴테이블

CmmnController.java

@RequestMapping(value = "left.do", method = RequestMethod.POST)
public String index(Locale locale, ModelMap model, HttpServletRequest request) throws Exception {
    HttpSession session = request.getSession();

    //System.out.println("*********** locale : " + locale.getLanguage());

    if(locale.getLanguage().equals("ko")) {

        List<?> list = cmmnService.selectCommCdList(session.getAttribute("id").toString());
        model.addAttribute("MenuList", list);

        CodeData data = new CodeData();

        data.setCOMM_GROUP("M");
        data.setCOMM_CD("001");

        List<?> use_list = codeService.selectCommCdList(data);

        model.addAttribute("MenuGroup", use_list);
        model.addAttribute("active_menu_group", request.getParameter("active"));

    } else {

        List<?> list = cmmnService.selectCommCdList_en(session.getAttribute("id").toString());
        model.addAttribute("MenuList_en", list);

        CodeData data = new CodeData();

        data.setCOMM_GROUP("M");
        data.setCOMM_CD("001");

        List<?> use_list = codeService.selectCommCdList_en(data);

        model.addAttribute("MenuGroup", use_list);
        model.addAttribute("active_menu_group", request.getParameter("active"));

    }

    return "include/left";
}

 

left.jsp

<c:choose>
	<c:when test="${fn:length(MenuList) > 0 }">
		<c:set var="menugroup" value=""/>
		<c:forEach var="row" items="${MenuGroup}" varStatus="status">
			<c:forEach var="row1" items="${MenuList}" varStatus="status1">
				<c:if test="${row.COMM_SUB_CD == row1.MENU_GRP}">
					<c:if test="${menugroup != row1.MENU_GRP}">
						<c:set var="menugroup" value="${row1.MENU_GRP}"/>
						<li class="nav-item">
					    <a class="nav-link collapsed" href="javascript:void(0)" data-toggle="collapse" data-target="#<c:out value="${menugroup}"></c:out>"
					        aria-expanded="true" aria-controls="collapseTwo">
					        <span><c:out value="${row.COMM_SUB_NM}"></c:out></span>
					    </a>
					    <div id="<c:out value="${menugroup}"></c:out>" class="collapse <c:if test="${menugroup == active_menu_group}"> show </c:if>" aria-labelledby="headingTwo" data-parent="#accordionSidebar">
					        <div class="bg-gray py-2 collapse-inner rounded">
						        <c:forEach var="row2" items="${MenuList}" varStatus="status2">
						        	<c:if test="${menugroup == row2.MENU_GRP}">
						        		<a class="collapse-item" href="<c:out value="${row2.MENU_URL}"></c:out>"><c:out value="${row2.MENU_NM}"></c:out></a>
						        	</c:if>
						        </c:forEach>
					        </div>
					    </div>
					</li>
					</c:if>
				</c:if>
			</c:forEach>					
		</c:forEach>	
	</c:when>
	<c:when test="${fn:length(MenuList_en) > 0 }">
		<c:set var="menugroup" value=""/>
		<c:forEach var="row" items="${MenuGroup}" varStatus="status">
			<c:forEach var="row1" items="${MenuList_en}" varStatus="status1">
				<c:if test="${row.COMM_SUB_CD == row1.MENU_GRP}">
					<c:if test="${menugroup != row1.MENU_GRP}">
						<c:set var="menugroup" value="${row1.MENU_GRP}"/>
						<li class="nav-item">
					    <a class="nav-link collapsed" href="javascript:void(0)" data-toggle="collapse" data-target="#<c:out value="${menugroup}"></c:out>"
					        aria-expanded="true" aria-controls="collapseTwo">
					        <span><c:out value="${row.COMM_SUB_NM_EN}"></c:out></span>
					    </a>
					    <div id="<c:out value="${menugroup}"></c:out>" class="collapse <c:if test="${menugroup == active_menu_group}"> show </c:if>" aria-labelledby="headingTwo" data-parent="#accordionSidebar">
					        <div class="bg-gray py-2 collapse-inner rounded">
						        <c:forEach var="row2" items="${MenuList_en}" varStatus="status2">
						        	<c:if test="${menugroup == row2.MENU_GRP}">
						        		<a class="collapse-item" href="<c:out value="${row2.MENU_URL}"></c:out>"><c:out value="${row2.MENU_NM_EN}"></c:out></a>
						        	</c:if>
						        </c:forEach>
					        </div>
					    </div>
					</li>
					</c:if>
				</c:if>
			</c:forEach>					
		</c:forEach>	
	</c:when>
</c:choose>

'JAVA' 카테고리의 다른 글

[JAVA] request.getParameter() 메소드  (0) 2021.11.30
[JAVA] Generic(제네릭)  (0) 2021.11.15
[JAVA] Casting(캐스팅 : 형변환)  (0) 2021.11.12
[JAVA] 상속  (0) 2021.11.11
[JAVA] Setter 메소드와 Getter 메소드  (0) 2021.11.10
Comments