
🍁博客主页:👉不会压弯的小飞侠
✨欢迎关注:👉点赞👍收藏⭐留言✒
✨系列专栏:SSM框架整合专栏
✨如果觉得博主的文章还不错的话,请三连支持一下博主。
🔥欢迎大佬指正,一起 学习!一起加油!

(点击直接查看) 进行学习。(点击直接查看)(点击直接查看)的代码即可。🔥需要把上篇SSM案例整合分析(详解)的代码导入SpringBoot工程中,直接把config包下的配置类全部干掉。SpringBoot的核心就是自动配置。
项目结构:

🔥导入druid依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.11</version>
</dependency>
🔥把jdbc.properties给删掉,创建application.yml配置文件
server:
port: 8080
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/springboot?serverTimezone=UTC
username: root
password: root
@Mapper@Mapper,它就会将mapper自动注入进spring容器。@MapperScan,指定要扫描(dao接口)包的路径。package com.study.dao;
import com.study.domain.Book;
import org.apache.ibatis.annotations.*;
import java.util.List;
@Mapper
public interface BookDao {
@Insert("insert into tbl_book values(null,#{type},#{name},#{description})")
public int save(Book book);
@Update("update tbl_book set type=#{type},name=#{name},description=#{description} where id=#{id}")
public int update(Book book);
@Delete("delete from tbl_book where id=#{id}")
public int delete(Integer id);
@Select("select * from tbl_book where id=#{id}")
public Book getById(Integer id);
@Select("select * from tbl_book")
public List<Book> getAll();
}
🔥编写测试类
package com.study;
import com.study.domain.Book;
import com.study.service.BookService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@SpringBootTest
public class BookTest {
@Autowired
private BookService bookService;
@Test
public void getById(){
Book byId = bookService.getById(7);
System.out.println(byId);
}
@Test
public void getAll(){
List<Book> all = bookService.getAll();
for (Book book : all) {
System.out.println(book);
}
}
}
运行测试:

🔥添加静态资源
静态资源需要放到resource下的static包中,这里就不过多描述,上篇把整个项目传入GitHub中,需要的自取。
代码不需要修改。

启动的时候就不用输入地址了。
🔥index.html
<script>
document.location.href="pages/books.html";
</script>
测试:
🔥 新增,编辑和删除功能也是正常可以使用的。
