MyBatis在Insert之后返回值



嘿,伙计们,我是MyBatis的新手,正试图从传入的请求对象创建一个帐户,但当我尝试这样做时,它会说:

Mapper method 'com.example.modular.mappers.AccountMapper.createAccount' has an unsupported return type: class com.example.modular.model.Account

映射器:

public interface AccountMapper {
@Select("SELECT * FROM ACCOUNT WHERE id = #{id}")
Account getAccount(@Param("id") Long id);
@Options(useGeneratedKeys=true, keyProperty = "id", keyColumn="id")
@Insert("INSERT INTO ACCOUNT(customerId,country) values (#{customerId},#{country})")
Account createAccount(Account account);

Sql架构关于架构,我不确定指定id的第一行是否写得正确->目标是在插入新记录时自动增加id

CREATE TABLE IF NOT EXISTS Account
(
id  INTEGER NOT NULL GENERATED always as identity,
customerId  INTEGER,
country  VARCHAR(22)
);

账户模型

public class Account {
@Id
private Long id;
@Column("country")
private String country;
@Column("customerId")
private Long customerId;
}

您需要使用以下插入查询

@Insert("INSERT INTO ACCOUNT(customerId,country) values (#{account.customerId},#{account.country})")

最新更新