All Projects → jeffgbutler → mybatis-kotlin-examples

jeffgbutler / mybatis-kotlin-examples

Licence: MIT license
Examples for Using MyBatis with Kotlin

Programming Languages

kotlin
9241 projects

Labels

Projects that are alternatives of or similar to mybatis-kotlin-examples

robert
基于SpringCloud的企业级微服务多租户系统、多语言的脚手架, 代码组件化、高内聚低耦合,代码简介,注释丰富容易上手,该项目包括用于开发分布式应用程序服务的必要组件,支持多应用程序访问,并使开发人员可以轻松地使用Spring Cloud编程模型来开发分布式应用程序服务。
Stars: ✭ 45 (+21.62%)
Mutual labels:  mybatis
tongyimall
高仿小米商城用户端,是Vue + SpringBoot的前后端分离项目,包括首页门户、商品分类、首页轮播、商品展示、购物车、地址管理等部分。管理端在另一个仓库。
Stars: ✭ 55 (+48.65%)
Mutual labels:  mybatis
p mybatis
mybatis深入学习代码文档以及源码解析,包含通用mapper、分页等插件的详细介绍以及使用
Stars: ✭ 22 (-40.54%)
Mutual labels:  mybatis
spring-boot-demo
SpringBoot Demo.集成统一异常处理,Swagger,Druid,Mybatis,Redis,Mongo.
Stars: ✭ 21 (-43.24%)
Mutual labels:  mybatis
mybatis-r2dbc
MyBatis R2DBC Adapter
Stars: ✭ 121 (+227.03%)
Mutual labels:  mybatis
SecKillShop
🚀基于MyBatis、SpringBoot、Redis、消息队列的高并发处理的商品秒杀项目
Stars: ✭ 25 (-32.43%)
Mutual labels:  mybatis
community
基于spring boot与mybatis搭建的社区
Stars: ✭ 18 (-51.35%)
Mutual labels:  mybatis
ncms
Java CMS engine. Host and develop multiple websites inside a single instance through the GUI and benefit from features like A/B testing, affiliate tracking tools, and a high performance template engine with CSS stylesheets processing & scripts minification.
Stars: ✭ 32 (-13.51%)
Mutual labels:  mybatis
vacomall
☀️☀️ 基于 dubbo 实现的分布式电商平台。
Stars: ✭ 42 (+13.51%)
Mutual labels:  mybatis
mee-admin
admin、cms、console 等多用途开源后台系统
Stars: ✭ 117 (+216.22%)
Mutual labels:  mybatis
Logistics-admin
SpringBoot+adminlte+maven的物流公司管理系统
Stars: ✭ 61 (+64.86%)
Mutual labels:  mybatis
javayh-platform
javayh-platform 使用Springboot2.2.6为开发脚手架,SpringCloud为云端服务框架,Nacos为注册中心、分布式配置管理中心,Oauth2协议实现统一授权,Mybatis作为持久层框架,提供了代码生成器,SQL防注入,SwaggerAPI文档,Redis 作为缓存服务等强大的功能
Stars: ✭ 32 (-13.51%)
Mutual labels:  mybatis
jdbcTemplatePlus
基于SpringJdbcTemplate的ORM框架,比Mybatis更方便,更简单,仅需定义Model就可支持各种SQL查询和动态SQL,不再用拼写XML文件和SQL语句,可以通过各种注解式插件扩展,目前主要支持Mysql数据库
Stars: ✭ 25 (-32.43%)
Mutual labels:  mybatis
springbook
java8+springMVC4+mybatis编写一个图书管理系统
Stars: ✭ 32 (-13.51%)
Mutual labels:  mybatis
gobatis
golang's ORM framework, similar to Java's Mybatis. supports direct execution of sql statements, xml, go template, and dynamic sql.
Stars: ✭ 28 (-24.32%)
Mutual labels:  mybatis
event-recommender-festa
[SI -> 오늘회, 펫프렌드 이직, 연봉 35% 상승] 내 주변지역의 이벤트와 행사를 추천해주는 서비스
Stars: ✭ 64 (+72.97%)
Mutual labels:  mybatis
multipleselect
java 结合mybatis-plus 实现非手写sql多表查询
Stars: ✭ 98 (+164.86%)
Mutual labels:  mybatis
energy-management-sys communication-sub-sys
基于DLT645-2007/DLT645-1997协议的智能电表数据采集系统。借助于高性能的网络编程框架Netty开发,系统可以和智能电表交互并把设备传上来的数据实时写进数据库(目前只支持MySQL)。
Stars: ✭ 27 (-27.03%)
Mutual labels:  mybatis
springboot-react-blog
使用 springboot 和 react 开发的博客系统
Stars: ✭ 77 (+108.11%)
Mutual labels:  mybatis
AwesomeMall
Java EE电商项目(使用SSM框架)
Stars: ✭ 29 (-21.62%)
Mutual labels:  mybatis

MyBatis Kotlin Examples

This project demonstrates use of MyBatis with the Kotlin language. This is a work in progress, and we will update as our learnings progress and/or new capabilities in MyBatis become available.

Note that in most cases we are foregoing XML and working solely with the Java API for MyBatis. Hopefully it will be clear how to translate the concepts to XML if so desired.

All the code in this project is pure Kotlin. As is typical, source code is in the /src/main/kotlin directory and test code is in /src/test/kotlin. The examples described below have associated packages in the source trees. So code for example01 is in /src/main/kotlin/example01, etc.

Using MyBatis with Kotlin

One of MyBatis' core strengths is mapping SQL result sets to an object graph. MyBatis is good at these mappings for many types of class hierarchies. MyBatis can create a deeply nested object graph and its group by function provides support for creating an object graph that avoids the need for N+1 queries. However, the implementation of this result set mapping is predicated on the idea that objects can be instantiated and later modified - and this is not strictly compatible with idiomatic Kotlin. With idiomatic Kotlin, objects are created through their constructors and are immutable after creation. The examples (especially example03 and example04) will show patterns of dealing with this.

example01 - Auto Mapping

This example shows that MyBatis is able to create simple objects (basic data types, no nested classes) with idiomatic Kotlin. The "model" classes are Kotlin data classes with a mix of nullable and non-nullable types. No special mapping is needed in MyBatis. MyBatis can auto discover class constructors in this case. The important distinction is there are no nested classes or group-by functions

example02 - Type Handlers and Advanced Auto Mapping

This example shows the use of TypeHandlers. With this example we have moved beyond simple types. We are still using immutable types, but in this case we have a non-standard type that requires a TypeHandler. Important code changes:

  1. Look in /src/main/kotlin/util/YesNoTypeHandler.kt to see how to write the type handler
  2. Look in /src/test/kotlin/example02/Example02Test.kt to see how to register the type handler

example02.oldmybatis - Type Handlers and Advanced Auto Mapping in Older MyBatis Versions

This example shows the use of classes that need TypeHandlers in older versions of MyBatis. In MyBatis versions prior to 3.5.0, MyBatis sometimes had difficulty finding constructors on classes that included types with TypeHandlers. In that case, we need to annotate the class constructor with the @AutomapConstructor annotation and also register the type handler. Important code changes:

  1. Look in /src/main/kotlin/example02/oldmybatis/Example02Model.kt to see how to annotate the class
  2. Look in /src/main/kotlin/util/YesNoTypeHandler.kt to see how to write the type handler
  3. Look in /src/test/kotlin/example02/oldmybatis/Example02Test.kt to see how to register the type handler

example03 - Nested Objects

This example shows how to write Kotlin for a class hierarchy where a class (Person in this case) has an attribute that is another class (Address in this case). With this example we can no longer use Kotlin immutable data classes because of the way that MyBatis constructs an object graph in cases like this.

example04 - Join Queries with Nested Collections

This example shows how to use MyBatis support for N+1 query mitigation. This involves creating a result map with a nested collection. Currently, this is only supported in MyBatis using XML to define the result map.

example05 - MyBatis Dynamic SQL

This example shows how to use Kotlin to interact with the "MyBatis Dynamic SQL" library. This example also shows how MyBatis Generator creates code for Kotlin.

example06 - MyBatis Dynamic SQL (Generated Values)

This example shows how to use Kotlin to interact with the "MyBatis Dynamic SQL" library when a table contains generated values. This example also shows how MyBatis Generator creates code for Kotlin.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].