【问题标题】:DataRepository and mybatis supportDataRepository 和 mybatis 支持
【发布时间】:2016-09-26 14:04:07
【问题描述】:

我遵循了 react-js-and-spring-data-rest 指南。

https://spring.io/blog/2015/10/28/react-js-and-spring-data-rest-part-5-security

本教程使用JPA hibernate,我很喜欢React/Api的设计,但是我不想用JPA hibernate DAO,我想用Mybatis。

有没有办法在 mybatis 中使用 spring DataRepository ?

【问题讨论】:

    标签: spring spring-data spring-data-rest


    【解决方案1】:

    据我所知,这种方式是不可能的。当然,您可以使用与 Spring Data Repositories 相差不大的MyBatis-Spring-Boot-Starter 集成。它不仅仅是 DataRepository 可以,但不是更多......例如一个映射器应该是:

    @Mapper
    public interface CityMapper {
        @Select("SELECT * FROM CITY WHERE state = #{state}")
        City findByState(@Param("state") String state);
    }
    

    然后您可以将其作为 Bean Repository 注入而无需实现:

    @Autowired
    private CityMapper cityMapper;
    

    不幸的是,您应该在您需要的实体中执行所有 Crud 操作...这可能很乏味,因此在 Spring Data 的 de Data Repositories 中不需要。

    例子在MyBatis Reference Documentation,比这里解释得更多。

    【讨论】:

    • spring 数据仓库的优势在于一套工具可以帮助你管理一个rest api (spring-hateoas)。所以就没有办法了吗?我见过一些自制的 spring-mybatis-data 项目,但不是社区高级水平
    • 不,据我所知,在MyBatis 中,您应该手动实现所有这些有用的工具......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-13
    • 1970-01-01
    • 1970-01-01
    • 2013-10-03
    • 1970-01-01
    相关资源
    最近更新 更多