4 Star 43 Fork 7

change/spring-data-jdbc-mybatis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
README.md 3.59 KB
一键复制 编辑 原始数据 按行查看 历史
change 提交于 1年前 . [new] update readme

spring-data-jdbc-mybatis

spring data jdbc extend mybatis dynamic sql

What Is This?

  • It aims at being conceptually easy. In order to achieve this it does NOT offer caching, lazy loading,QueryDSL, write behind or many other features of JPA. This makes a simple, limited, opinionated ORM.

  • use mybatis dynamic SQL(not dependency mybatis),it is good for complex SQL

  • SQL is written in Markdown

UserInfoRepository.md

-- findUserByIds
SELECT  [@id column] FROM user_base 
<where> 
[@@and id in #{idList:in} and user_name like #{userName:like}]
[@and user_name like userName%]
[@and id in idList]
<if test="null!=createTime">  and create_time < #{createTime}  </if>
</where>

see easy-dynamic-sql.md

userInfoMethodDao.findAll(UserExample.builder()
.userCodeIn(Arrays.asList("u001","u002"))
.userNameLike("ch%")
.createTimeDesc(true).build());

Features

Getting Started with JDBC mybatis

UserInfoRepository.java

public interface UserInfoRepository extends CrudExtendRepository<UserInfoDO, Long> {
    List<UserInfoDO> findByUserCodes(@Param("userCodes") List<String> userCodes);
    List<UserInfoDO> findUserBySearchParam(@Param("param") SearchParam searchParam);
}

define sql in markdown UserInfoRepository.md

need @EnableJdbcRepositories

@SpringBootApplication
@EnableJdbcRepositories
public class JdbcMybatisTestApplication {
    public static void main(String[] args) {
        SpringApplication.run(JdbcMybatisTestApplication.class, args);
    }
}

maven

<!-- spring boot 2.x -->
<dependency>
  <groupId>com.vonchange.common</groupId>
  <artifactId>spring-data-jdbc-mybatis</artifactId>
  <version>${version}</version>
</dependency>
<dependency>
       <groupId>org.springframework.data</groupId>
       <artifactId>spring-data-commons</artifactId>
 </dependency>
 <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-jdbc</artifactId>
 </dependency>

official spring data jdbc extend mybatis dynamic sql

see spring-data-jdbc-demo

configuration

@Configuration
public class MybatisQuerySupportConfig {
    @Bean
    public NamedParameterJdbcOperations namedParameterJdbcOperations(DataSource dataSource) {
        return new MybatisJdbcTemplate(dataSource) {@Override protected Dialect dialect() {return new MySQLDialect();}};
    }
}

use

    @Query("user.queryByUserCode")
    List<UserDTO> queryByUserCode(@Param("userCode") String userCode);

but SpEL support became available with Spring Data JDBC 3.0 RC1

Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/vonchange/spring-data-jdbc-mybatis.git
git@gitee.com:vonchange/spring-data-jdbc-mybatis.git
vonchange
spring-data-jdbc-mybatis
spring-data-jdbc-mybatis
master

搜索帮助