基于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版本 持久化 ...
随机推荐
- 「SOL」E-Lite (Ural Championship 2013)
为什么这数据能水到可以枚举角度 ac 啊 # 题面 给你 \(n\) 个平面向量 \((x_i,y_i)\),对于每个 \(k=1\sim n\),求「从给出的 \(n\) 个向量中不重复地选择 \( ...
- Git、GitHub、GitLab三者之间的区别
1.Git Git是一个版本控制系统. 版本控制是一种用于记录一个或多个文件内容变化,方便我们查阅特定版本修订情况的系统. 总结: (1)分布式版本控制系统下的本地仓库包含代码库还有历史库,在本地就可 ...
- tomcat 重启脚本
1 创建脚本后将脚本放到tomcat/bin目录下并授权,就可以通过此脚本一键重启拉! #!/bin/bash tomcat_path1="$( cd "$( dirname &q ...
- 一招彻底解决——双系统下windows时间错误显示
双系统下windows与ubuntu系统时间不同步 我的笔电是windows系统,工作需要安装了ubuntu,于是成为双系统,于是从18年我就遇到了装了ubuntu系统之后windows时间显示错误的 ...
- 项目引入fastclick 导致ios中input需要多次点击才能触发focus
main.js中引入之后的修改 import FastClick from "fastclick"; FastClick.prototype.focus = function (t ...
- Alibaba Cloud Linux 3.2104 64位安装nginx-1.16.1
1 下载nginx 从nginx官网 http://nginx.org/ 下载新的稳定版本nginx 并上传到linux服务器 2 安装nginx 所需要的扩展 yum -y install ...
- hdu: Dire Wolf(区间DP)
Problem DescriptionDire wolves, also known as Dark wolves, are extraordinarily large and powerful wo ...
- 《JavaScript高级程序设计》Chapter03 JavaScript语言基础
目录 Syntax Variable var let const Data Type Undefined Null Boolean Number String Symbol Object Operat ...
- Vue学习day1
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title&g ...
- SQL Server 分页问题
------------- SQL Server 1.使用row_number分页 declare @PageSize int = 5 declare @PageIndex int = 1 selec ...