(1)SpringBoot整合Spring(不存在)

(2)SpringBoot整合SpringMVC(不存在)

(3)SpringBoot整合MyBatis(主要)

一、新建springboot项目。

在application.yml配置文件中添加数据源信息

二、创建domain.book表对象

package com.itheima.domain;

public class Book {
private Integer id;
private String name;
private String type;
private String description; @Override
public String toString() {
return "Book{" +
"id=" + id +
", name='" + name + '\'' +
", type='" + type + '\'' +
", description='" + description + '\'' +
'}';
} public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getType() {
return type;
} public void setType(String type) {
this.type = type;
} public String getDescription() {
return description;
} public void setDescription(String description) {
this.description = description;
}
}

三、创建dao.BookDao接口,书写数据库方法

package com.itheima.dao;

import com.itheima.domain.Book;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select; @Mapper
public interface BookDao {
@Select("select * from tb_book where id = #{id}")
public Book getById(Integer id);
}

四、创建service.BookService接口,书写对应数据库方法

package com.itheima.service;

import com.itheima.domain.Book;

public interface BookService {
public Book getById(Integer id);
}

五、创建service.impl.BookServiceImpl类封装实现BookService接口方法。

package com.itheima.service.impl;

import com.itheima.dao.BookDao;
import com.itheima.domain.Book;
import com.itheima.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; @Service
public class BookServiceImpl implements BookService { @Autowired
private BookDao bookDao; @Override
public Book getById(Integer id) {
Book book = bookDao.getById(id);
return book;
}
}

六、在test中测试

package com.itheima;

import com.itheima.domain.Book;
import com.itheima.service.BookService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest
class Springboot08MybatisApplicationTests { @Autowired
private BookService bookService; @Test
void contextLoads() {
Book book = bookService.getById(12);
System.out.println(book);
} }

结果:

不用内置数据源,设置druid数据源。

在pom中添加druid依赖:

<!--        druid数据源-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.16</version>
</dependency>

基于springboot实现SSM整合的更多相关文章

  1. idea基于springboot搭建ssm(maven)

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/liboyang71/article/det ...

  2. 基于springboot的SSM框架实现返回easyui-tree所需要数据

    1.easyui-tree easui-tree目所需要的数据结构类型如下: [ { "children": [ { "children": [], " ...

  3. 基于Maven的SSM整合的web工程

    此文章主要有以下几个知识点: 一.如何创建 Maven的Web 工程 二.整合SSM(Spring,SpringMvc,Mybatis),包括所有的配置文件 三.用 mybatis 逆向工程生成对应的 ...

  4. 基于springboot的ssm

    参考该网址成功搭建: https://blog.csdn.net/liboyang71/article/details/73459909 目前有几个问题: 1.我使用application.yml配置 ...

  5. 开发步骤Dubbo、spring mvc、springboot、SSM整合开发步骤

    一.Dubbo开发步骤: 链接:https://pan.baidu.com/s/1pMPO1kf 密码:9zaa 第一: 1.创建consumer工程2.在pom.xml文件下添加配置3.添加appl ...

  6. 基于IDEA实现SSM整合框架的搭建配置流程

    1.创建数据库表,以员工信息表为例子: DROP TABLE IF EXISTS `em_info`; CREATE TABLE `em_info` ( `em_id` INT(50) NOT NUL ...

  7. 基于SpringBoot+SSM实现的Dota2资料库智能管理平台

    Dota2资料库智能管理平台的设计与实现 摘    要 当今社会,游戏产业蓬勃发展,如PC端的绝地求生.坦克世界.英雄联盟,再到移动端的王者荣耀.荒野行动的火爆.都离不开科学的游戏管理系统,游戏管理系 ...

  8. springBoot (适合ssm)

    很多小白在学ssm的时候,选用idea,网上应该有很多教程,创建maven项目,创建spring项目的都有,五花八门. 最近接触了springBoot,这个项目类型适用于ssm,还不用去创建很多文件夹 ...

  9. 基于maven的ssm框架整合

    基于maven的ssm框架整合 第一步:通过maven建立一个web项目.                第二步:pom文件导入jar包                              (1 ...

  10. 基于SpringBoot从零构建博客网站 - 技术选型和整合开发环境

    技术选型和整合开发环境 1.技术选型 博客网站是基于SpringBoot整合其它模块而开发的,那么每个模块选择的技术如下: SpringBoot版本选择目前较新的2.1.1.RELEASE版本 持久化 ...

随机推荐

  1. css如何实现(animation)跑马灯效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 20191323王予涵sort

    sort 任务 用man sort 查看sort的帮助文档 sort常用选项有哪些,都有什么功能?提交相关使用的截图 如果让你编写sort,你怎么实现?写出伪代码和相关的函数或系统调用 一.查看帮助文 ...

  3. md5加密js内容

    避免以后都得百度,直接留一份存档 /* * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message * Diges ...

  4. 解决linux时间转换为yyyy-MM-dd

    linux时间显示为:Tue Nov 30 09:33:04 CST 2021 SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd ...

  5. 第11章 配置ASP.NET Core应用程序(ASP.NET Core in Action, 2nd Edition)

    本章包括 从多个配置提供程序加载设置 安全存储敏感设置 使用强类型设置对象 在不同的宿主环境中使用不同的设置 在本书的第1部分中,您学习了ASP.NET Core应用程序启动和运行的基础知识,以及如何 ...

  6. error: You must be logged in to the server (Unauthorized) 问题处理

    故障现象: 执行kubectl 命令时: 提示"error: You must be logged in to the server (Unauthorized)" 分析: 权限问 ...

  7. 软件工程作业:个人项目—wc项目

    软件工程作业:个人项目-WC项目 项目相关要求 wc.exe 是一个常见的工具,它能统计文本文件的字符数.单词数和行数.这个项目要求写一个命令行程序,模仿已有wc.exe 的功能,并加以扩充,给出某程 ...

  8. python excel使用

    python excel使用 https://blog.csdn.net/m0_59235508/article/details/122808875 pandas不覆盖写入 https://blog. ...

  9. js计算某一天是本月的第几周

    需要实现一个小需求,计算2月24号是2月的第几周: 废话不多说,直接上代码: /** * a = d = 当前日期 * b = 6 - w = 当前周的还有几天过完(不算今天) * a + b 的和在 ...

  10. 数据库自动备份,crontab定时任务

    查看crontab运行状态service crond status 查看当前用户的crontab,输入 crontab -l: 编辑crontab,输入 crontab -e: 删除crontab,输 ...