Thymeleaf选择设置为null

时间:2018-03-30 17:00:20

标签: spring thymeleaf

我正在尝试设置成分的度量单位,但它将ID设置为null。我发送的对象是一个包含IngredientsCommand对象的包装器。

select user, room_id
from rooms_available
where date between '2018-04-02' AND '2018-04-04'
group by user, room_id
having count(*) = 3;  -- this is the number of days in the range

>

<select th:field="*{ingredientsWrapper[__${iter.index}__].unitOfMeasure}" name="unitOfMeasure.id">
   <option value="NULL"></option>
   <option th:each="unit : ${unitOfMeasureSet}"
        th:value="${unit.id}"
        th:text="${unit.unitName}">Test
   </option>
</select>

&GT;

@Getter @Setter
@NoArgsConstructor
public class IngredientsCommand {

private Long Id;
private String ingredientName;
private Long recipeId;
private BigDecimal amount;
private String countryOfOrigin;
private BigDecimal ingredientCost;
private RecipeCommand recipe;
private UnitOfMeasureCommand unitOfMeasure;
}

1 个答案:

答案 0 :(得分:0)

当它从命令转换为成分时,我没有自动连接测量单位转换器。我也从th:field="*{ingredientsWrapper[__${iter.index}__].unitOfMeasure}"更改为th:field="*{ingredientsWrapper[__${iter.index}__].unitOfMeasure.id}",现在可以使用了。谢谢你的帮助。