kotlin的KProperty
发表于|更新于
|浏览量:
浪子挥霍的是他的祖业,财迷葬送的却是他自己。——托·富勒
在mp中使用KtQueryWrapper时,需要如下使用:
1 | KtQueryWrapper(User::class.java).eq(User::name, "sss").eq(User::roleId, "sss2") |
这里的User::name是一个KProperty,其文档:https://kotlinlang.org/docs/reflection.html
可以使用KProperty的name属性获取到其属性名
1 | User::name.name |
当然其还有很丰富的其他属性、函数

在项目中使用其,需要先引入kotlin-reflect依赖
1 | <dependency> |
相关推荐
2022-11-03
kotlin NaN坑
发脾气的人比被发脾气的对象所受的损失更大——霍姆斯 今天发现一个坑,在代码里尝试toBigDecimal抛出了NumberFormatException debug一看,发现值为NaN 在kotlin里,这样的代码会导致NaN 1234val nan = 0.0 / 0.0nan.toBigDecimal() // java.lang.NumberFormatExceptionjava.lang.Double.isNaN(nan) // true 最重要的是NaN,不会通过 安全调用操作符?. 的判断,因为其属于有值 所以上述代码可以改为 12val nan = 0.0 / 0.0nan.takeUnless { it.isNaN() }?.toBigDecimal() // null
2022-08-17
aop注解在整个类生效
志向是天才的幼苗,经过热爱劳动的双手培育,在肥田沃土里将成长为粗壮的大树。——苏霍姆林斯基 之前写过自定义注解和AOP,但其是作用于方法上 今天用kotlin写一个作用在类上的:主要是@annotation换成@within 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647package com.ruben.simplebootimport org.aspectj.lang.ProceedingJoinPointimport org.aspectj.lang.annotation.Aroundimport org.aspectj.lang.annotation.Aspectimport org.springframework.boot.autoconfigure.SpringBootApplicationimport org.springframework.boot.runApplicationimport org.springframework.ster...
2022-08-27
kotlin延迟属性
得饶人处且饶人——曹雪芹 kotlin习惯用法见:https://www.kotlincn.net/docs/reference/idioms.html 这里试试延迟属性: https://www.kotlincn.net/docs/reference/delegated-properties.html#%E5%BB%B6%E8%BF%9F%E5%B1%9E%E6%80%A7-lazy 1234567val lazyValue: String by lazy { println("computed!") "Hello"}println(lazyValue)println(lazyValue) 运行结果: 123computed!HelloHello
2022-09-06
kotlin相关依赖
朋友间保持一定的距离,而使友谊永存——查尔卡 第一次用kt写东西的时候,没引入GAV都可以用…应该是idea集成了kt环境,到线上打包就没有了 新建了一个kotlin项目,发现需要GAV才能打包进去 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253<properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <kotlin.version>1.7.10</kotlin.version></properties...
2023-07-19
kotlin的..<运算符
此处果有可乐,我即别无所思。——林语堂 今天升级了kotlin版本1.9.0 发现了个新特性 https://kotlinlang.org/docs/whatsnew19.html#stable-operator-for-open-ended-ranges 这个是用来取代以前的until函数的 12345678fun main() { for (number in 2 until 10) { if (number % 2 == 0) { print("$number ") } } // 2 4 6 8} 现在: 12345678fun main() { for (number in 2..<10) { if (number % 2 == 0) { print("$number ") } } ...
2023-04-28
mvc导出excel报错No converter
无翼而飞者,声也。——佚名 今天导出excel报错 1No converter for [class org.springframework.core.io.ByteArrayResource] with preset Content-Type 'application/vnd.ms-excel' 代码如下: 123456789@PostMapping("exportSettle")fun export(dto: CommonDTO) { val writer = ExcelUtil.getWriter() writer.writeRow(Maps.of("key", "value"), true) response.addHeader("Content-Disposition", writer.getDisposition("test.xlsx", CharsetUtil.CHARSET_UTF_8)) response.contentTyp...

阿超
我的名字叫阿超 年龄25岁 家在北京市 职业是软件开发 每天最晚也会在八点前回家 不抽烟 酒浅尝辄止 晚上十二点上床 保证睡足八个小时 睡前写一篇博客 再做二十分钟俯卧撑暖身 然后再睡觉 基本能熟睡到天亮 像婴儿一样不留下任何疲劳和压力 就这样迎来第二天的早晨 健康检查结果也显示我很正常 我想说明我是一个不论何时都追求内心平稳的人 不拘泥于胜负 不纠结于烦恼 不树立使我夜不能寐的敌人 这就是我在这社会的生活态度
Follow Me公告
This is my Blog