当前位置: 首页 > 知识库问答 >
问题:

Kotlin modelMapper,Int to Float

凤经国
2023-03-14

我使用Kotlin/Springboot,并希望使用ModelMapper映射到数据类。我想将account:balance:amount:int映射到accountdto:balance:float

来自:

data class Account(
        val id: String,
        var balance: Amount
)

data class Amount(var value: Int)
data class AccountDto(
        var id: String,
        var balance: Float?)
val modelMapper = ModelMapper()

modelMapper.addMappings(object : PropertyMap<Account, AccountDto>() {
    override fun configure() {
        map(source.balance.value / 100f, destination.balance)
    }
})

但我有这样的错误:

Caused by: org.modelmapper.ConfigurationException: ModelMapper configuration errors:

1) Cannot map final type ....accounts.Account.

2) Cannot map final method ....accounts.Account.getBalance().

3) Cannot map final type ....accounts.Amount.

4) Cannot map final method ....accounts.Amount.getValue().

5) Cannot map final type ....account.dto.AccountDto.

6) Cannot map final method ....account.dto.AccountDto.getBalance().

我现在不知道。

共有1个答案

龙才俊
2023-03-14

val更改为var

data class Account(
        val id: String,
        var balance: Amount
)

 类似资料:

相关问答

相关文章

相关阅读