<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- mybatis(非继承) -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
以上依赖可以在创建子模块时选择,如图:
然后将其复制至父模块 pom
文件
测试对应的数据库文件: demo-database-create.sql
实体类(POJO): com.ljq.demo.springboot.entity.UserDO
DAO: com.ljq.demo.springboot.dao.user.UserDao
mapper: resources/mapper/usermapper.xml
Service: com.ljq.demo.springboot.service.UserService
com.ljq.demo.springboot.service.impl.UserServiceImpl
Conrtoller: com.ljq.demo.springboot.web.controller.UserController
application.yml 配置文件: demo-web/src/main/resources/application.yml
关于 yaml/yml 文件字符串换行问题: springBoot配置文件yml字符串换行问题
Spring boot Application 方法的注意事项:
com.ljq.demo.springboot.web.DemoWebApplication
需要添加以下注解:
@EnableAutoConfiguration // 开启自动配置,避免在使用 @Autowired 注解时编译器报红
@ComponentScan(basePackages = {"com.ljq.demo.springboot"}) // 指定扫描的包,避免程序运行时找不到 bean
@MapperScan("com.ljq.demo.springboot.dao") // 指定 dao 类的包名,避免程序运行时找不到 dao 类以及 mapper
一个规范的 RESTful API 一般需要对接口返回结果进行封装,具体可参考:
../demo-common/src/main/java/com/ljq/demo/springboot/common/api/ApiResult.java
其他可查看 common
模块
本次整合提交记录为:
commit 26c3445dc9aeb74437ccfb307eca6f7038dc37a8 (HEAD -> master, origin/master, origin/HEAD)
Author: junqiang.lu <flying9001@gmail.com>
Date: Tue Oct 9 20:47:57 2018 +0800
版本回退命令:
git reset --soft 26c3445dc9aeb74437ccfb307eca6f7038dc37a8