Spring MVC / Thymeleaf-하나의 입력 필드를 사용하여 두 개의 다른 테이블에 삽입하는 방법은 무엇입니까?

지지

이름 입력 필드가 있습니다.

<input th:field="*{fleet.firstName}" class="signup1" type="text" id="fname" name="fname" autofocus="" required=""/>

두 개의 테이블 / 객체 'fleet'과 'service'가 있습니다. thymeleaf가 입력 필드 당 하나의 개체 만 사용할 수 있도록 허용하는 경우 어떻게해야합니까?

두 개의 입력 th : field를 시도했지만 작동하지 않았습니다. 처럼:

<input th:field="*{fleet.firstName}" th:field="*{service.firstName}" class="signup1" type="text" id="fname" name="fname" autofocus="" required=""/>
crm86

나는 이것이 불가능하다고 생각합니다. 웹 측에서 보려는 필드의 결합으로 Thymeleaf에 대한 DTO 개체를 만들 수 있습니다. 그런 다음이를 서비스 계층의 데이터베이스 테이블로 분리합니다.

다음과 같은 것 :

옵션 1 : th : object 없음

<form th:action="@{/destination}">
      <input type="text" th:value="${service.firstName}" name="service.firstName"/>
      <input type="text" th:value="${fleet.firstName}" name="fleet.firstName"/>
      <button type="submit">Go</button>
</form>

옵션 2 :

편물

<form th:action="@{/destination}" th:object="${myThymeleafFormObject}">

public class ThymeleafForm {

    private String fleetFirstName;
    private String serviceFirstName;

    ...

}

서비스

public class MyService {

    // To avoid complexity maps the ThymeleafForm in different JPA entities 
    // Logic and repository calls
}

저장소

public class FleetServiceRepositoryJPA {    
    //Database operations for fleet table
}

public class ServiceRepositoryJPA { 
    //Database operations for service table
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관