【发布时间】:2017-07-03 17:28:39
【问题描述】:
升级到 spring-boot-2-m2 (thymeleaf 3) 后,我收到与 JPA 关系对应的字段的转换失败错误。
Failed to convert from type [@javax.persistence.ManyToOne @javax.persistence.JoinColumn com.pps2....entities.FormType] to type [java.lang.String] for value 'com.pps2.....FormType@819841af'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.Optional<?>] to type [java.lang.String]
JPA 实体
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "id_form_type")
private FormType type;
public FormType getType() {
return type;
}
模板中的代码是:
<select th:field="*{type}" class="col-xs-12">
抛出类似的失败转换错误。
当然,直接引用时它可以工作,但在这种情况下,它会破坏项目中的许多模板。并将name 生成为type.id 而不是type。
工作示例
<select th:field="*{type.id}" class="col-xs-12">
问题 - 他们为什么要更改 API?有没有办法在不重新检查所有模板的情况下解决它(例如编写转换器?)?
【问题讨论】:
-
为什么说“Thymeleaf 转换失败”,当它是 Spring 时例外?如果是这种情况,JPA 与转换问题有什么关系?也就是调试问题出在这 3 位软件的地方
-
感谢我对 Spring 环境很陌生。