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他解析成一个高阶函数了

相关推荐
余醉 | dtminer29 分钟前
56%的保护效应藏在乳腺密度里:Nat Commun 高分中介孟德尔随机化全 R 管线拆解(附核心图)
开发语言·r语言·孟德尔随机化
2501_9339232532 分钟前
SpringCloud组件:Eureka服务注册与发现
java·开发语言·后端·spring cloud·eureka
染指11101 小时前
142.Agent-多Agent框架-通过Skills实现多Agent
开发语言·人工智能·python·langchain·agents
好好学习O(∩_∩)O1 小时前
[QT] 多线程moveToThread 和易踩的8个坑
开发语言·qt
我是人✓1 小时前
Java核心语法:作用域、循环与大数值处理
java·开发语言·后端
敲代码的乔帮主2 小时前
Python 3 现代类型标注入门
开发语言·python
‎ദ്ദിᵔ.˛.ᵔ₎2 小时前
c++11:fuction包装器
开发语言·c++
kimnoic2 小时前
Python 爬虫的原理
开发语言·python
Fluxproxy2 小时前
Python爬虫异步提速终极方案|线程池ThreadPoolExecutor实战,告别单线程慢速爬取
开发语言·爬虫·python
淡海水2 小时前
02-07-原理篇-GC暂停时间的本质
开发语言·unity·c#·gc·暂停时间