(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. STM32中遇到的一些关键字

    3.在STM32编程中遇到的一些关键字 STM32是基于RAM的架构,学习它可以是嵌入式的一个基础部分.因此对于一些关键字也必须了解,在STM32学习过程中,遇到过如下变量,对其有疑问 关键字 功能 ...

  2. python + selenium 常用公共方法封装

    selenium 环境配置及浏览器驱动的安装:https://www.cnblogs.com/gancuimian/p/16435300.html uiautomator2 常用公共方法封装见之前的帖 ...

  3. Jmeter添加Plugins Manager插件管理器后增加常用base类函数

    路径为/lib/ext/jmeter-plugins-manager-1.7.jar 放置即可打开插件管理器: 搜索Custom JMeter Functions后自动下载安装即可:

  4. AIO基本编写

    一. public class Server { //线程池 private ExecutorService executorService; //线程组 private AsynchronousCh ...

  5. 5.26 学习SSH

    1.ssh客户端是一种使用Secure Shell协议 连接到运行了ssh服务端的远程服务器上 ssh是比较可靠的,专为远程登录会话和其他网络服务提供安全性的协议 2.

  6. 微信小程序:流程/步骤流/时间轴自定义组件

    效果图: 1.首先在小程序components目录下新建一个名为step的文件夹,再建step组件名.结构如下. 直接上代码 step.wxml <view class="step&q ...

  7. 解决 vue init webpack 报错问题 报错原因是因为不能执行脚本文件。

    解决方案: 运行下面一行代码: set-ExecutionPolicy RemoteSigned 

  8. 升级openssl版本

    一.安装步骤 1.下载openssl安装包 2.编译安装 3.备份旧版本openssl 4.添加软连接 5.添加OpenSSL动态链接库并使其生效 二.下载openssl安装包 [root@local ...

  9. mitudesk的pytorch基础

    pytorch定义张量的方法和Numpy差不多 2. 标量才能对张量求导,代表其在各个方向上的偏导数,结果是一个张量 3. 在pyt中张量可以对张量求导,前提条件是求导时传一个1,1,1,1,进去,其 ...

  10. webstrom破解

    1.下载webstrom补丁 链接:https://pan.baidu.com/s/1I93J_JOlbZzkoqV4EsJlpQ       提取码:kopn       (永久有效) 2.将补丁复 ...