IT/development

[thyemeleaf] form ๊ฒ€์ƒ‰๊ฐ’ ์œ ์ง€

์•Œ ์ˆ˜ ์—†๋Š” ์‚ฌ์šฉ์ž 2023. 4. 26.

์ฝ”๋“œ๋กœ ๋Œ€์ฒดํ•จ

<form id="frm" action="" th:object="${userVo}" method="get">
	<input type="text" th:field="*{empNm}" name="empNm"/>
</form>

formํƒœ๊ทธ์— th:object๋กœ ์„œ๋ฒ„์—์„œ form ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์„ Vo ์ž…๋ ฅ

controller์—์„œ๋„ UserVo๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›๋„๋ก ์„ค์ •

@GetMapping(value = "list")
public Object testList(@ModelAttribute("userVo") UserVo userVo) {
    ... ์ƒ๋žต
}

๊ทธ ํ›„ ํ™”๋ฉด์˜ input๊ณผ ๊ฐ™์€ ์—˜๋ฆฌ๋จผํŠธ ํƒœ๊ทธ์— th:field="*{vo์— ๋‹ด๊ธด ํ•„๋“œ๋ช…}"์„ ์„ ์–ธํ•˜๋ฉด ๋œ๋‹ค.

๋Œ“๊ธ€