본문 바로가기
Developer/Java

[Java] ModelAndView_예제01

by 순수한소년 2018. 8. 26.
728x90
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package egovframework.rte.tex.com.web;
 
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
 
import egovframework.rte.tex.com.service.EgovUserUtil;
import egovframework.rte.tex.mbr.service.MemberVO;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJacksonJsonView;
 
@Controller
public class EgovCommonController {
 
    /** LocaleResolver */
    @Resource
    LocaleResolver localeResolver;
 
    /**
     * 권한이 없는 사용자가 접근시 권한제한 화면으로 이동한다.
     * @return "cmmn/EgovAccessDenie"
     * @exception Exception
     */
    @RequestMapping("/com/accessDenied.do")
    public String accessDenied() throws Exception {
        return "cmmn/EgovAccessDenied";
    }
 
    /**
     * 국제화 적용 페이지로 이동한다.
     * @return "main/EgovMain"
     * @exception Exception
     */
    @RequestMapping(value = "/com/egovMain.do", method = RequestMethod.GET)
    protected String changeLocale(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
        Locale locale = new Locale("kr"); //default = kr
        if (request.getParameter("locale"== null) {
            locale = localeResolver.resolveLocale(request);
        } else {
            locale = new Locale(request.getParameter("locale"));
        }
        // localeResolver에 locale 셋팅
        localeResolver.setLocale(request, response, locale);
 
        MemberVO loginVO = EgovUserUtil.getMemberInfo();
        model.addAttribute("loginVO", loginVO);
 
        return "main/EgovMain";
    }
 
    /**
     * AJAX기능을 jQuery를 이용하여 탭형식으로 나타낸다.
     * @param tabName 각 탭명
     * @param request
     * @return 메인페이지
     * @throws Exception
     */
    @Resource
    ResourceBundleMessageSource messageSource;
    @Resource
    MappingJacksonJsonView ajaxMainView;
 
    @RequestMapping(value = "/com/ajax.do")
    protected ModelAndView egovMain(String tabName, HttpServletRequest request) throws Exception {
 
        Locale locale = localeResolver.resolveLocale(request); //language 
 
        Map<String, Object> model = new HashMap<String, Object>();
 
        model.put("divId""." + tabName);
        model.put("description", messageSource.getMessage(tabName, null, locale));
 
        return new ModelAndView(ajaxMainView, model);
    }
}
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<%@ page language="java" contentType="text/html; charset=utf-8"    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="validator" uri="http://www.springmodules.org/tags/commons-validator"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%
 /**
  * @JSP Name : EgovMain.jsp
  * @Description : 메인 화면
  * @Modification Information
  * 
  *   수정일         수정자                   수정내용
  *  -------    --------    ---------------------------
  *  2011.06.07  신혜연          최초 생성
  *
  * author 실행환경팀 
  * Copyright (C) 2011 by MOPAS  All right reserved.
  */
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>egov | main</title>
 
<link type="text/css" rel="stylesheet" href="<c:url value='/css/egovframework/egov.css'/>" >
<link type="text/css" rel="stylesheet" href="<c:url value='/css/egovframework/jquery-ui-1.8.14.custom.css'/>">
<script type="text/javaScript" src="<c:url value='/js/jquery-1.5.1.min.js'/>"></script>
<script type="text/javaScript" src="<c:url value='/js/jquery-ui-1.8.14.custom.min.js'/>"></script>
 
<script type="text/javaScript" language="javascript" defer="defer">

$(function(){
    $('#tabs').tabs();
    ajaxCall('Restful');
    $("#tabs").bind('tabsselect'function(event, ui) {
        ajaxCall(ui.tab.innerHTML);
    });
});
 
function ajaxCall(tabName){
    $.ajax({
          url:  '<c:url value="/com/ajax.do" />',
          data: "tabName="+tabName,
          dataType: 'json',
          success: function(data) { 
              $(data.divId).html(data.description);
        }
    });
}
 
</script>
 
</head>
<body style="text-align: center; margin: 0 auto; display: inline; padding-top: 100px;">
    <!-- 전체 레이어 시작 -->
    <div id="wrap">
        <!-- header 시작 -->
        <div id="header"><%@ include
                file="/WEB-INF/jsp/egovframework/rte/tex/com/header.jsp"%></div>
        <!-- //header 끝 -->
        <!-- container 시작 -->
        <div id="container">
            <!-- 좌측메뉴 시작 -->
            <div id="leftmenu"><%@ include
                    file="/WEB-INF/jsp/egovframework/rte/tex/com/leftmenu.jsp"%></div>
            <!-- //좌측메뉴 끝 -->
 
            <!-- content 시작 -->
            <div id="content_pop">
            <spring:message code="main.title"/>
            <div id="tabs">
                    <ul>
                        <li><a href="#tabs-1">Restful</a></li>
                        <li><a href="#tabs-2">ORM</a></li>
                        <li><a href="#tabs-3">Excel</a></li>
                        <li><a href="#tabs-4">OXM</a></li>
                    </ul>
                    <div id="tabs-1" class="Restful" style="height: 250px;"></div>
                    <div id="tabs-2" class="ORM" style="height: 250px;"></div>
                    <div id="tabs-3" class="Excel" style="height: 250px;"></div>
                    <div id="tabs-4" class="OXM" style="height: 250px;"></div>
                </div>
            </div>
            <!-- //content 끝-->
        </div>
        <!-- //container 끝-->
        <!-- footer 시작 -->
        <div id="footer"><%@ include file="/WEB-INF/jsp/egovframework/rte/tex/com/footer.jsp"%></div>
        <!-- //footer 끝 -->
    </div>
    <!--// 전체 레이어 끝 -->
</body>
</html>
 
 
cs


반응형