spring @Controller

박예린·2023년 2월 20일

Controller

: 주로 사용자의 요청을 처리하고 난 후 정해진 뷰에 객체를 넘겨주는 역할

@Controller

: 전통적인 스프링의 컨트롤러. MVC에서 C에 해당하며 주로 사용자의 요청을 처리한 후 지정된 뷰에 모델 객체를 넘겨주는 역할

@RequestMapping

: ()안에 있는 경로와 컨트롤러를 이어주는(매핑) 역할

HelloController.java

package mul.cam.a;

import java.util.Date;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller		//annotation(주석문, 지시문)
public class HelloController {
	
	@RequestMapping("/hello")
	public String hello() {
		System.out.println("HelloController hello()" + new Date());
	
		return "hello"; 	//hello.jsp로 이동
	}

}

index.jsp

<%@ 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>
<%-- <%
	response.sendRedirect("/hello");
%> --%>

<a href = "hello">hello 이동</a>
</body>
</html>
profile
개발자를 꿈꾸는 귀여운 나

0개의 댓글