springboot+idea+maven 多模块项目搭建的详细过程(连接数据库进行测试)
创建之前项目之前 记得改一下maven 提高下载Pom速度
4.0.0 com.honor phone pom 1.0-SNAPSHOT honor-dao honor-common honor-manager org.springframework.boot spring-boot-starter-parent 2.1.7.RELEASE 1.0-SNAPSHOT 1.0-SNAPSHOT UTF-8 UTF-8 1.8 true 4.5.7 2.7.0 1.3.7 3.4.6 42.2.12 2.1.5.RELEASE 0.9.0 2.5.0 2.8.5 2.13.3 3.1.0 6.0.0 4.1.2 org.springframework.boot spring-boot-starter-web org.hibernate.validator hibernate-validator ch.qos.logback logback-classic org.springframework.boot spring-boot-starter-logging org.springframework.boot spring-boot-starter-actuator org.springframework.boot spring-boot-starter-aop org.springframework.boot spring-boot-starter-test test org.apache.logging.log4j log4j-slf4j-impl ${log4j2.version} compile org.apache.logging.log4j log4j-core ${log4j2.version} compile org.apache.logging.log4j log4j-jul ${log4j2.version} compile org.apache.logging.log4j log4j-api ${log4j2.version} compile javax.servlet javax.servlet-api 3.1.0 provided org.junit.jupiter junit-jupiter-api 5.5.0 test com.honor honor-common ${honor-common} com.honor honor-dao ${honor-dao} com.alibaba druid-spring-boot-starter 1.1.20 io.springfox springfox-swagger2 ${swagger2.version} io.springfox springfox-swagger-ui ${swagger2.version} com.baomidou mybatis-plus-boot-starter ${mybatis-plus.version} com.baomidou mybatis-plus-generator ${mybatis-plus.version} mysql mysql-connector-java runtime 8.0.13 org.springframework.data spring-data-commons ${spring-data-commons.version} io.jsonwebtoken jjwt ${jjwt.version} com.google.code.gson gson ${gson.version} net.sf.json-lib json-lib 2.4 jdk15 org.activiti activiti-engine ${activiti.version} org.mybatis mybatis org.activiti activiti-spring-boot-starter-jpa ${activiti.version} org.apache.poi poi ${poi.version} org.apache.poi poi-ooxml ${poi.version}
第二个是honor-common
phone com.honor 1.0-SNAPSHOT 4.0.0 honor-common org.projectlombok lombok com.baomidou mybatis-plus-annotation 3.1.0 compile
第三个是honor-dao的pom
phone com.honor 1.0-SNAPSHOT 4.0.0 honor-dao com.honor honor-common com.baomidou mybatis-plus-boot-starter com.baomidou mybatis-plus-generator mysql mysql-connector-java
第四个是honor-manager的
phone com.honor 1.0-SNAPSHOT 4.0.0 com.honor.manager honor-manager pom honor-manager-txn1 honor-manager-user1 honor-manager-boot com.honor honor-common com.honor honor-dao com.baomidou mybatis-plus-boot-starter org.springframework.boot spring-boot-starter-web com.honor.manager honor-manager-boot 1.0-SNAPSHOT com.honor.manager >honor-manager-txn1 1.0-SNAPSHOT com.honor.manager >honor-manager-user1 1.0-SNAPSHOT
然后 是 honor-manager-user
honor-manager com.honor.manager 1.0-SNAPSHOT 4.0.0 honor-manager-user1 org.springframework.boot spring-boot-starter-web
然后 是honor-manager-boot记得boot 要引入txn1 和user的依赖,记得要把parents 要改一下,是为honor-manager.
4.0.0 honor-manager com.honor.manager 1.0-SNAPSHOT com.honor.manager honor-manager-boot 0.0.1-SNAPSHOT honor-manager-boot DemoprojectforSpringBoot 1.8 com.honor.manager honor-manager-user1 1.0-SNAPSHOT com.honor.manager honor-manager-txn1 1.0-SNAPSHOT mysql mysql-connector-java runtime org.junit.jupiter junit-jupiter-api com.alibaba druid-spring-boot-starter org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.junit.vintage junit-vintage-engine org.junit.jupiter junit-jupiter RELEASE test org.springframework.boot spring-boot-maven-plugin
第二阶段 开始测试 首先搭建数据库,做个简单的User 表测试就行了
packagecom.honor.common.beans; importcom.baomidou.mybatisplus.annotation.IdType; importcom.baomidou.mybatisplus.annotation.TableId; importlombok.Data; importlombok.EqualsAndHashCode; importlombok.experimental.Accessors; @Data @EqualsAndHashCode(callSuper=false) @Accessors(chain=true) publicclassUser{ @TableId(type=IdType.AUTO) privateIntegerid; privateStringusername; privateStringpassword; }
第二部dao层
packagecom.honor.mapper; importcom.baomidou.mybatisplus.core.mapper.BaseMapper; importcom.honor.common.beans.User; importorg.apache.ibatis.annotations.Mapper; importjava.util.List; @Mapper publicinterfaceUserMapperextendsBaseMapper{ }
UserMapper.xml
第三部分springboot 的application 中加入扫描包的注解
@ServletComponentScan @MapperScan("com.honor.mapper")
然后编写application.yml 文件
server: port:8880 servlet: context-path:/honor-manager spring: application: name:users datasource: type:com.alibaba.druid.pool.DruidDataSource driver-class-name:com.mysql.jdbc.Driver url:jdbc:mysql://localhost:3306/eft?characterEncoding=UTF-8&serverTimezone=UTC&useSSL=true username:root password:111111 mybatis-plus: mapper-locations: -classpath*:com/honor/mapper/*.xml check-config-location:true debug:true
紧接着编写userController 进行测试一定要前缀一样!这里注意要前缀一样,要不 扫描不到
packagecom.honor.manager.controller; importcom.honor.common.beans.User; importcom.honor.mapper.UserMapper; importorg.springframework.http.MediaType; importorg.springframework.web.bind.annotation.*; importjavax.annotation.Resource; importjava.util.Map; @RestController publicclassUserController{ @Resource UserMapperuserMapper; @RequestMapping( value="/api/user", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_UTF8_VALUE ) @ResponseBody publicUserread(@RequestParamMapparams){ returnuserMapper.selectById("1"); } @GetMapping("/api/test") publicStringhello(){ return"hello"; } }
访问 http://localhost:8880/honor-manager/api/user
到此这篇关于springboot+idea+maven多模块项目搭建的详细过程(连接数据库进行测试)的文章就介绍到这了,更多相关springboot+idea+maven多模块项目搭建内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。