Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
MyBatis Dynamic SQLの Kotlinサポートを使う
Search
Takehata Naoto
December 09, 2020
0
980
MyBatis Dynamic SQLの Kotlinサポートを使う
2020年12月9日(水) 「集まれKotlin好き!Kolint愛好会 vol.26 @オンライン」の談義資料です。
Takehata Naoto
December 09, 2020
Tweet
Share
More Decks by Takehata Naoto
See All by Takehata Naoto
組織貢献をするフリーランスエンジニアという生き方
n_takehata
2
3.4k
「2024年版 Kotlin サーバーサイドプログラミング実践開発」の補講 〜O/Rマッパー編〜
n_takehata
2
650
2024年版 Kotlin サーバーサイドプログラミング実践開発
n_takehata
7
5.6k
Server-Side目線で見る、Kotlin Festの楽しみ方
n_takehata
0
450
KotlinとCloud Vision APIで領収書の電子帳簿保存法対応をする
n_takehata
1
1.4k
KotlinConf 2023 現地参加レポート
n_takehata
1
340
サーバーサイドKotlinクイズ
n_takehata
0
210
サーバーサイドでのKotlin Coroutines
n_takehata
0
1.2k
KotlessとDynamoDBで自分のツイートを収集するサーバーレスアプリケーションを作る
n_takehata
0
430
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
46
14k
Building a Modern Day E-commerce SEO Strategy
aleyda
40
7.3k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
19
1.2k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
14
1.5k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
24
2.7k
Making the Leap to Tech Lead
cromwellryan
133
9.3k
Designing Experiences People Love
moore
142
24k
Gamification - CAS2011
davidbonilla
81
5.3k
Building Applications with DynamoDB
mza
94
6.4k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
Documentation Writing (for coders)
carmenintech
71
4.8k
Transcript
MyBatis Dynamic SQLの Kotlinサポートを使う 2020年12月9日 Kotlin愛好会 vol.26 竹端 尚人
自己紹介
概要 竹端 尚人 Twitter: @n_takehata • サーバーサイドKotlin • (少し前まで)スマートフォンゲーム開発 •
今月からフリーランス
登壇、執筆 • CEDEC 2018登壇 • CEDEC 2019登壇 • Software Design
2019年2月号〜4月号で短期連載 「サーバーサイド開発の品質を向上させる Java→Kotlin 移行のススメ」執筆
本日の内容
MyBatis Dynamic SQLのKotlinでの使い方を ライブコーディングで説明します
MyBatisとは?
• JavaのポピュラーなO/Rマッパーの一つ • もともとXMLにSQLを記述し、インターフェースとマッピング する方式 • XMLやInterface、Modelクラスなどのボイラープレートを生 成するGeneratorがある Java製のO/Rマッパー
XMLの例(抜粋) <insert id="insertSelective" parameterType="love.kotlin.server.crud.database.User" > insert into user <trim prefix="("
suffix=")" suffixOverrides=","> <if test="id != null"> id, </if> <if test="name != null"> name, </if> <if test="age != null"> age,
インターフェースの例(抜粋) @Insert({ "insert into user (id, name, " , "age)",
"values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, " , "#{age,jdbcType=INTEGER})" }) int insert(User record); int insertSelective(User record);
MyBatis Dynamyc SQL
• コード上でSQLを構築できる • こちらもGeneratorによる自動生成に対応 • Kotlinでのコードも生成可能に MyBatisで動的SQL生成のスタック
fun findAll(): List<User> { return userMapper.select { where(id, isEqualTo(1)) }
}
ここからはライブコーディングで説明します