wasup
Spring Legacy MiNi Project - STS / tiles 적용 본문
반응형
1. 툴 다운로드
sts : ( https://spring.io/tools )
2. 미니 프로젝트
2-1. Spring Legacy MiNi Project
2-2. Spring Boot MiNi Project
2-3 eGov
Project Name : slp(spring legacy project) 회원관리, 게시판
개발환경
- window10
- tomcat8.5
- mysql 5.5
- java version 1.8.0_40
- sts3
- jdbc 3.2.3
- myBatis 3.2.8
개발언어
- java, spring, jsp
- jsjq
- html5, css3
STS3(Spring Tool Suite3)-spring legacy project
: 이전부터 사용되어온 주 시스템(core, bases)
: Spring Legacy Project는 STS3까지 지원
: STS4부터는 Spring Boot가 기본
: STS4에서 Spring Legacy Project를 사용하기 위해서는 지원 플러그인을 따로 설치해서 사용
참고 링크 - ( https://woopi1087.tistory.com/26 )
참고 링크 - ( https://developsd.tistory.com/68 )
0_) 새프로젝트 생성
new project name : slp-tiles / package : com.mvc.pj
1_) pom.xml 설정
추가할 내용
<!-- MyBatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.8</version>
</dependency>
<!-- mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
</dependency>
<!-- Mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.31</version>
</dependency>
<!--spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<!-- tiles -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>2.2.2</version>
</dependency>
<!-- tiles-core -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>2.2.2</version>
</dependency>
2_) root-context.xml 수정
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="dataSource"
class="org.apache.ibatis.datasource.pooled.PooledDataSource">
<property name="driver" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/community" />
<property name="username" value="root" />
<property name="password" value="1234" />
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation"
value="classpath:/mybatis/mybatis-config.xml">
</property>
</bean>
<bean id="sqlSession"
class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg ref="sqlSessionFactory"></constructor-arg>
</bean>
</beans>
3_) src/main/resources/mybatis 작성(복사)
4_1) src/main/java/ 패키지 생성
com.mvc.pj.domain : MemberDTO.java, BoardDTO.java
com.mvc.pj.controller : MemberController.java, BoardController.java
4_2) src/main/resources/mybatis의 하위.xml 패키지명 수정
: 3_)번과 연결
5_) view하위의 member폴더와 board폴더 작성(복사)
: 수정사항 없으면 패스
6_) 타일즈 프로젝트의 pom.xml 설정 가져오기
<!-- tiles -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>2.2.2</version>
</dependency>
<!-- tiles-core -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>2.2.2</version>
</dependency>
7_) tiles 프로젝트의 servlet-context.xml 설정 가져오기
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving
up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<beans:bean
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<beans:property name="definitions">
<beans:list>
<beans:value>/WEB-INF/tiles-def.xml</beans:value>
</beans:list>
</beans:property>
</beans:bean>
<beans:bean
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<beans:property name="viewClass"
value="org.springframework.web.servlet.view.tiles2.TilesView" />
<beans:property name="viewNames" value=".*" />
<beans:property name="order" value="1" />
</beans:bean>
<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/views directory -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
<beans:property name="order" value="2" />
</beans:bean>
<context:component-scan
base-package="com.mvc.pj" />
</beans:beans>
8_) tiles 프로젝트의 tiles-def.xml가져오기
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
"http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
<definition name=".main.layout" template="/WEB-INF/views/layout.jsp">
<put-attribute name="header" value="/WEB-INF/views/header.jsp"/>
<put-attribute name="side" value="/WEB-INF/views/side.jsp"/>
<put-attribute name="content" value="/WEB-INF/views/list.jsp"/>
<put-attribute name="footer" value="/WEB-INF/views/footer.jsp"/>
</definition>
<definition name=".main.*.*" extends=".main.layout">
<put-attribute name="content" value="/WEB-INF/views/{1}/{2}.jsp"/>
</definition>
</tiles-definitions>
9_) tiles 프로젝트의 view하위의 header, side, footer, layout 작성(가져오기)
10_) Controller 수정
HomeComtroller.java
//return "home";
return ".main.layout";
BoardController.java수정
//return "board/writeForm";// View return writeForm.jsp
return ".main.board.writeForm"; // View return
//return "board/list"; // View return list.jsp
return ".main.board.list"; // View return
//return "board/content"; //view return content.jsp
return ".main.board.content"; // View return
//mv.setViewName("board/updateForm");//updateForm.jsp
mv.setViewName(".main.board.updateForm");//View return
MemberComtroller.java수정
//return "main";//뷰 리턴 //views/main.jsp
return ".main.layout";//View return
//return "/member/insertForm";//views/member/insertForm.jsp
return ".main.member.insertForm";// View return
//return "main";//뷰 리턴
return ".main.layout";//View return
//return "member/loginForm";//views/member/loginForm.jsp 뷰를 리턴
return ".main.member.loginForm";
//return "/member/loginForm";//뷰 리턴 loginForm.jsp
return ".main.member.loginForm";//View return
//return "member/loginSucess";//loginSucess.jsp 뷰리턴
return ".main.member.loginSucess";//View Return
//return "/member/logOut";//뷰 리턴 logOut.jsp
return ".main.member.logOut";//View Return
//return "/member/updateForm";//뷰리턴 updateForm.jsp
return ".main.member.updateForm";//View Return
//return "main";//뷰 리턴
return ".main.layout";//View Return
//return "main";//뷰 리턴
return ".main.layout";//View Return
11_) resources 파일 가져오기
반응형
'IT > Java' 카테고리의 다른 글
Spring) 계층형 게시판 만들기(답변+댓글) (0) | 2021.08.17 |
---|---|
Spring) spring boot - spring starter project 해보기! (0) | 2021.08.16 |
Spring) Tiles 사용해보기 (0) | 2021.08.13 |
Spring Legacy MiNi Project - STS / board view (0) | 2021.08.11 |
Spring Legacy MiNi Project - STS / board java (0) | 2021.08.10 |
Comments