(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. python菜鸟学习: 10. 函数的基本用法

    # -*- coding: utf-8 -*-# 回参函数def test01(): return 0# 以元组返回参数def test02(): return 1, [1, 2, 3, 4, 5], ...

  2. C# 调用https接口 安全证书问题 解决方法

    原文链接: https://blog.csdn.net/lizaijinsheng/article/details/127321758 说明: 如果是用https的话,由于没有证书,会报错:基础连接已 ...

  3. 深入理解snp-calling流程——转载

    ------------恢复内容开始------------ GATK4流程 准备配套数据 明确参考基因组版本!!!b36/b37/hg18/hg19/hg38,记住b37和hg19并不是完全一样的, ...

  4. 第三阶段Blog

    题目集7~9的总结性Blog 1.前言 一个月又过去了,又到了写blog的时候,相较于前两次Blog,这一次所要分析的内容从原先的侧重于类设计到了这次的侧重于结构设计.在完成作业的时候,尽管题目内提供 ...

  5. oracle建表和sqlserver建表

    oracle declare num number;begin select count(1) into num from user_all_tables where Upper(Table_Name ...

  6. 项目自动备份,oracle 自动备份

    1 项目备份      变量的形式 定时任务不执行就都写成了绝对路径 #!/bin/bash # # 项目路径 /usr/local/tomcat-bjkjdx 备份文件路径/usr/local/ba ...

  7. 爱心代码_HTML

    直接上效果 <!doctype html> <html> <head> <meta charset="utf-8"> <tit ...

  8. AntD为Form的List设置默认值 (antd form.list 设置默认值 )

    import React from "react"; function demo() { const FormConfig = { labelCol: { span: 8 }, w ...

  9. Vue系列---【自定义vue组件发布npm仓库】

    自定义vue组件发布npm仓库 参考链接:自定义vue组件发布npm仓库

  10. .Net 开发 web.config参数获取

    System.Configuration.ConfigurationSettings.AppSettings["title"] 对应着 web.config下面的 <conf ...