2014. 10. 15. 22:41




1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version="1.0" encoding="UTF-8"?>
<Context>
    <Resource 
    name="jdbc/oracle"
    auth="Container"
    driverClassName="oracle.jdbc.OracleDriver"
    type="javax.sql.DataSource"
    url="jdbc:oracle:thin:@localhost:1521:xe"
    username="test"
    password="1111"
    maxIdle="10" maxActive="20" maxWait="-1"
    />
</Context>
Colored By Color Scripter


Posted by 루피아빠
2014. 10. 15. 22:15




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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC 
"-//mybatis.org/DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
    <setting name="jdbcTypeForNull" value="NULL"/>
</settings>
 
    <typeAliases>
        <typeAlias type="com.pmi.lms.vo.User" alias="User"/>    
        <typeAlias type="com.pmi.lms.vo.Hits" alias="Hits"/>    
        <typeAlias type="com.pmi.lms.vo.Likes" alias="Likes"/>
        <typeAlias type="com.pmi.lms.vo.Massage" alias="Massage"/>    
        <typeAlias type="com.pmi.lms.vo.Picture" alias="Picture"/>    
    </typeAliases>

    <mappers>
        <mapper resource="com/pmi/lms/map/user.xml"/>  
        <mapper resource="com/pmi/lms/map/hits.xml"/> 
        <mapper resource="com/pmi/lms/map/likes.xml"/> 
        <mapper resource="com/pmi/lms/map/massage.xml"/> 
        <mapper resource="com/pmi/lms/map/picture.xml"/> 
    </mappers>
</configuration>

Colored By Color Scripter

Posted by 루피아빠
2014. 10. 15. 21:56



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
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
 
    <!-- view만 있는 요청들은 Contoller없이 실행하도록 -->
    <mvc:annotation-driven/>
    <mvc:view-controller path="/view_page_name1.html"
        view-name="view_page_name1" />
    <mvc:view-controller path="/view_page_name2.html"
        view-name="view_page_name2" />
    <mvc:view-controller path="/view_page_name3.html"
        view-name="view_page_name3" />
    
    <!-- controller 등록 -->
    <bean class="com.pmi.lms.controller.MainController"/>
    <bean class="com.pmi.lms.controller.JoinController"/>
    <bean class = "com.pmi.lms.controller.BoardController"
    p:rename-ref="rename"/>
    
    <!-- 포워드뷰를 편리하게 사용하도록 해결해주는 해결사 -->
    <!-- WEB-INF/view/ .jsp 생략시켜줌 -->
    <bean 
    p:prefix="WEB-INF/view/" 
    p:suffix=".jsp"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"/> 
 
      <!-- interceptor들 설정 -->
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/main.html"/>
            <bean class="com.pmi.photo.util.LoginCheckInterceptor"/>
        </mvc:interceptor>
 
    </mvc:interceptors> 
 
</beans>
 

Colored By Color Scripter

Posted by 루피아빠
2014. 10. 15. 21:41




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
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:websocket="http://www.springframework.org/schema/websocket"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd">
 
    <!-- @Controller, @Service -->
    <mvc:annotation-driven />
 
    <!-- jndi 설정 : Java Naming and Directory Interface -->
    <!-- jndi-name에서 "java:comp/env/여기 부분을 찾음  -->
    <!-- META-INF/context.xml에서 name의 값과 같음 -->
    <!-- WEB-INF/lib/ojdbc6.jar 파일 필요 -->
    <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/oracle" />
    
    <!--  jndi 설정을 안하면 아래 코드로 작성 -->
    
    <!-- DataSource 설정 -->
    <!--  
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
    p:driverClassName="oracle.jdbc.OracleDriver"
    p:url="jdbc:oracle:thin:@localhost:1521:xe"
    p:username="test"
    p:password="1111"/>
    -->
 
    <!-- SqlSessionFactory 설정 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
        p:dataSource-ref="dataSource" p:configLocation="WEB-INF/mybatis-config.xml" />
 
    <!-- SqlSessionTemplate 설정 -->
    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg ref="sqlSessionFactory" />
    </bean>
    <!-- 여기까지 기본셋팅 -->
 
    <!-- Bean DAO설정 --> 
    <!-- scope의 default는 싱글톤으로 만들어집니다. -->
    <bean scope="singleton" id="usersDAO" p:session-ref="sqlSession"
    class="com.pmi.lms.dao.UserDAOImpl"/>
    
    <!-- Bean Service설정 --> 
    <bean id="usersService" p:userDAO-ref="usersDAO"
    class="com.pmi.lms.service.UserServiceImpl"/>
    
    <!-- multipartResolver 설정(멀티파트,업로드처리) -->
    <bean id="multipartResolver" p:defaultEncoding="UTF-8"
        p:maxUploadSize="104857600"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
    
    <!-- util 설정 -->
    <bean id="rename" class="com.pmi.lms.util.FileRenameUtil"/>
    
</beans>
 

Colored By Color Scripter

Posted by 루피아빠
2014. 10. 15. 18:59




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
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>project-name</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
<!-- 여기는 톰캣설정(WAS)설정입니다.  -->
<!-- 톰캣이 켜지면서 web.xml을 읽어들입니다. -->

<!-- post방식의 한글처리 설정 -->
<!-- dispatcherServlet보다 먼저 필터링을 합니다. -->
  <filter>
    <filter-name>encoding</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>encoding</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
<!-- //post방식의 한글처리 설정 -->

<!-- FrontController역할을 담당하는 서블릿 설정-->
<!-- servlet-name은 appName-servlet.xml의 " "-servlet 앞의 파일명이 됩니다. --> 
<!-- 1의 의미 : 서버가 켜지면서 객체가 생성된다는 의미 -->
  <servlet>
    <servlet-name>app-name</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
<!-- //FrontController역할을 담당하는 서블릿 설정--> 

<!-- URL 패턴 설정 -->
  <servlet-mapping>
    <servlet-name>app-name</servlet-name>
    <url-pattern>*.html</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>app-name</servlet-name>
    <url-pattern>*.json</url-pattern>
  </servlet-mapping>
<!-- //URL 패턴 설정 -->
<!-- Error page 설정 -->
  <error-page>
    <error-code>404</error-code>
    <location>/WEB-INF/view/error.jsp</location>
  </error-page>
<!-- //Error page 설정 -->

<!-- applicationContext.xml 설정 -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
<!-- //applicationContext.xml 설정 -->
</web-app>

Colored By Color Scripter


Posted by 루피아빠
2014. 10. 14. 19:58


사용 목적 


- 모듈간 결합도를 낮추기 위해 사용(종속성 제거

- 협업, 유지보수 용이

 


(설명)

A class B class가 있습니다. B class의 구현을 위해 A객체가 필요하다면 B class A class에 대한 Dependency(의존성)을 가진다고 말합니다.따라서 B class의 구현을 위해서는 A Bean이 필요한데 필요하다고 해서 직접 A Bean생성(new A() 방식)을 하지 않고 다른 방법을 통해 A Bean를 주입시켜 주는 것을 DI(의존성 주입)이라고 말합니다.

 

 

의존성 주입 3가지 패턴

(3 Patterns of Dependency Injection by Martin Fowler)

 

1) 생성자를 통한 주입(Injection by Constructor) : 비추

 

- A class의 생성자를 만들어 B class에 의존성을 주입

 

2) 셋터 메서드를 통한 주입(Injection by Setter method)

 

- A class(멤버)필드에 대한 setter()를 만들어 의존성 주입

 

3) 인터페이스를 통한 주입(Injection by Interface)

 

- 인터페이스에 의존성을 주입하는 추상메서드를 만들고 실행시 이 인터페이스를 

구현함으로써 의존성을 주입

 

 

 

<의존성 주입 예시>

 

BoardDAO 인터페이스

 

package dao;

import java.util.List;

import vo.Board;

 

//확장성을 휘해 BoardDAO를 인터페이스 생성

public interface BoardDAO {

         public List<Board> selectBoardList();

}//BoardDAO interface end

 

BoardDAO 인터페이스 구현 클래스

 

package dao;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import vo.Board;

 

//인터페이스 BoardDAO의 구현을 위한 BoardDAOImpl class

public class BoardDAOImpl implements BoardDAO {

 

// BoardDAO class SqlSession Class에 의존성을 가짐

// 1) SqlSession property 선언

// 2) SqlSession class setter()를 통해 의존성 주입

private SqlSession session;

public void setSession(SqlSession session) {

this.session = session;

}

 

//구현객체는 반드시 추상메서드를 구현해야합니다.

         public List<Board> selectBoardList(){

        

//의존성 주입을 했기 때문에 session객체를 바로 쓸 수 있습니다.

return session.selectList("board.selectBoardList");

         }; // selectBoardList()

}//BoardDAOImpl class end

 

 

BoardService 인터페이스

 

package service;

import java.util.List;

import vo.Board;

 

//BoardService interfaceTransaction 관리를 위해 만듭니다.

public interface BoardService {

public List<Board> getList();

}//BoardService interface end

 

BoardService 인터페이스 구현 클래스

 

package service;

import java.util.List;

import vo.Board;

import dao.BoardDAO;

 

//BoardService interface구현을 위한 BoardServiceImpl class

public class BoardServiceImpl implements BoardService {

 

 //BoardService BoardDAO에 대한 의존성을 가짐

          //따라서 BoardDAO Property를 선언해주고

 //setter를 통해 의존성 주입

         private BoardDAO dao;

 

 public void setDao(BoardDAO dao){

                   this.dao = dao;

 }

 

//구현객체는 반드시 추상메서드를 구현해야합니다.

 public List<Board> getList(){

   //의존성 주입을 했기 때문에 dao객체를 바로 쓸 수 있습니다.

                   return dao.selectBoardList();

 }

}//BoardServiceImpl class end


 

Tip) method명 짓는 노하우

 

- DAO SQL구문과 직접 관련되므로 메서드명에 select, update,delete,insert를 쓰면 편리함 ()selectList, selectOne

 

- Service DAO를 호출하기 때문에 굳이 SQL를 몰라도 됩니다.메서드명 규칙는 의미에 맞게 해줍니다. ()getList,getBoard,getUserInfo





크리에이티브 커먼즈 라이선스


Posted by 루피아빠
2014. 10. 14. 17:33

기본개념


아파치 메이븐은 프로젝트의 전체적인 생명주기를 관리해주는 자바 빌드 툴입니다.

메이븐을 통해 다양한 버전의 라이브러리 의존성 관리를 한번에 할 수 있습니다.

(광범위한 jar파일들을 쉽게 관리)

 

설치법


메이븐은 오픈 API 프로젝트이기 때문에 무료로 다운받을 수 있습니다.

톰캣서버를 키면 메이븐은 서버에서 pom.xml에 설정해 놓은 jar파일들을 자동으로 다운받아줍니다.

(다운로드 경로 : C:\apache-tomcat-7.0.xx\wtpwebapps\getMaven\WEB-INF\lib)

필요한 jar파일을 복사해서 스프링을 켜고 진행중인 프로젝트의 WEB-INF/lib에 붙여 넣습니다.


자세한 설치과정은 아래 캡처사진을 보며 따라해주세요.

 


[English]


Basic Concept


Apache maven is build tool for Java to manage overall life-cycle of your project. Maven automatically configures settings of across multiple versions about dependency relationship. You can manage wide jar files easily with this maven.

 

Installation usage


Maven is open API project so you can free download it.

If you run Tomcat server, Maven get jar files on Server and save your Tomcat folder.

You just copy the jar files into library of your project and start Spring.

(Download Path : C:\apache-tomcat-7.0.xx\wtpwebapps\getMaven\WEB-INF\lib)



Let's start while seeing some pictures!

 

Step1)

 

Make a maven project.

Right mouse click -> New -> Other




 

Step2)

 

Maven -> Maven Project -> Next


 

 

Step3)

 

Click the Next button.


 

 

Step4)

 

Group Id : org.apache.maven.archetypes

Artifact Id : maven-archetype-webapp

Version : RELEASE

-> Next



 



Step5)

 

Group Id : org.package-name(or org.company-name)

Artifact Id : getMaven

-> Next


메이븐은 전세계 개발자들과 다양한 프로젝트를 공유하는 것을 목적으로 하기 때문에 Group IDArtifact ID 설정을 해야 합니다.


Maven project is goal to share various projects with developers in the web-world.

This is why, we should do Group id and Artifact Id configuration.

 




 

Step6)

 

We can see getMaven Project in Project explorer. Go ahead, Double click pom.xml!

 



 

Step7)

 

Can you see this screen?  Good job! Go ahead next step.

 



 

Step8)

 

Search maven repository you need on http://mvnrepository.com.

Just copy dependency and paste on pom.xml.

 


Example)

<dependency>

<groupId>org.mybatis</groupId>

<artifactId>mybatis-spring</artifactId>

<version>x.x.x</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-context</artifactId>

<version>x.x.x.RELEASE</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-jdbc</artifactId>

<version>x.x.x.RELEASE</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-webmvc</artifactId>

<version>x.x.x.RELEASE</version>

</dependency>

 


Step9)

 

Run Tomcat server, so jar files are saved in your Tomcat folder.




 

Step10)

 

Finally, last step!!

 

Change your project to Spring project, and choose jar files saved in your Tomcat folder. Then Copy and Paste on WebContent/Web-INF/lib.







* 항상 인터넷이 연결되어 있어서 


서버에 연결할 때마다 lib 다운하도록 하기



Dynamic Web Project를 먼저 생성하고 해당 프로젝트 마우스 오른쪽 클릭





여기서부터는 위 Step5와 동일







Enjoy your programming life!!

 

Good luck.

 

By Luffy’s fafa


 

크리에이티브 커먼즈 라이선스


 

 

 

Posted by 루피아빠
2014. 10. 14. 14:05

Step1)

 

Menu -> Help -> Install New Software Click

 

 

Step2) 

 

'Add' button click

 

 

Step3)

 

Just copy&paste red Url in Location blank.

-> http://dist.springframework.org/release/IDE

 

 

Step4)

 

Just check Core/Spring IDE and click 'Next' button.

 

 

Step5)

 

Check "Keep my installation the same and bla bla bla..." 

and click the 'Next' button.

 

 

Step6)

 

Click the 'Next' button.

 

 

Step7)

 

Check "I accept the terms of the license agreement"

and Click the 'Finish' button. 

 

 

Step8)

 

Installation complete!  

Just click 'Yes' button so eclipse will be restarted. 

 

 

Step9)

 

Do you see popup-message "Spring Tool Tips" in right-bottom position?

So you did install Spring IDE plug-in very well.

 

 

Enjoy your programming life!

   

Good luck.

   

By Luffy's fafa



'프로그래밍 > Spring Framework' 카테고리의 다른 글

DI;Dependency Injection - 의존성 주입  (2) 2014.10.14
Apache Maven project configuration - 메이븐 설정  (0) 2014.10.14
Spring MVC Flow  (0) 2014.10.14
ModelAndView Class  (0) 2014.10.14
Spring MVC패턴 (Model2 개발)  (0) 2014.09.11
Posted by 루피아빠
2014. 10. 14. 13:11

사진출처 : http://java9s.com/wp-content/uploads/2011/05/Spring-3-MVC-Basic-Flow.jpg

 

Client ---요청---> Server ---web.xml 분석 후 제어 넘김---> DispatcherSevlet

<--- Controller 결정 ---> HandlerMapping ---> DispatcherServlet <--- View, Model 리턴 받음 --- Controller

 

1) DispatcherServlet : 모든 사용자 요청 받음

2) HandlerMapping : 해당 요청 URL과 Controller를 맵핑

3) Controller : DispatcherSevlet에서 요청을 받고 요청에 따른 로직 수행

4) Controller : Model을 생성

5) DispatcherServlet : View 호출과 Model 출력

 

 

DispatcherServlet의 역할

1) HTTP 요청을 접수

2) HandlerMapping에서 해당 요청 URL에 해당하는 Controller 선정

3) 선정된 Contoller에게 웹 요청을 위임

4) 선정된 Controller에게 View객체와 Model객체를 리턴받음

5) View객체 호출과 해당 뷰에서 Model객체를 reference

 

HandlerMapping의 역할

- URL과 요청정보를 기준으로 Controller 선정

- 하나 이상의 Handler Mapping 가능

 

HandlerMapping(Interface)의 종류

- BeanNameUrlHandlerMapping(defualt)

 : bean설정 시 name속성으로 mapping

- RequestMappingHandlerMapping(defualt)

 : Controllerannotation을 부여해서 mapping

- SimpleUrlHandlerMapping : 설정파일에 한번에 모아서 설정

- ControllerClassNameHandlerMapping : 클래스명과 메서드명으로 mapping

- ControllerBeanNameHandlerMapping : Bean이름으로 mapping

 

참고) HandlerAdapter(Interface) : Controller의 메서드를 호출할 때 사용

 

View의 종류

- InternalResourceView(forward방식)

- RedirectView(redirect방식)

- MarchallingView(XML)

- MappingJacksonJsonView(Json)

 

ViewResolver의 역할

- Controller가 리턴한 View이름을 참고하여 View를 찾는다.

 

ViewResolver의 종류

- InternalResourceViewResolver

- ContentNegotiatingViewResolver

- ResourceBundleViewResolver

- XmlViewResolver


*web.xml

(경로 : WebContent/WEB-INF/web.xml)

<!-- DispatcherServlet 설정 -->

<servlet>

<servlet-name>OOO</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>

 

<servlet-mapping>

<servlet-name> OOO </servlet-name>

<url-pattern>*.html</url-pattern>

</servlet-mapping>

 

Controller / Service / DAOFlow

요청

-> 해당 Controller(서비스에 대해 의존적-DI필요)

: 요청에 대한 서비스 호출

-> 호출받은 Service: 필요한 DAO호출, 이곳에서 TX (트랜잭션)수행

-> 호출받은 DAO: DBSQL수행 <-> DB

 

Controller에서 View 리턴 방식 고려사항

- 요청에 대한 View가 필요한가?

만약 필요하다면 forward방식(view jsp)

불필요하다면 redirect방식(기능단 jsp)

(JSP파일 경로는 WEB-INF/view/OOO.jsp)

 

InternalResourceViewResolver - 편리한 forward방식의 View 지정

-WEB-INF/view.jsp 생략가능

-redirect:index.html 등으로 redirect 지정가능

<!-- 포워드 뷰 InternalResourceView를 편리하게 사용할 수 있도록 설정 -->

<!-- 경로는 WEB-INF/해당프로젝트명-servlet.xml파일 à

<bean

p:prefix="WEB-INF/view/"

p:suffix=".jsp"

class="org.springframework.web.servlet.view.InternalResourceViewResolver"/>

 

Controller Bean 등록하기

- 해당프로젝트명-servlet.xml에 등록

() <bean class="조직구분.회사명.프로젝트명.controller.LogController"/>

- Annotation을 이용(@Controller)

- 중복된 Url이 있는지 한번에 관리하기 용이

 

Model이 필요없는 요청(View만 있는 요청)

- 우리가 직접 Controller를 생성할 필요없음

<!-- view만 있는 요청들은 Controller를 안만들고 이렇게 할 수도 있습니다. -->

<!-- 경로는 WEB-INF/해당프로젝트명-servlet.xml파일 à

 

<mvc:annotation-driven/>

<mvc:view-controller path="/content.html"/>

 

Controller단에서 메서드 설정

- annotation @RequestMapping 지정

- GET/POST방식 다르게 지정 가능

@RequestMapping(value="join.html", method=RequestMethod.GET)

@RequestMapping(value="join.html", method=RequestMethod.POST)

파라미터 편리하게 받기

- annotation @ModelAttribute 이용

- parameterVOproperty 일치 시 자동으로 setting

 

Session에 등록

- annotation @SessionAttributes(“이름”) 이용

- Model에 이름의 Attributes가 있으면 Sessionscope등록

*scope란 객체가 살아있는 범위를 말함

*4가지 scope

- context : 웹 서비스가 유지되는 동안 유지

- session : 세션이 유지되는 동안(브라우저창이 켜져있는 동안)

- request : 포워드 방식일 경우 request가 유지되는 동안만 유지

- page : 해당 페이지내에서만 유지



크리에이티브 커먼즈 라이선스


Posted by 루피아빠
2014. 10. 14. 06:43

(번역)

Spring MVC framework에서 ModelAndView class Model class View class 모두를 소유하는 클래스입니다. 두 클래스를 모두 소유하지만 이 두 클래스는 완전히 별개입니다. ModelAndView class단지 Controller Model객체와 View객체를 단 하나의 값으로 리턴하는 것이 가능하게 해줍니다. 그리고 이 클래스는 handler DispatcherServlet class에 의해 리턴됩니다. View class form ViewResolver객체를 이용해서 String view name으로 처리합니다. 다른 방법으로는 View객체로 직접 처리됩니다. Model클래스는 Map인데 이 Map name에 의해 키값화된 복수 객체의 사용이 가능하게 합니다


(부연설명)

원래는 View에 대한 리턴을 ModelAndView 객체로 해야하지만 View객체만 리턴해도 됩니다. Forward ViewInternalResourceView객체를 사용합니다. 그래서 우리가 직접InternalResourceView객체를 넘기면 그냥 그 View를 이용합니다. 하지만 이게 너무 귀찮으니까 SpringMVC는 우리에게 편리한 방법을 제공합니다. 우리가 단지 JSP의 경로를 쓰면 알아서 InternalResourceView를 자동으로 만들어서 작동해줍니다. WEB-INF/view/XXX.jsp라는 접미,접두사가 항상 똑같고 길기 때문에 우리가 String으로 넘길때 InternalResourceViewResolver가 있어서 그게 편리하게 작동해줍니다. , 우리는 String을 그냥 JSP의 이름만 넘기면 알아서 접두(prefix),접미사(suffix)를 만들어서 InternalResourceView를 생성해줍니다. 그런데 더 편리하게 하기 위해서 Spring MVC는 심지어 우리가 리턴하지 않으면 알아서 해당주소(index.html)에서 .html를 제외한 이름의(index)jsp를 알아서 찾습니다.(RequestMapping)


(원문)

외부링크 : java.lang.Object

org.springframework.web.servlet.ModelAndView

public class ModelAndView

extends Object


Holder for both Model and View in the web MVC framework. Note that these are entirely distinct. This class merely holds both to make it possible for a controller to return both model and view in a single return value.Represents a model and view returned by a handler, to be resolved by a DispatcherServlet. The view can take the form of a String view name which will need to be resolved by a ViewResolver object; alternatively a View object can be specified directly. The model is a Map, allowing the use of multiple objects keyed by name.

Author : Rod Johnson, Juergen Hoeller, Rob Harrop



크리에이티브 커먼즈 라이선스

 


Posted by 루피아빠