idea 中整合 SpringBoot+MyBatis -- 聚合工程
1,建父工程test_demo:删除父工程下的src文件
然后next -> finish
2,分别建子工程entity,service,dao,web
右击父工程,如图
点击Spring Initializr --> next -->
先建web
然后next
然后next-->finish
将demo_web 里 pom.xml 的jar包依赖 剪切到 父工程的pom.xml中(如图)
demo_web就建完了
之后建dao,service,entity
到这儿之后一直next->next->finish期间任何选项都不选
service,dao都如此,其中都将pom.xml中的 jar包依赖 删掉,jar包依赖 只需在 父工程的pom.xml中有就可以
3,打开父工程的pom.xml 添加
<packaging>pom</packaging>
并添加其子工程:
并添加mapper位置(以防后边找不到mapper.xml)
<!-- mapper 配置位置 --> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources>
4,分别在dao,service,entity,web中加入父工程依赖:如下图
5,分别加入依赖:dao层依赖entity(如下图); service依赖dao,entity; web依赖service,entity;entity不需要
6,在demo_web中测试搭建是否成功
在demo_web的com.test.demo_web包结构下创建一个包controller(如图)
7,添加application.properties(配置数据源,.xml文件,配置jsp)
spring.datasource.url=jdbc:mysql://localhost:3306/test1 spring.datasource.username=root spring.datasource.password=root spring.datasource.driver-class-name=com.mysql.jdbc.Driver mybatis.mapper-locations = classpath:mapper/*.xml spring.mvc.view.prefix=/WEB-INF/views/ spring.mvc.view.suffix=.jsp8,在SpringBoot的入口加上exclude= {DataSourceAutoConfiguration.class}(测试时)
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) public class DemoWebApplication { public static void main(String[] args) { SpringApplication.run(DemoWebApplication.class, args); } }
测试结果:
以上就是使用springboot搭建简单的聚合项目