SampleController.java
페이지 정보
본문
package com.pkt.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import lombok.extern.log4j.Log4j;
@Controller
@RequestMapping("/sample/")
@Log4j
public class SampleController {
// 리다이렉트 해야 할 경우
@RequestMapping("ee")
public String basic05(RedirectAttributes rttr) {
log.info("ee...........");
//한 번만 전달 할 경우 addFlashAttribute()로 변수 전달해야 한다.
rttr.addFlashAttribute("msg", "메세지다~");
rttr.addAttribute("id", "1111");
return "redirect:/sample/result";
}
@RequestMapping("result")
public void doF(@ModelAttribute("msg") String msg, @ModelAttribute("id") String id) {
//msg, id 변수 전달 차이점 (브라우저 새로고침)
log.info("msg : " + msg);
log.info("id : " + id);
}
}
- 이전글③ 기초적인 컨트롤러 생성 실습 ( redirect : 페이지 이동 ) - 냉무 24.07.17
- 다음글result.jsp 24.07.17
댓글목록
등록된 댓글이 없습니다.