基于springboot实现SSM整合
(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整合的更多相关文章
- idea基于springboot搭建ssm(maven)
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/liboyang71/article/det ...
- 基于springboot的SSM框架实现返回easyui-tree所需要数据
1.easyui-tree easui-tree目所需要的数据结构类型如下: [ { "children": [ { "children": [], " ...
- 基于Maven的SSM整合的web工程
此文章主要有以下几个知识点: 一.如何创建 Maven的Web 工程 二.整合SSM(Spring,SpringMvc,Mybatis),包括所有的配置文件 三.用 mybatis 逆向工程生成对应的 ...
- 基于springboot的ssm
参考该网址成功搭建: https://blog.csdn.net/liboyang71/article/details/73459909 目前有几个问题: 1.我使用application.yml配置 ...
- 开发步骤Dubbo、spring mvc、springboot、SSM整合开发步骤
一.Dubbo开发步骤: 链接:https://pan.baidu.com/s/1pMPO1kf 密码:9zaa 第一: 1.创建consumer工程2.在pom.xml文件下添加配置3.添加appl ...
- 基于IDEA实现SSM整合框架的搭建配置流程
1.创建数据库表,以员工信息表为例子: DROP TABLE IF EXISTS `em_info`; CREATE TABLE `em_info` ( `em_id` INT(50) NOT NUL ...
- 基于SpringBoot+SSM实现的Dota2资料库智能管理平台
Dota2资料库智能管理平台的设计与实现 摘 要 当今社会,游戏产业蓬勃发展,如PC端的绝地求生.坦克世界.英雄联盟,再到移动端的王者荣耀.荒野行动的火爆.都离不开科学的游戏管理系统,游戏管理系 ...
- springBoot (适合ssm)
很多小白在学ssm的时候,选用idea,网上应该有很多教程,创建maven项目,创建spring项目的都有,五花八门. 最近接触了springBoot,这个项目类型适用于ssm,还不用去创建很多文件夹 ...
- 基于maven的ssm框架整合
基于maven的ssm框架整合 第一步:通过maven建立一个web项目. 第二步:pom文件导入jar包 (1 ...
- 基于SpringBoot从零构建博客网站 - 技术选型和整合开发环境
技术选型和整合开发环境 1.技术选型 博客网站是基于SpringBoot整合其它模块而开发的,那么每个模块选择的技术如下: SpringBoot版本选择目前较新的2.1.1.RELEASE版本 持久化 ...
随机推荐
- cad图整理
UF_initialize(); tag_t ObjectTag = NULL_TAG; tag_t view_tag = NULL_TAG; UF_OBJ_disp_props_t disp_pro ...
- React整洁的代码的一些原则
1. Model is everything models are the heart of your app. If you have models separated from th rest ...
- Dos基本命令及批处理
如何操作DOS命令: 开始----运行----cmd----回车: win+R------运行----cmd----回车: 基本命令: 1.命令:color f0 color ? 寻求帮助 改变背景 ...
- Linux系统安装&VMware安装三
第十四步: 开始安装
- vue创建项目的命令
一.首先下载node环境 二.全局安装vue-cli cnpm i -g @vue/cli 这里一定要注意是vue/cli,而不是vue-cli 三.新建文件夹,打开cmd命令 1.vue creat ...
- 第16章 发布和部署应用程序(ASP.NET Core in Action, 2nd Edition)
本章包括 发布 ASP.NET Core 应用程序 在 IIS 中托管 ASP.NET Core 应用程序 自定义 ASP.NET Core 应用程序的 URL 通过捆绑和缩小优化客户端资源 到目前为 ...
- Vue3 animate.css + wowjs 官网实现滚动到对应元素位置增加动画特效
本人在Vue3中使用的是 setup语法糖 也就是 <script setup>...</ script> 在项目中install一下两个插件: yarn add animat ...
- Windows 解决teamview远程必须mstsc连接
真实原因是你的TeamViewer一直在用远程桌面的ID进行登录,所以一旦远程桌面断开,TeamViewer就无法连接了.因此我们只需要切换为服务器的TeamViewer ID即可,服务器的TeamV ...
- Calendar 获取当前月份最后一周
import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Ca ...
- (十四).CSS3中的多列布局和伸缩盒布局
1 多列布局 ① 设置给包裹元素的 CSS 属性(共 8 个属性) CSS 属性名 含义 值 column-count 设置列数 纯数字 column-width 设置列宽 长度 columns 同时 ...