인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

hyunji00332681's profile image
hyunji00332681

asked

Spring MVC Part 2 - Backend Web Development Utilization Technology

Applying a converter to a view template

th:field="*{ipPort}"에서 IpPortToStringConverter가 선택된 이유

Written on

·

502

·

Edited

2

[ConverterController.java]
public String converterForm(Model model) {
    IpPort ipPort = new IpPort("127.0.0.1", 8080);
    Form form = new Form(ipPort);
    model.addAttribute("form", form);

    return "converter-form";
}

[converter-form.html]
<form th:object="${form}" th:method="post">
    th:field <input type="text" th:field="*{ipPort}"><br/>
    th:value <input type="text" th:value="*{ipPort}">
</form>

th:field가 컨버터로 IpPortToStringConverter를 선택한 이유가 궁금한데요. 추측해본 이유는 다음과 같습니다.

th:field가 value 속성을 만들 때, form.getIpPort()에 컨버터를 적용하려고 한다. 그런데, form.getIpPort()의 타입은 IpPort이다. 그래서, 컨버팅 대상은 IpPort가 되는 것이다.

String으로 컨버팅되는 이유는 <input type="text">이기 때문이다.

springmvcMVC

Answer 1

0

yh님의 프로필 이미지
yh
Instructor

안녕하세요. 도토리님

생각하신 내용이 맞습니다.

감사합니다.

hyunji00332681's profile image
hyunji00332681

asked

Ask a question