我试图用mybatis编写一个sql查询,从表中选择一堆字段,但不是全部。
表格:
CREATE TABLE metadata
(
id BIGINT PRIMARY KEY,
uuid VARCHAR(61) NOT NULL,
original_name VARCHAR(255),
file_size INTEGER NOT NULL,
width INTEGER NOT NULL,
height INTEGER NOT NULL,
file_create_date TIMESTAMP WITH TIME ZONE,
uploaded TIMESTAMP WITH TIME ZONE NOT NULL,
title VARCHAR(255),
status CHAR(1) NOT NULL DEFAULT 'I'
);
mybatisMap器:
@Select("SELECT id, uuid FROM metadata WHERE status = 'A' AND uuid = #{uuid}")
Metadata getMetadata(@Param("uuid") String uuid);
但我得到一个 No constructor found in myClass
.
我可以指示mybatis使用setter方法而不是带有输入参数的构造函数吗?
我需要这种灵活性,因为我不想在编写结果集稍有不同的新sql查询或向sql查询添加新字段时一直编写/修改构造函数。
mybatis异常:
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.apache.ibatis.executor.ExecutorException: No constructor found in com.a.b.Metadata matching [java.lang.Long, java.lang.String]
### The error may exist in com/a/b/mapper/MetadataDao.java (best guess)
### The error may involve com.a.b..mapper.MetadataDao.getMetadata
### The error occurred while handling results
### SQL: SELECT id, uuid FROM metadata WHERE status = 'A' AND uuid = ?
### Cause: org.apache.ibatis.executor.ExecutorException: No constructor found in com.a.b.Metadata matching [java.lang.Long, java.lang.String]
更新
我使用lombok生成getter/setter方法、构建器等等,所以我不想手工编写构造函数。
暂无答案!
目前还没有任何答案,快来回答吧!