Spring - 기초편1
저장위치 라고 해야하나 글을 받아 들이는 곳이라고 해야하나 ?
뭐 그런 것에 대해 써보려고 한다.
1) 파일 이름 : 01-SpringURLMapping
2) 앞에서 사용한 기본적인 파일
1. com.heeyeon.config -> package
① . RootAppContext.java
② . ServletAppContext.java
③ . SpringConfigClass.java
2. com.heeyeon.controller -> package
① . HomeController.java
3) 파일 자체에 pom.xml 넣기
-----------------------------------------------------------------------------------------------------------
1. TestController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
package com.heeyeon.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class TestController {
@RequestMapping(value="/Test01.do", method=RequestMethod.GET)
public String test01() {
System.out.println("test01.jsp는 없지만 이 로그는 출력 되어야 한다");
// 여기에 필요한 로직들을 쓴다.
return "test01";
}
@RequestMapping(value="/Test02.do", method=RequestMethod.GET)
public String test02() {
return "test02";
}
}
|
cs |
1) test01.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<ul>
<h1>TEST01.jsp 파일입니다.</h1>
</ul>
</body>
</html>
|
cs |
2) test02.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<ul>
<h1>TEST02.jsp 파일입니다.</h1>
</ul>
</body>
</html>
|
cs |
-----------------------------------------------------------------------------------------------------------
1. SubController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
package com.heeyeon.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class SubController {
// 메서드 정의
@RequestMapping(value = "Sub/Sub01.do", method = RequestMethod.GET)
public String subTest01() {
return "sub/sub01";
}
@RequestMapping(value = "Sub/Sub02.do", method = RequestMethod.GET)
public String subTest02() {
return "sub/sub02";
}
}
|
cs |
1) sub01.jsp
1
2
3
4
5
6
7
8
9
10
11
12
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>sub01.jsp파일입니다.</h1>
</body>
</html>
|
cs |
2) sub02.jsp
1
2
3
4
5
6
7
8
9
10
11
12
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>sub02.jsp파일입니다.</h1>
</body>
</html>
|
cs |
-----------------------------------------------------------------------------------------------------------
1. SubController02.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
package com.heeyeon.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/Sub02")
public class SubController02 {
@RequestMapping(value="/Sub03.do",method = RequestMethod.GET)
public String Sub03() {
return "sub02/sub03";
}
@RequestMapping(value="/Sub04.do",method = RequestMethod.GET)
public String Sub04() {
return "sub02/sub04";
}
}
|
cs |
1) sub03.jsp
1
2
3
4
5
6
7
8
9
10
11
12
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>sub03.jsp입니다.</h1>
</body>
</html>
|
cs |
2) sub04.jsp
1
2
3
4
5
6
7
8
9
10
11
12
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>sub04.jsp입니다.</h1>
</body>
</html>
|
cs |
------------------------------------------------------------------------
-> index.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- <h1>HELLO SPRINGMVC JAVA</h1> -->
<!-- <img src="images/spring.png"> -->
<li><a href="Test01.do">test01</a></li>
<li><a href="Test02.do">test02</a></li>
<li><a href="Sub/Sub01.do">sub01</a></li>
<li><a href="Sub/Sub02.do">sub02</a></li>
<li><a href="Sub02/Sub03.do">sub03</a></li>
<li><a href="Sub02/Sub04.do">sub04</a></li>
</body>
</html>
|
cs |
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
결과 화면