kotlin使用mybatis plus lambdaQuery报错

记录一下学习kotlin中遇到的问题

报错

bash 复制代码
### Error querying database.  
Cause: org.apache.ibatis.builder.BuilderException: 
Error evaluating expression 
'ew.sqlSegment != null and ew.sqlSegment != '''. 
Cause: org.apache.ibatis.ognl.OgnlException: 
sqlSegment [org.apache.ibatis.reflection.ReflectionException: 
Error parsing property name 'querySingleAnnualIncomeBudget$lambda$2'.  Didn't start with 'is', 'get' or 'set'.]

先把我的实体类贴一下

kotlin 复制代码
data class AnnualIncomeBudget(
	@TableId(type = IdType.ASSIGN_ID)
	var id: Long? = null,

	@ApiModelProperty("年份")
	var year: @NotNull(message = "[年份]不能为空") Int? = null,

	@ApiModelProperty("年初总收入预算金额")
	var totalBudget: @NotNull(message = "[年初总收入预算金额]不能为空") BigDecimal? = null,

	@ApiModelProperty("剩余开票额度")
	var remainingBudget: @NotNull(message = "[剩余开票额度]不能为空") BigDecimal? = null,

	@ApiModelProperty("创建时间")
	var createTime: @NotNull(message = "[创建时间]不能为空") LocalDateTime? = null,

	@ApiModelProperty("更新时间")
	var updateTime: @NotNull(message = "[更新时间]不能为空") LocalDateTime? = null,
)

然后时查询, 很简单

kotlin 复制代码
override fun querySingleAnnualIncomeBudget(year: Int): AnnualIncomeBudget? {
	return getOne(
		Wrappers.lambdaQuery<AnnualIncomeBudget>()
			.eq(AnnualIncomeBudget::year, year)
	)
}

直接贴解决方案

kotlin 复制代码
override fun querySingleAnnualIncomeBudget(year: Int): AnnualIncomeBudget? {
	return getOne(
		Wrappers.query<AnnualIncomeBudget>()
			.eq(AnnualIncomeBudget::year.name, year)
	)
}

放弃lambdaQuery改用query, lambdaquery最终还是会转换成string类型

Kotlin这里AnnualIncomeBudget::year他解析成一个高阶函数了

相关推荐
ai2work2 分钟前
附录 D 速查索引与阅读指南
kotlin
ai2work2 分钟前
ch22 诊断方法论:三个真实事故的根因分析
kotlin
Lazionr7 分钟前
多态:从多种形态到运行时绑定
开发语言·c++
大黄说说24 分钟前
iOS 列表滑动卡顿:UITableView / UICollectionView 深度优化实战
开发语言
于樱花森上飞舞41 分钟前
【Redis】哨兵详解
java·开发语言·数据库·redis
Lazionr1 小时前
二叉搜索树:从树形结构到高效查找
开发语言·c++
此生决int1 小时前
深入理解C++系列(21)——异常
开发语言·c++
Kapaseker1 小时前
你有搞明白 Volatile 什么意思吗?
android·kotlin
乌暮1 小时前
Java 抽象类与接口详解:半成品图纸 vs 能力合同
java·开发语言·后端·学习
乐观的Terry1 小时前
ShipDesk 完整使用教程:从新建项目到 SSH 自动发布
开发语言