SpringBoot 整合 SSM 的步骤(基于 SSM 中的 SSM 整合案例)
创建 SpringBoot 工程,在创建工程时需要勾选 web、mysql、mybatis
导入 Druid 的坐标
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.16</version>
</dependency>

需要修改的内容如下:
Springmvc_11_page 中 config 包下的是配置类,而 SpringBoot 工程不需要这些配置类,所以这些可以直接删除
dao 包下的接口上在拷贝到 springboot_09-ssm 工程中需要在接口中添加 @Mapper 注解
BookServiceTest 测试需要改成 SpringBoot 整合 junit 的
@SpringBootTest
public class BookServiceTest {
@Autowired
private BookService bookService;
@Test
public void testGetById(){
Book book = bookService.getById(2);
System.out.println(book);
}
@Test
public void testGetAll(){
List<Book> all = bookService.getAll();
System.out.println(all);
}
}在 application.yml 配置文件中需要配置如下内容
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/ssm?serverTimezone=UTC
username: root
password: 200133
type: com.alibaba.druid.pool.DruidDataSource
在 SpringBoot 程序中是没有 webapp 目录的,那么在 SpringBoot 程序中静态资源需要放在什么位置呢?
静态资源需要放在 resources 下的 static 下,如下图所示

