단순 코드 기록/Spring

Spring_URLMAPPING

일일일코_장민기 2024. 2. 14. 09:56
728x90
package com.app.test;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class TestController {

	@RequestMapping(value =  {"/aaa", "/bbb"}, method = RequestMethod.GET)
	public String ab() {							
		System.out.println("login1 - loginForm - GET");	
		return "Main";
	
	}
	
	@RequestMapping(value =  {"/ccc/*"}, method = RequestMethod.GET)	//  ccc/나 ccc/*/*는 안 됨
	public String ccc() {							
		System.out.println("login1 - loginForm - GET");	
		return "Main2";
	
	}
	@RequestMapping(value =  {"/ddd/**"}, method = RequestMethod.GET)	//  ddd부터 뭘 붙여도 다됨
	public String ddd() {							
		System.out.println("login1 - loginForm - GET");	
		return "Main3";
	
	}
	
	@RequestMapping(value =  {"/eee/**/aaa"}, method = RequestMethod.GET)	//  eee로 시작해서 aaa로 끝나기만 하면 됨
	public String eee() {							
		System.out.println("login1 - loginForm - GET");	
		return "Main4";
	
	}
	
	@RequestMapping(value =  {"/fff/{userid}/fff2/{passwd}"}, method = RequestMethod.GET)	//  fff/아이디/fff2/패스워드 -> 이걸 아이디와 패스워드로 가져옴(파싱)
	public String fff(@PathVariable("userid") String userid, @PathVariable("passwd") String passwd) {							
		System.out.println("login1 - loginForm - GET");	
		System.out.println(userid+"\t"+passwd);
		return "Main5";
	
	}
	
	@RequestMapping(value =  {"/ggg"}, method = RequestMethod.GET)	//  /ggg?id=아이디값
	public String ggg (@RequestParam String id) {							
		System.out.println("login1 - loginForm - GET");	
		System.out.println(id);
		return "Main6";
	
	}
	
	
	
	
	
	
}

'단순 코드 기록 > Spring' 카테고리의 다른 글

Spring_Intercept  (0) 2024.02.14
Spring_Redirect_Forwarding  (0) 2024.02.14
Spring_Exception  (0) 2024.02.13
Spring_returnType  (0) 2024.02.13
Spring_returnType  (0) 2024.02.13