Вложенный List в обьект в Spring Thymeleaf

У меня есть обьект Product

@Table(name = "products")
data class Product(

        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        val id: Long = 0,

        @Column(name = "name")
        var name: String,

        @Column(name = "description")
        var description: String,

        @Column(name = "count")
        var count: Int,

        @Column(name = "coast")
        var coast: Int,

        @Column
        @Convert(converter = SizeConverter::class)
        val size: List<Size>?
)

И 2 http ендпоинта

 @GetMapping("/ads")
    fun ads(model: Model): String {
        model.addAttribute("product",  Product(0,"","",0,0, listOf(Size("S",0),
                Size("S",0))));

        return "addProduct"
    }

    @PostMapping("/add")
    fun add(@ModelAttribute product: Product, bindingResult: BindingResult) :String {
        println(product)
        return "Test"
    }

Я должен вернуть из таймлиф формы Product в метод add

Thymeleaf:

    <input type="text" th:field="*{name}"/>
    <input type="text" th:field="*{description}"/>
    <input type="text" th:field="*{coast}"/>
    <input type="text" th:field="*{count}"/>
    <input type="text" th:field="*{size}"/>
    <th:block th:each="person,state : *{size}">
        <input type="text" th:field="*{size[__${state.index}__].sizeName}" th:value="${person.sizeName}"/>
        <input type="text" th:field="*{size[__${state.index}__].count}" th:value="${person.count}"/>
    </th:block>
    <input type="submit" value="Send Request">
</form>

он отдает post реквест с такм телом:

name: 
description: 
coast: 0
count: 0
size[0].sizeName: S
size[0].count: 0
size[1].sizeName: S
size[1].count: 0

но уже в методе add println() получаю такой Product Product(id=0, name=, description=00, count=0, coast=0, size=null)


Ответы (0 шт):