SampleController.java > SPRING1

본문 바로가기

사이트 내 전체검색

뒤로가기 SPRING1

SampleController.java

페이지 정보

작성자 관리자 작성일 24-07-17 11:06 조회 1,133 댓글 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 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);

}

}


댓글목록 0

등록된 댓글이 없습니다.


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