SimpleController.java ( String , 변수 전달 ) > SPRING1

본문 바로가기

사이트 내 전체검색

뒤로가기 SPRING1

SimpleController.java ( String , 변수 전달 )

페이지 정보

작성자 관리자 작성일 24-07-16 16:29 조회 1,143 댓글 0

본문

package com.pkt.controller;


import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.ModelAttribute;

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


import lombok.extern.log4j.Log4j;


@Controller 

@RequestMapping("/sample/")

@Log4j

public class SampleController {


// String 이 리턴 타입일 경우

@RequestMapping("bb")

public String basic02() {

log.info("bb ............. ");


return "/sample/result";

//bb.jsp 가 아닌 result.jsp 를 찾게된다.

}


@RequestMapping("cc")

public String basic03(@ModelAttribute("msg") String msg) {

log.info("msg:"+msg); 


return "/sample/result"; //절대경로로 반환

}

}





== 실행 ==
http://localhost:8080/sample/cc?msg=hi ( 브라우저 확인 ) 

== tip == 

@ModelAttribute 애노테이션

request에 전달된 데이터를 view화면에 필요한 테이터를 추가 전달하기 위해서 사용된다.

댓글목록 0

등록된 댓글이 없습니다.


Copyright © dancePKT. All rights reserved.
PC 버전으로 보기