All Projects → easybest → Spring Data Mybatis

easybest / Spring Data Mybatis

Licence: apache-2.0
Simplifies the development of creating a MyBatis-based data access layer.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Spring Data Mybatis

Spring Data Examples
Examples for using Spring Data for JPA, MongoDB, Neo4j, Redis
Stars: ✭ 181 (-12.14%)
Mutual labels:  spring-data
Domt
这是一个J2EE学生宿舍管理系统, 能完成学生班级楼栋宿舍等的基本管理, 能够智能批量地分配和腾空宿舍, 能够统计打印学生和宿舍入住名单
Stars: ✭ 190 (-7.77%)
Mutual labels:  mybatis
Ebook
🔥🔥Java相关精品电子书分享100+,书籍来自网络🔥🔥
Stars: ✭ 197 (-4.37%)
Mutual labels:  mybatis
Icloud
Stars: ✭ 184 (-10.68%)
Mutual labels:  mybatis
Awesome Spring
A curated list of awesome books, tutorials, courses, and resources for the Spring framework ecosystem.
Stars: ✭ 186 (-9.71%)
Mutual labels:  spring-data
Shopping Mmall
聚焦高并发、分布式集群、微服务架构迭代的互联网电商项目(Java技术栈)
Stars: ✭ 194 (-5.83%)
Mutual labels:  mybatis
Seconds Kill
基于 Springboot + Redis + Kafka 的秒杀系统,乐观锁 + 缓存 + 限流 + 异步,TPS 从 500 优化到 3000
Stars: ✭ 180 (-12.62%)
Mutual labels:  mybatis
My Blog Layui
layui 版本的 My-Blog : A simple & beautiful blogging system implemented with spring-boot & layui & thymeleaf & mybatis My Blog 是由 SpringBoot + Layui + Mybatis + Thymeleaf 等技术实现的 Java 博客系统,页面美观、功能齐全、部署简单及完善的代码,一定会给使用者无与伦比的体验
Stars: ✭ 204 (-0.97%)
Mutual labels:  mybatis
Mybatis Plus Generator Ui
对mybatis-plus-generator进行封装,通过Web UI快速生成兼容Spring boot,mybatis-plus框架的各类业务代码
Stars: ✭ 188 (-8.74%)
Mutual labels:  mybatis
Springboot mybatisplus
SpringBoot集成MyBatisPlus
Stars: ✭ 199 (-3.4%)
Mutual labels:  mybatis
Ebook Chat App Spring Websocket Cassandra Redis Rabbitmq
Pro Java Clustering and Scalability: Building Real-Time Apps with Spring, Cassandra, Redis, WebSocket and RabbitMQ
Stars: ✭ 186 (-9.71%)
Mutual labels:  spring-data
Springcloud Miaosha
一个基于spring cloud Greenwich的简单秒杀电子商城项目,适合新人阅读。A simple spring cloud based seckill shopping mall project, suitable for young people to read. It can be used as a paper material for academic defense.
Stars: ✭ 187 (-9.22%)
Mutual labels:  mybatis
Castle Platform
Castle-Platform是一个以高性能、高扩展性为目标的java开发平台。它是spring-mvc, spring-data, spring-security, Querydsl, JPA, Redis, Mongodb, Neo4j, groovy-template, Thymeleaf, ExtJS6, dubbo, thrift的最佳实践。
Stars: ✭ 197 (-4.37%)
Mutual labels:  spring-data
Xbin Store
模仿国内知名B2C网站,实现的一个分布式B2C商城 使用Spring Boot 自动配置 Dubbox / MVC / MyBatis / Druid / Solr / Redis 等。使用Spring Cloud版本请查看
Stars: ✭ 2,140 (+938.83%)
Mutual labels:  mybatis
Learningsummary
涵盖大部分Java进阶需要掌握的知识,包括【微服务】【中间件】【缓存】【数据库优化】【搜索引擎】【分布式】等等,欢迎Star~
Stars: ✭ 201 (-2.43%)
Mutual labels:  mybatis
Spring Boot Sample
Spring-boot 集成druid数据库连接池,Spring-boot实现druid的动态数据源,Spring-boot实现定时任务schedule,spring-boot集成mybatis
Stars: ✭ 180 (-12.62%)
Mutual labels:  mybatis
Blog
每周一篇,内容精简,不咸不淡,期盼探讨。微信公众号:芋道源码【纯源码分享公众号】
Stars: ✭ 2,327 (+1029.61%)
Mutual labels:  mybatis
Spring Boot Seed
SpringBoot骨架项目,集成SpringBoot、Mybatis、Druid、Mapper、PageHelper、Redis、Shiro、Swagger2、Log4j2等技术
Stars: ✭ 204 (-0.97%)
Mutual labels:  mybatis
Kotlin Jpa Specification Dsl
This library provides a fluent DSL for querying spring data JPA repositories using spring data Specifications (i.e. the JPA Criteria API), without boilerplate code or a generated metamodel.
Stars: ✭ 203 (-1.46%)
Mutual labels:  spring-data
Demo Project
存放学习过程中的demo项目,别光fork,顺便点下⭐哦
Stars: ✭ 198 (-3.88%)
Mutual labels:  mybatis

Spring Data MyBatis

Build Status Gitter chat Maven Central License: Apache 2.0

Simplified Chinese

Documentation

Example Project

The primary goal of the Spring Data project is to make it easier to build Spring-powered applications that use data access technologies. This module deals with enhanced support for MyBatis based data access layers.

Features

  • Implementation of CRUD methods for normal Entities
  • Dynamic query generation from query method names
  • Implementation domain base classes providing basic properties
  • Support for transparent auditing (created, last changed)
  • Possibility to integrate custom repository code
  • Easy Spring integration with custom namespace
  • Support MySQL, Oracle, Sql Server, H2, PostgreSQL, etc.
  • Support SpringBoot 2.x

Getting Help

If you have any question, please record a issue to me.

Quick Start

Download the jar through Maven:

<dependency>
  <groupId>io.easybest</groupId>
  <artifactId>spring-data-mybatis</artifactId>
  <version>2.0.1.RELEASE</version>
</dependency>

The simple Spring Data Mybatis configuration with Java-Config looks like this:

@Configuration
@EnableMybatisRepositories(
        value = "org.springframework.data.mybatis.repository.sample",
        mapperLocations = "classpath*:/org/springframework/data/mybatis/repository/sample/mappers/*Mapper.xml"
)
public class TestConfig {

    @Bean
    public DataSource dataSource() throws SQLException {
        return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).addScript("classpath:/test-init.sql").build();
    }

    @Bean
    public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource) {
        SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
        factoryBean.setDataSource(dataSource);
        return factoryBean;
    }

    @Bean
    public PlatformTransactionManager transactionManager(DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }

}

Create an entity:

@Entity
@Table(name = "user")
public class User extends LongId {

  
  @Condition
  private String firstname;
  @Condition(type=Condition.Type.CONTAINING)  private String lastname;
  private String fullName;
  @Conditions({@Condition, @Condition(type=Condition.Type.CONTAINING,properties = "fuzzyName")})
  private String fullName;
  @Transient
  private String fuzzyName;
  @Column(name = "usertype")
  private String status;
  // Getters and setters
  // (Firstname, Lastname)-constructor and noargs-constructor
  // equals / hashcode
}

When using findAll method of MybatisRepository the @Condition or @Conditions annotations will work

Create a repository interface in com.example.repositories:

public interface UserRepository extends MybatisRepository<User, Long> {
  List<User> findByLastname(String lastname);  
  
  @Query("select firstname from user")
  List<String> findUsersFirstName();
  
}

Write a test client:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AppConfig.class)
public class UserRepositoryIntegrationTest {
     
  @Autowired UserRepository repository;
     
  @Test
  public void sampleTestCase() {
    User dave = new User("Dave", "Matthews");
    dave = repository.save(dave);
         
    User carter = new User("Carter", "Beauford");
    carter = repository.save(carter);
         
    List<User> result = repository.findByLastname("Matthews");
    assertThat(result.size(), is(1));
    assertThat(result, hasItem(dave));
  }
}

Use Spring Boot

add the jar through Maven:

<dependency>
    <groupId>io.easybest</groupId>
    <artifactId>spring-data-mybatis-boot-starter</artifactId>
    <version>2.0.1.RELEASE</version>
</dependency>

If you need custom Mapper, you should add property in your application.yml like this:

mybatis:
  mapper-locations: "classpath*:/mapper/**/**Mapper.xml"

And you need not to define SqlSessionFactory manually.

The full test code like this:

@SpringBootApplication
public class SpringDataMybatisSamplesApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringDataMybatisSamplesApplication.class, args);
    }

    @Bean
    public CommandLineRunner dummyCLR(ReservationRepository reservationRepository) {
        return args -> {
            Stream.of("Tom", "Jack", "Apple")
                    .forEach(name -> reservationRepository.save(new Reservation(name)));
        };
    }

}

@RepositoryRestResource // here we use RepositoryRestResource
interface ReservationRepository extends MybatisRepository<Reservation, Long> {
}

@Entity
@Table(name = "user")
class Reservation extends LongId {

    private String reservationName;

    public Reservation() {
    }

    public Reservation(String reservationName) {
        this.reservationName = reservationName;
    }

    public String getReservationName() {
        return reservationName;
    }

    @Override
    public String toString() {
        return "Reservation{" +
                "reservationName='" + reservationName + '\'' +
                '}';
    }
}

The full example you can find in https://github.com/easybest/spring-data-mybatis-samples

Contributing to Spring Data MyBatis

Here are some ways for you to get involved in the community:

  • Github is for social coding: if you want to write code, we encourage contributions through pull requests from forks of this repository.

Help me better - Donation

paypal

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].