Type Date cannot be resolved to a type 解决

本文介绍在MyBatis测试代码中遇到的日期类型冲突问题。当同时引入java.util.Date和java.sql.Date时,会出现编译错误。文章提供了解决方案,即明确指定所需的日期类型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天在写mybatis测试代码,其中用到日期变量。
编写如下代码后便报错:Type Date cannot be resolved to a type。

private    Date    datetime;

后来查看到Date 在两个包中都用定义。
java.uti.Date 和 java.sql.Date。
因此,如果出现两个包中都有定义的情况下,编译器便会报如上错误。
在使用时应该加上包名。

private    java.util.Date    datetime;
Caused By: javax.faces.view.facelets.FaceletException: 检验数据查询错误,{endDate=2025-07-22, notLikeKey=T11, startDate=2025-07-16},EJBException: An exception occurred while creating a query in EntityManager: Exception Description: Problem compiling [select c.id,c.orgCode,t.old_tool_gather_no from mes.tool_check c,mes.tool_note_requests t where c.request_no=t.request_no]. [7, 11] The state field path 'c.id' cannot be resolved to a valid type. [13, 22] The state field path 'c.orgCode' cannot be resolved to a valid type. [24, 44] The state field path 't.old_tool_gather_no' cannot be resolved to a valid type. [50, 66] 'mes.tool_check c' cannot be the first declaration of the FROM clause. [99, 111] The state field path 'c.request_no' cannot be resolved to a valid type. [114, 126] The state field path 't.request_no' cannot be resolved to a valid type. at com.lkm.pmi.toolSystem.server.ToolCheckListBeanEjb.queryCheckByPage2(ToolCheckListBeanEjb.java:53) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method), /** * 查询,分页 */ public List<ToolCheckEntity> queryPage2(int first, int pageSize, Map<String, String> queryMap, Map<String, String> sortMap) { try { evictAllEm(); String querySql = getCheckAndOldToolGatherNo(); Query query = this.em.createQuery(querySql); query.setFirstResult(first); query.setMaxResults(pageSize); return query.getResultList(); } catch (Exception e) { throw new EJBException(e.getMessage()); } } private String getCheckAndOldToolGatherNo(){ String sql="select c.id,c.orgCode,t.old_tool_gather_no from mes.tool_check c,mes.tool_note_requests t \n" + "where c.request_no=t.request_no"; return sql; }报错如何解决
最新发布
07-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值