spring-projects / spring-data-relational

Spring Data Relational. Home of Spring Data JDBC and Spring Data R2DBC.
https://spring.io/projects/spring-data-jdbc
Apache License 2.0
764 stars 344 forks source link

Integration Mybatis with spring-data-jdbc,make mybatis can mixed with spring-data-jdbc in ONE repository [DATAJDBC-373] #598

Closed spring-projects-issues closed 4 days ago

spring-projects-issues commented 5 years ago

neil4dong opened DATAJDBC-373 and commented

Integration Mybatis with spring-data-jdbc,make mybatis can mixed with spring-data-jdbc in ONE repository by annotation with @MybatisQuery

Please check out if this way is feasible ? In my case we currently use mybatis for data access, and we are considering to migrate to spring-data-jdbc, but we have a lot of complex SQL which organized by Mybatis.

Considering the migration cost, how about use mybaitis and spring-data-jdbc together, so we can benefit form

  1. the simplicity provided form spring-data-jdbc
  2. another complex SQL solution provided by mybatis (which now only provided by QueryDsl)

Referenced from: pull request https://github.com/spring-projects/spring-data-jdbc/pull/152

spring-projects-issues commented 5 years ago

José Miguel Sanz García commented

Agree with neil4dong. Once you have MyBatis integrated to do simple statements, why not use it to it's full potential?

Anyone would argue: ok but you can use MyBatis in parallel with Spring Data JDBC to retrieve entities using complex queries. Against that I would say that it would be a lot cleaner to access MyBatis queries through DataJDBC repositories having all the code well organized instead of having both DataJDBC and MyBatis mapper classes

spring-projects-issues commented 3 years ago

Jens Schauder commented

If I understand this comment on the PR correct, there is a nice way to integrate MyBatis with Spring Data JDBC just through custom method implementations.

This sounds preferable to me than having an extra feature, that needs maintaining

samyc1201 commented 3 years ago

This is nice idea.... is this in the plan?

linghengqian commented 2 years ago

The PR involved in this issue makes me confused. Is it trying to introduce the concept of BaseMapper similar to baomidou's Mybatis Plus to directly provide additional methods for Mapper?

CuriousRookie commented 10 months ago

The PR involved in this issue makes me confused. Is it trying to introduce the concept of BaseMapper similar to baomidou's Mybatis Plus to directly provide additional methods for Mapper?

maybe like this #1312

VonChange commented 3 months ago

I implemented such functionality by custom NamedParameterTemplate

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

then you can use like this

@Query("person.selectAllRow")
List<Person> selectAllRow();

For more details, spring-data-jdbc-demo But this is more troublesome, I still hope you can support another complex SQL solution provided by mybatis you can see mybati only complex SQL solution provided No other functions

schauder commented 4 days ago

This issue started as a post hoc issue for a PR I just closed and didn't really develop in a clear direction.

Therefore closing it.