
jchanghong.kotlin.Anys.kt Maven / Gradle / Ivy
package jchanghong.kotlin
import cn.hutool.core.bean.BeanUtil
import cn.hutool.json.JSONObject
import java.time.LocalDate
import java.time.LocalDateTime
import java.util.*
import kotlin.reflect.KMutableProperty
import kotlin.reflect.full.memberProperties
import kotlin.reflect.jvm.javaType
/** fill null bean类*/
inline fun T.beanFillNullValues(): T {
if (this is Collection<*>) return this
val props = T::class.memberProperties
.mapNotNull { it as? KMutableProperty<*> }
for (property in props) {
if (property.call(this) != null) continue
when (property.returnType.javaType.typeName) {
"java.time.LocalDateTime" -> property.setter.call(this, LocalDateTime.now())
"java.time.LocalDate" -> property.setter.call(this, LocalDate.now())
"java.lang.Long" -> property.setter.call(this, 0L)
"java.lang.Integer" -> property.setter.call(this, 0)
"java.lang.Double" -> property.setter.call(this, 0.0)
"java.lang.String" -> property.setter.call(this, " ")
"java.util.Date" -> property.setter.call(this, Date())
"cn.hutool.json.JSONObject" -> property.setter.call(this, JSONObject())
else -> {}
}
}
return this
}
class Test2 {
var id:Int?=null
var name:String?=null
}
fun main() {
var sql = " SELECT id,name,create_time FROM table1 limit 1 offset 0"
sql=sql.replace("""(SELECT)([^&]+)(FROM)""".toRegex(),"$1 * $3")
println(sql)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy