网站浏览记录怎么做/郑州网站建设推广
文章目录
- Structure
- MyBatis++ Controller Abilities
- Configure Plugins and Repositories
- Apply Plugins and Add Dependencies
- MyBatis++ Spring Properties
- MyBatis++ Application
- MyBatis++ Beans
- MyBatis++ Mapper
- MyBatis++ Query Builder
Structure
this blog introduce 3 ways using mybatis
-
based on annotationed SQL and Query interfaces : suppored by MyBatis framework
-
based on Query Wrapper : supported by MyBatis Plus framework
MyBatis Plus provides a easier way to dynamically set condition and updated fields
-
base on Query Condition : combined MyBatis Plus and Kotlin, so called MyBatis++
MyBatis++ provides a more easier way to build complicated conditions
and supports update values through an Example bean
MyBatis++ Controller Abilities
this controller present multiple ways to do CURD with MyBatis++
you can choose your favorite ones or those match your current project most comfortably
package x.spring.hello.controllerimport org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController
import x.kotlin.commons.serialize.JSON.toJson
import x.kotlin.commons.serialize.JSON.toJsonOrNull
import x.kotlin.commons.string.UUID
import x.spring.hello.model.User
import x.spring.hello.model.UserExample
import x.spring.hello.repository.UserMapper
import x.spring.hello.mybatis.*@RestController
class UserController {@Autowiredprivate lateinit var userMapper: UserMapper@GetMapping("/01")fun selectAll(): String {val userList = userMapper.selectAll()return userList.toJson()}@GetMapping("/02")fun selectByName(): String {val user = userMapper.selectUserByName("Jimmy")return user.toJsonOrNull().orEmpty()}@GetMapping("/03")fun selectByCondition(): String {val condition = condition { it.eq(User::name, "Jimmy") }val users = userMapper.selectList(condition.build())return users.toJson()}@GetMapping("/04")fun insert(): String {val user = User()user.name = UUID.short()userMapper.insert(user)return user.toJson()}@GetMapping("/05")fun insertOrUpdate(): String {val user = User()user.id = "1"user.name = UUID.short()userMapper.insertOrUpdate(user)return user.toJson()}@GetMapping("/06")fun updateByCondition(): String {val cond1 = condition { it.isNotNull(User::id) }val cond2 = condition { it.eq(User::name, "Jimmy") }val cond3 = condition { it.gt(User::age, 15) }val cond4 = condition {it.set(User::name, "Jimmy")it.set(User::age, 18)}val condition = cond1 and cond2 and cond3 attributes cond4val count = userMapper.update(condition.build())return count.toJson()}@GetMapping("/07")fun updateByEntityAndCondition(): String {val entity = User()entity.name = "Updated"entity.age = 36val cond1 = condition { it.isNotNull(User::id) }val cond2 = condition { it.like(User::name, "Jimmy") }val cond3 = condition { it.gt(User::age, 35) }val condition = cond1 and (cond2 or cond3)val count = userMapper.update(entity, condition.build())return count.toJson()}@GetMapping("/08")fun updateByExampleAndCondition(): String {val example = UserExample()example.age = 18val cond1 = condition { it.isNotNull(User::id) }val cond2 = condition { it.like(User::name, "Jimmy") }val cond3 = condition { it.gt(User::age, 35) }val condition = cond1 and (cond2 or cond3) values exampleval count = userMapper.update(condition.build())return count.toJson()}@GetMapping("/09")fun selectCrossTables(): String {val userRoles = userMapper.selectUserRole()return userRoles.toJson()}
}
Configure Plugins and Repositories
pluginManagement {repositories {gradlePluginPortal()google()mavenCentral()}
}dependencyResolutionManagement {repositoriesMode = RepositoriesMode.PREFER_SETTINGSrepositories {gradlePluginPortal()google()mavenCentral()}
}buildscript {repositories {gradlePluginPortal()google()mavenCentral()}
}plugins {id("org.jetbrains.kotlin.jvm") version "2.0.21" apply falseid("org.jetbrains.kotlin.kapt") version "2.0.21" apply falseid("org.jetbrains.kotlin.plugin.spring") version "2.0.21" apply falseid("org.springframework.boot") version "3.4.1" apply false
}include("spring-mybatis")
Apply Plugins and Add Dependencies
plugins {id("org.jetbrains.kotlin.jvm")id("org.jetbrains.kotlin.kapt")id("org.jetbrains.kotlin.plugin.spring")id("org.springframework.boot")
}java {toolchain {languageVersion = JavaLanguageVersion.of(17)}
}dependencies {val springBootVersion = "3.4.1"val springCloudVersion = "4.2.0"val springCloudAlibabaVersion = "2023.0.3.2"// commonsapi("io.github.hellogoogle2000:kotlin-commons:1.0.19")// kotlinapi("org.jetbrains.kotlin:kotlin-reflect:2.0.21")// springapi("org.springframework.boot:spring-boot-starter:$springBootVersion")api("org.springframework.boot:spring-boot-starter-web:$springBootVersion")api("org.springframework.cloud:spring-cloud-starter-bootstrap:$springCloudVersion")// mybatisapi("link.thingscloud:quick-spring-boot-starter-mybatis-plus:2025.01.22")
}
MyBatis++ Spring Properties
# service
server.port=10003
spring.application.name=mybatis
spring.profiles.active=dev
spring.devtools.add-properties=false
# mybatis
spring.datasource.username=root
spring.datasource.password=123456789
spring.datasource.url=jdbc:mysql://localhost:3306/dev?characterEncoding=utf-8&serverTimezone=UTC
MyBatis++ Application
package x.spring.helloimport org.mybatis.spring.annotation.MapperScan
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication@SpringBootApplication
@MapperScan(basePackages = ["x.spring.hello.repository"])
class MybatisApplicationfun main(args: Array<String>) {runApplication<MybatisApplication>(*args)
}
MyBatis++ Beans
package x.spring.hello.modelimport com.baomidou.mybatisplus.annotation.IdType
import com.baomidou.mybatisplus.annotation.TableIdclass User {@TableId(type = IdType.ASSIGN_UUID)var id = ""var name = ""var age = 0
}
package x.spring.hello.modelclass UserExample {var id: String? = nullvar name: String? = nullvar age: Int? = null
}
package x.spring.hello.modelclass UserRoleQueryResult {var name = ""var role = ""
}
MyBatis++ Mapper
mapper sometimes called interface, service or repository in other projects
package x.spring.hello.repositoryimport link.thingscloud.quick.mybatisplus.base.BaseMapper
import org.apache.ibatis.annotations.Select
import x.spring.hello.model.User
import x.spring.hello.model.UserRoleQueryResultinterface UserMapper : BaseMapper<User> {@Select("select * from user")fun selectAll(): MutableList<User>@Select("select * from user where name = #{name}")fun selectUserByName(name: String): User?@Select("""select user.name as name,role.name as role from user left join roleon user.roleId = role.id""")fun selectUserRole(): List<UserRoleQueryResult>
}
MyBatis++ Query Builder
this is the core component to build query condition and examples
difference between entity and example is :
entity will update all field, while example only update non-null fields
package x.spring.hello.mybatisimport com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper
import kotlin.reflect.KClass
import kotlin.reflect.KProperty1
import kotlin.reflect.full.memberPropertiesfun interface ConditionConfigurator<T : Any> {fun configure(wrapper: KtUpdateWrapper<T>)
}data class QueryCondition<T : Any>(val configurator: ConditionConfigurator<T>
)inline fun <reified T : Any> QueryCondition<T>.build(): KtUpdateWrapper<T> {val wrapper = KtUpdateWrapper(T::class.java)configurator.configure(wrapper)return wrapper
}inline fun <reified T : Any> condition(configurator: ConditionConfigurator<T>): QueryCondition<T> {return QueryCondition(configurator)
}infix fun <T : Any> QueryCondition<T>.and(other: QueryCondition<T>): QueryCondition<T> {val configurator = ConditionConfigurator {configurator.configure(it)it.and { other.configurator.configure(it) }}return QueryCondition(configurator)
}infix fun <T : Any> QueryCondition<T>.or(other: QueryCondition<T>): QueryCondition<T> {val configurator = ConditionConfigurator {configurator.configure(it)it.or { other.configurator.configure(it) }}return QueryCondition(configurator)
}infix fun <T : Any> QueryCondition<T>.not(other: QueryCondition<T>): QueryCondition<T> {val configurator = ConditionConfigurator {configurator.configure(it)it.not { other.configurator.configure(it) }}return QueryCondition(configurator)
}infix fun <T : Any> QueryCondition<T>.attributes(other: QueryCondition<T>): QueryCondition<T> {val configurator = ConditionConfigurator {configurator.configure(it)other.configurator.configure(it)}return QueryCondition(configurator)
}inline infix fun <reified T : Any, reified S : Any> QueryCondition<T>.values(example: S): QueryCondition<T> {val configurator = ConditionConfigurator { wrapper ->configurator.configure(wrapper)val properties = S::class.memberPropertiesproperties.forEach { propertyS ->val value = propertyS.get(example)value.takeIf { it != null } ?: return@forEachval property = T::class.findPropertyByName(propertyS.name)property.takeIf { it != null } ?: return@forEachwrapper.set(property, value)}}return QueryCondition(configurator)
}inline fun <reified T : Any> KClass<T>.findPropertyByName(name: String): KProperty1<T, *>? {return memberProperties.firstOrNull { it.name == name }
}
相关文章:

[ Spring ] Spring Boot Mybatis++ 2025
文章目录 StructureMyBatis Controller AbilitiesConfigure Plugins and RepositoriesApply Plugins and Add DependenciesMyBatis Spring PropertiesMyBatis ApplicationMyBatis BeansMyBatis MapperMyBatis Query Builder Structure this blog introduce 3 ways using mybat…...

JAVAweb学习日记(九) MySQL-事务索引
一、事务-介绍 示例代码: 二、事务-四大特性 三、索引-介绍 无索引:全表扫描(对应字段逐一比较) 有索引:根据索引结构高效获取数据 优缺点: 四、索引-结构 五、索引-操作语法...

企业加密软件(天锐绿盾)
天锐绿盾是一款功能强大的企业加密软件,以下是对其的详细介绍: 一、产品概述 天锐绿盾(又名绿盾信息安全管理软件),专注于企业数据防泄密,致力于为企业提供全方位的数据安全保障。其官网为www.drhchina.c…...

Python实现监督学习与无监督学习
在机器学习中,算法被广泛应用于解决实际问题。监督学习与无监督学习是其中两种重要的学习范式。监督学习通过已标注的数据进行训练,目标是学会预测未知数据的标签。而无监督学习不需要数据的标签,它专注于数据的结构和模式,通常用于聚类或降维等任务。 本教程的目标是帮助…...

Python网络自动化运维---批量登录设备
文章目录 目录 文章目录 前言 实验准备 一.批量登录 IP 连续的设备 1.1.1 实验代码 1.1.2 代码分段分解 1.1.3 实验结果验证 二.批量登录 IP 不连续的设备 2.2.1 实验代码 2.2.2 代码分段分解 2.2.3 实验结果验证 前言 在生产环境中,我们通常需要登录多个设备…...

如何抓取酒店列表: 揭开秘密
搜索酒店列表是一种强大的工具,可以从各种在线资源中收集有关住宿、价格和可用性的综合数据。无论您是要比较价格、分析市场趋势,还是要创建个性化的旅行计划,搜索都能让您有效地汇编所需的信息。在本文中,我们将介绍如何搜索酒店…...

day32-文件共享服务ftp与smb
文件共享服务方案有很多,了解即可 ftp(简单文件传输服务) 提供用户认证机制 可以输入账号密码 python -m SimpleHTTPServer nginx也提供了文件下载的功能 提供用户认证机制 反向代理,负载均衡 web服务器,静态文件…...

快速傅里叶离散变换FFT (更新中)
声明:参考了 y y c yyc yyc 的 blog 和 PPT (from smwc) ,以及 w z r wzr wzr 的 blog 。 目录 Part 1 多项式Part 2 FFT概论Part 3 点值与插值Part 4 复数,单位根Part 5 Part 1 多项式 定义:对于有限数列 A 0 A_{0} A0~ n…...

【从零开始入门unity游戏开发之——C#篇48】C#补充知识点——静态导入、异常捕获和异常筛选器、nameof运算符
考虑到每个人基础可能不一样,且并不是所有人都有同时做2D、3D开发的需求,所以我把 【零基础入门unity游戏开发】 分为成了C#篇、unity通用篇、unity3D篇、unity2D篇。 【C#篇】:主要讲解C#的基础语法,包括变量、数据类型、运算符、流程控制、面向对象等,适合没有编程基础的…...

8.PPT:小李-第二次世界大战【21】
目录 NO123 NO4567 NO8\9\10\11 图片→格式→大小对话框→锁定纵横比✔动画→飞入→效果选项:方向/序列→开始→持续时间→延迟时间持续时间:1s延迟:0.5s音频剪切时间:0.5s:00:00.500自动换片时间设置&…...

企业百科和品牌百科创建技巧
很多人比较困惑,创建百科词条需要注意哪些事情?为什么参考提交了权威新闻参考资料还是没有通过,下面小马识途营销顾问就为大家解答疑惑: 1、品牌词以及企业词提交 1)如果没有词条,我们可以通过平台提供的急…...

搭建集成开发环境PyCharm
1.下载安装Python(建议下载并安装3.9.x) https://www.python.org/downloads/windows/ 要注意勾选“Add Python 3.9 to PATH”复选框,表示将Python的路径增加到环境变量中 2.安装集成开发环境Pycharm http://www.jetbrains.com/pycharm/…...

【Rust自学】16.4. 通过Send和Sync trait来扩展并发
喜欢的话别忘了点赞、收藏加关注哦,对接下来的教程有兴趣的可以关注专栏。谢谢喵!(・ω・) 16.4.1. Send和Sync trait Rust语言本身的并发特性较少,目前所提及的并发特性都来自于标准库,而不是语言本身。其…...

2025年02月05日Github流行趋势
项目名称:OCRmyPDF 项目地址url:https://github.com/ocrmypdf/OCRmyPDF项目语言:Python历史star数:15872今日star数:157项目维护者:jbarlow83, fritz-hh, apps/dependabot, mawi12345, mara004项目简介&…...

拉取本地的 Docker 镜像的三种方法
方法 1:通过 docker save 和 docker load 导出和导入镜像 在本地服务器上导出镜像: 使用 docker save 将镜像保存为一个 .tar 文件: docker save -o mysql-5.7.tar mysql:5.7 将镜像文件传输到其他服务器: 你可以通过 scp 或其他…...

springboot+vue+uniapp的校园二手交易小程序
开发语言:Java框架:springbootuniappJDK版本:JDK1.8服务器:tomcat7数据库:mysql 5.7(一定要5.7版本)数据库工具:Navicat11开发软件:eclipse/myeclipse/ideaMaven包&#…...

NeetCode刷题第21天(2025.2.4)
文章目录 114 Gas Station 加油站115 Hand of Straights 顺子之手116 Merge Triplets to Form Target 将 Triplelet 合并到 Form Target117 Partition Labels 分区标签118 Valid Parenthesis String 有效的括号字符串119 Insert Interval 插入间隔120 Merge Intervals 合并区间…...

人工智能|本地部署|ollama+chatbox快速Windows10下部署(初级篇)
一、 前言: 其实早一个月我已经使用过deepseek,并且也在自己的机器上通过ollama部署过,但一直没有太多动力,现在感觉还是的记录一下,省的自己给忘掉了 本文只是简单记录一下ollamaopen-webuichatbox部署通过网盘分享…...

chrome插件模板;使用 React 18 和 Webpack 5 的 Chrome 扩展样板
一、软件介绍(文末提供下载) 这是一个基本的 Chrome 扩展样板,可帮助您编写模块化和现代的 Javascript 代码,轻松加载 CSS,并在代码更改时自动重新加载浏览器。 github地址:https://github.com/lxieyang/c…...

大语言模型极速部署:Ollama 与 One-API 完美搭建教程
大语言模型极速部署:Ollama 与 One-API 完美搭建教程 本文将介绍如何通过命令行工具部署 Ollama 和 One-API,帮助你快速搭建私有化大模型。 一、安装 Ollama Ollama 是一个容器化的应用,方便部署和管理 AI 模型。以下是安装 Ollama 的步骤。…...

【C++】STL——list底层实现
目录 💕1.list的三个类介绍 💕2.list——节点类 (ListNode) 💕3.list——链表类 (List) 💕4.list——迭代器类(重点思考)(ListIterator) 💕5…...

Java 进阶day14XML Dom4j 工厂模式 Base64
目录 知识点1、XML 概念XML约束 知识点2、XML解析 Dom4j(Dom for java)XPath 知识点3、工厂模式知识点4、Base64 知识点1、XML 概念 XML的全称为(eXtensible Markup Language),是一种可扩展的标记语言。 XML的作用&…...

100.6 AI量化面试题:如何评估AI量化模型的过拟合风险?
目录 0. 承前1. 解题思路1.1 性能验证维度1.2 统计检验维度1.3 实践验证维度 2. 样本内外性能对比2.1 基础性能指标计算2.2 策略收益对比 3. 参数敏感性分析3.1 参数网格搜索3.2 稳定性评估 4. 白噪声测试4.1 随机数据测试 5. Deflated Sharpe Ratio5.1 DSR计算 6. 交易成本敏感…...

C++模板:泛型编程的魔法钥匙
前言 本篇博客将详细介绍C的模板 💖 个人主页:熬夜写代码的小蔡 🖥 文章专栏:C 若有问题 评论区见 🎉欢迎大家点赞👍收藏⭐文章 一:引言:为什么需要模板? 1.复杂代码…...

unordered_map/set的哈希封装
【C笔记】unordered_map/set的哈希封装 🔥个人主页:大白的编程日记 🔥专栏:C笔记 文章目录 【C笔记】unordered_map/set的哈希封装前言一. 源码及框架分析二.迭代器三.operator[]四.使用哈希表封装unordered_map/set后言 前言 哈…...

机器学习专业毕设选题推荐合集 人工智能
目录 前言 毕设选题 开题指导建议 更多精选选题 选题帮助 最后 前言 大家好,这里是海浪学长毕设专题! 大四是整个大学期间最忙碌的时光,一边要忙着准备考研、考公、考教资或者实习为毕业后面临的升学就业做准备,一边要为毕业设计耗费大量精力。学长给大家整理…...

软件工程导论三级项目报告--《软件工程》课程网站
《软件工程》课程网站 摘要 本文详细介绍了《软件工程》课程网站的设计与实现方案,包括可行性分析、需求分析、总体设计、详细设计、测试用例。首先,通过可行性分析从各方面确认了该工程的可实现性,接着需求分析明确了系统的目标用户群和功能…...

物联网领域的MQTT协议,优势和应用场景
MQTT(Message Queuing Telemetry Transport)作为轻量级发布/订阅协议,凭借其低带宽消耗、低功耗与高扩展性,已成为物联网通信的事实标准。其核心优势包括:基于TCP/IP的异步通信机制、支持QoS(服务质量&…...

缓存类为啥使用 unordered_map 而不是 map
性能考虑: std::unordered_map 是基于哈希表实现的,而 std::map 是基于红黑树实现的。对于查找操作,std::unordered_map 的平均查找时间复杂度是 O ( 1 ) O(1) O(1),而 std::map 的查找时间复杂度是 O ( l o g n ) O(log n) O(l…...

产品经理的人工智能课 02 - 自然语言处理
产品经理的人工智能课 02 - 自然语言处理 1 自然语言处理是什么2 一个 NLP 算法的例子——n-gram 模型3 预处理与重要概念3.1 分词 Token3.2 词向量化表示与 Word2Vec 4 与大语言模型的交互过程参考链接 大语言模型(Large Language Models, LLMs)是自然语…...