Springboot+Mybatis+Druid+Maven多模块项目搭建

版权声明:转发请标明出处,谢谢! https://blog.csdn.net/Myuhua/article/details/84777069

前段时间跟大家探讨过用springboot去搭单模块分层项目,现在跟大家看一看用springboot整合mybatis搭建多项目模块。

整个项目总共分为以下几个模块:

//用来写共用部分
springbootdemo-common
//用来写持久层代码
springbootdemo-dao
//用来写业务层代码
springbootdemo-service
//可用来写展示层代码
springbootdemo-web

在springbootdemo-web模块下有springboot的application.yml配置文件,配置了数据源,mybatis的东西,此外,启动类也放在了这一层。application.yml中的配置跟单模块搭建时候基本一样,需要提醒的是,因为现在搭建的是多模块项目,除了需要理清各模块之间的依赖关系之外,还需要在springboot的启动类中配置包扫描,否则启动项目会报相关的错误。

/**
 * 启动类,配置包扫描scanBasePackages = "com.jd"
 */
@SpringBootApplication(scanBasePackages = "com.jd")
public class SpringBootStart {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootStart.class,args);
    }
}

以上是需要注意的几点。其他几部分就是把原来的层次调用改到了各个模块,通过springboot扫描com.jd包来完成相应的功能关系调用,模块之间的依赖关系都在各模块的pom中做了配置。

Springboot+Mybatis+Druid+Maven单模块项目搭建:https://blog.csdn.net/Myuhua/article/details/84258067

多模块项目搭建完整代码地址:https://github.com/Myuhua/springboot.git

大家把代码拉下来之后从com.jd.controller.StudentController的位置开始看。后期可以在上面集成更多需要用到的东西,后期我也会以这个为基点去扩展对其他东西的整合。

猜你喜欢

转载自blog.csdn.net/Myuhua/article/details/84777069