У меня есть эта сущность, которая содержит список объектов (пропущенные методы получения и установки и весь несоответствующий код для этого примера)
public class SampleType {
@OneToMany
List<SampleTypeTime> sampleTypeTimes = new ArrayList<SampleTypeTime>();
}
public class SampleTypeTime {
@DateTimeFormat(iso = ISO.TIME)
LocalTime time;
}
И у меня есть эта форма, которая позволяет пользователю выбирать несколько часов ..
<form th:object="${sampleType}" th:method="POST" th:action="@{#}">
<select th:field="*{sampleTypeTimes}" type="time" class="form-control" multiple>
<option th:value="00:00" th:text="${"00:00"}"></option>
<option th:value="01:00" th:text="${"01:00"}"></option>
... and so on
</select>
</form>
Мой контроллер:
@PostMapping("sampletype/")
public String productsTypesPost(@ModelAttribute SampleType sampleType, Model model) {
sampleTypeRepository.save(sampleType);
return "sampletype";
}
Когда я отправляю форму, я получаю следующее сообщение об ошибке:
Field error in object 'sampleType' on field 'sampleTypeTimes': rejected value [00:00,02:00];
codes [typeMismatch.sampleType.sampleTypeTimes,typeMismatch.sampleTypeTimes,typeMismatch.java.util.List,typeMismatch];
arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [sampleType.sampleTypeTimes,sampleTypeTimes];
arguments []; default message [sampleTypeTimes]]; default message [Failed to convert property value of type 'java.lang.String[]' to required type 'java.util.List' for property 'sampleTypeTimes';
nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'com.example.project.SampleTypeTime' for property 'sampleTypeTimes[0]': no matching editors or conversion strategy found]
Мне кажется, что это затрудняет преобразование Строка [] в список, как я могу обойти это?
Редактировать: добавлен класс контроллера