Cha*_*tha 1 java spring jpa spring-boot
我在spring boot repository的查询方法中使用了java.util.Date属性.但它给了我" 无法从类型java.lang.String转换为类型@ org.springframework.data.repository.query.Param java.util.Date的值'2014-11-27" 错误.我在下面提到了Entity类和Repository类的代码段.这会是什么问题?
实体类
@Column(name="date")
@Temporal(TemporalType.DATE)
private Date date;
Run Code Online (Sandbox Code Playgroud)
知识库
public interface WeatherRepository extends CrudRepository<Weather, String> {
List<Weather> findAllByDate(@Param("date") Date date);
Weather findWeatherByCity(@Param("city") String city);
Run Code Online (Sandbox Code Playgroud)
}
您可以使用参数@org.springframework.format.annotation.DateTimeFormat上的注释date来显式指定格式.在注释中,您可以使用
pattern指定任意模式(遵循SimpleDateFormat模式)iso 使用标准ISO格式之一style用于日期和时间格式的简写双字母代码(S hort/M edium/L ong/F ull/-)仅选择其中一个配置选项.
然后你可以使用任何的Date,Calendar,Long,乔达时类型或(春季4 + JDK 8)java.time类型作为你的参数类型.
| 归档时间: |
|
| 查看次数: |
2910 次 |
| 最近记录: |