@RequestMapping을 클래스 수준에 줄 수 있다.

 

같은 이름 맵핑 되었을때 가는 곳?

package kh.spring.board;

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

@Controller
public class MemberController {

	@RequestMapping("test")
	public String test() {
		return "member/test";
	}
	
}
package kh.spring.board;

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

@Controller
public class BoardController {
	@RequestMapping("test")
	public String test() {
		return "board/test";
	}
	
}

 

 

컴퍼넌트 스캔을 진행해서 빈으로 만들어 수집

클라이언트 요청을 받을 수있는 곳 검사

같은 이름일 경우 에러 발생 (Ambiguous 모호한)

 

1. 같은 이름 만들지 않기

2. 또는

리쿼스트맵핑을 컨트롤러( 클래스 수준)에도 걸수 있다.

package kh.spring.board;

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

@Controller

@RequestMapping("/member/")
public class MemberController {

	@RequestMapping("test")
	public String test() {
		return "member/test";
	}
	
}


package kh.spring.board;

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

@Controller

@RequestMapping("/member/")
public class MemberController {

	@RequestMapping("test")
	public String test() {
		return "member/test";
	}
	
	@RequestMapping("signup")
	public String signup() {
		return "signup";
	}
	@RequestMapping("login")
	public String login() {
		return "member/test";
	}
	
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="C"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
</head>
<body>
	로그인 / 회원가입
	<c:choose>
		<c:when test="${!empty loginInfo}">
                     
   	${loginInfo}님 환영합니다!
	<button id="Logout">로그아웃</button>
			<script>
				$("#Logout").on("click", function() {
					location.href = "LogoutController";
				})
			</script>

		</c:when>
		<c:otherwise>
			<div class="wrapper">
				<form action=LoginController method="post">
					<table align=center border="1px" style="text-align: center">
						<tr>
							<td><b>Login</b></td>
						</tr>
						<tr>
							<td><input type="text" name="id" placeholder="Input your ID"></td>
						</tr>
						<tr>
							<td><input type="password" name="pw"
								placeholder="Input your PW"></td>
						</tr>
						<tr>
							<td><input type="submit" id="login" value="Login"> <input
								type="button" id="signup" value="Sign up"><br> <input
								type="checkbox">Remember my ID</td>
						</tr>
					</table>
				</form>
			</div>
			<script>
				$("#signup").on("click", function() {
					location.href = "signup"
				})
				$("#login").on("click", function() {
					location.href = "login"
				})
			</script>

		</c:otherwise>
	</c:choose>


</body>
</html>

+ Recent posts