插入后的mybatis返回值

ljo96ir5  于 2021-07-27  发布在  Java
关注(0)|答案(1)|浏览(450)

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

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

Map器:

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);

关于schema的sql schema我不确定在第一行中指定的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;

}
t40tm48m

t40tm48m1#

您需要使用下面的插入查询

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

相关问题