Skip to content

TaylorXian/mybatis-groovy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mybatis-groovy

TOC

[[toc]]

Introduction

Write Sql In Groovy Script.

See the 中文文档 for Chinese README.

Design

Install

Spring boot
  • Maven
<dependency>
    <groupId>io.github.taylorxian</groupId>
    <artifactId>mybatis-groovy-boot-starter</artifactId>
    <version>1.0-RC</version>
</dependency>
Java App
  • Maven
<dependency>
    <groupId>io.github.taylorxian</groupId>
    <artifactId>mybatis-groovy</artifactId>
    <version>1.0-RC</version>
</dependency>

Usage

Groovy Method
@Mapper
public interface UserMapper {

    @Select("UserMapperSql#selectByCondition")
    @Lang(GroovyLangDriver.class)
    List<UserVO> selectByCondition(UserVO userVO);

}
def selectByCondition(Object parameter) {
    '''
SELECT id, name, age, addr
FROM `user`
''' + where { c ->
        if (parameter?.id) c += 'id = #{id} '
        if (parameter?.name) c += ' AND name = #{name} '
        c
    }
}
Groovy Script
@Mapper
public interface UserMapper {

    @Select("UserMapperSelectByName")
    @Lang(GroovyLangDriver.class)
    UserVO selectByName(String name);

}
'''select * from user where name = #{name}'''

Contribution