
2025-05-02
form ๋ฐ์ดํฐ ํ๋ผ๋ฏธํฐ ์ ๋ฌrequired, defaultValue ์ต์
์ผ๋ก ์ ์ฐํ ์ฒ๋ฆฌ ๊ฐ๋ฅpublic class PersonDto {
private String username;
private int age;
private String addr;
// ์์ฑ์, getter, setter, toString ํฌํจ
}
@Controller
@Slf4j
@RequestMapping("/param")
public class ParameterTestController {
// ๋ค์ํ ๋ฉ์๋ ์ค์ต: @RequestParam, @RequestBody, @PathVariable, Model, RedirectAttributes ๋ฑ
// ์: @GetMapping("/p01"), @PostMapping("/p03"), @GetMapping("/page01"), ...
}
/param/page01.jsp<h1>PAGE 01</h1>
USERNAME : ${dto.username }<br/>
AGE : ${dto.age }<br/>
ADDR : ${dto.addr }<br/>
${test}<br/>
GET http://localhost:8090/param/p01?name=ํ๊ธธ๋
GET http://localhost:8090/param/page01?username=ํ๊ธธ๋&age=30&addr=์์ธ
GET http://localhost:8090/param/p08/ํ๊ธธ๋/30/์์ธ
GET http://localhost:8090/param/page05?username=ํ๊ธธ๋&age=25&addr=๋๊ตฌ
http://localhost:8090/param/p03name=ํ๊ธธ๋
http://localhost:8090/param/p04Content-Type: application/json"ํ๊ธธ๋"
GET http://localhost:8090/param/forward1
โ forward2 โ forward3 โ JSP๋ก ์ถ๋ ฅ
GET http://localhost:8090/param/redirect1
โ RedirectAttributes๋ฅผ ํตํด r1, r2 ์ฟผ๋ฆฌ์คํธ๋ง ์ ๋ฌ
โ ์ต์ข
view์์ r1, r2, r3 ์ถ๋ ฅ
@RequestParam, @PathVariable, @ModelAttribute, @RequestBody๋ ๊ฐ๊ธฐ ๋ค๋ฅธ ์ํฉ์ ์ ํฉModel๊ณผ RedirectAttributes๋ฅผ ํ์ฉํด ๋ทฐ๋ก ๋ฐ์ดํฐ ์ ๋ฌ ๊ฐ๋ฅModelAndView๋ ๋ทฐ ์ด๋ฆ๊ณผ ๋ฐ์ดํฐ๋ฅผ ํจ๊ป ์ค์ ํ๋ ๋ฐฉ์HttpServletRequest๋ ๋ณํ ์ค์ตํจRedirectAttributes๋ฅผ ๋ฐ๋์ ์ฌ์ฉํด์ผ ํจ