[英]How to fix 'ERROR: Incorrect DATETIME value: %%' in spring data?
I have a page that requests a list of items with a search function. 我有一个页面,请求具有搜索功能的项目列表。
I just want to point out that this code works perfectly on my work laptop and deployed on my live server but on my home laptop I get the following error: 我只是想指出,这段代码在我的工作笔记本电脑上工作得很好,并部署在我的实时服务器上,但在我的家用笔记本电脑上,我收到以下错误:
WARN SQL Error: 1525, SQLState: HY000
ERROR Incorrect DATETIME value: '%%'
I use Eclipse EE maven project(spring boot with spring data) with 1.8 java on Windows 10. MySql default dev set-up. 我在Windows 10上使用带有1.8 java的Eclipse EE maven项目(spring spring with spring data).MySql默认开发设置。 I got the same libraries on both laptops. 我在两台笔记本电脑上都有相同的库。
Repo call: 回复电话:
findAll(request, "%" + f.getSearchField() + "%");
Query: 查询:
@Query( value = "SELECT cl from ConnectionLog cl WHERE cl.user.login LIKE :search OR cl.user.firstName LIKE :search OR cl.user.lastName LIKE :search OR CONCAT( cl.user.lastName, ' ', cl.user.firstName ) LIKE :search OR CONCAT( cl.user.firstName, ' ', cl.user.lastName ) LIKE :search OR cl.lastSeen LIKE :search OR cl.browser LIKE :search OR cl.operatingSystem LIKE :search")
Page<ConnectionLog> findAll(Pageable pageable, @Param("search") String search);
The 'lastSeen' field is the DATE column. 'lastSeen'字段是DATE列。 Model: 模型:
@Column(name = "last_seen")
@Temporal(TemporalType.TIMESTAMP)
@JsonProperty
@JsonSerialize(include = Inclusion.NON_NULL)
private Date lastSeen;
How could I make this work? 我怎么能做这个工作? Why would this work on one computer and not on another? 为什么这可以在一台计算机上工作而不在另一台计
I am answering my own question because I found a solution after all. 我正在回答我自己的问题,因为我毕竟找到了解决方案。 Not sure if it's good but it works... 不确定它是否好,但它的工作原理......
I've taken out the '%' from the repo call and added to the @Query with CONCAT() and DATE_FORMAT(). 我从repo调用中取出'%'并使用CONCAT()和DATE_FORMAT()添加到@Query。
DATE_FORMAT(cl.lastSeen, '%Y %m') LIKE CONCAT('%', DATE_FORMAT(:search, '%Y %m'), '%')
Full Query: 完整查询:
@Query( value = "SELECT cl from ConnectionLog cl WHERE cl.user.login LIKE CONCAT('%', :search, '%') OR cl.user.firstName LIKE CONCAT('%', :search, '%') OR cl.user.lastName LIKE CONCAT('%', :search, '%') OR CONCAT( cl.user.lastName, ' ', cl.user.firstName ) LIKE CONCAT('%', :search, '%') OR CONCAT( cl.user.firstName, ' ', cl.user.lastName ) LIKE CONCAT('%', :search, '%') OR DATE_FORMAT(cl.lastSeen, '%Y %m') LIKE CONCAT('%', DATE_FORMAT(:search, '%Y %m'), '%') OR cl.browser LIKE CONCAT('%', :search, '%') OR cl.operatingSystem LIKE CONCAT('%', :search, '%')")
Page<ConnectionLog> findAll(Pageable pageable, @Param("search") String search);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.