繁体   English   中英

MyBatis 插入后返回值

[英]MyBatis return value after Insert

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

 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)

);

帐户 model

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})")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM