springboot2整合mysql5_SpringBoot2整合SSM框架详解
SpringBoot2整合SSM框架详解
发布时间:2019-01-15 21:33,
浏览次数:1218
, 标签:
SpringBoot
SSM
<>开发环境
* 开发工具:Eclipse + STS插件
* JDK版本:9.0.4
* MySQL版本:8.0.12
* Spring Boot版本:2.1.2
<>1、创建Spring Boot工程
<> (1)工程创建过程
<> (2)工程目录结构
注:工程创建完成后,缺少的文件夹需手动补全。
<> (3)添加额外依赖工程
所依赖的jar包和插件由工程创建过程中所选的组件自动生成。由于本工程需要用到JSP视图,需要在pom.xml中手动添加额外依赖:
org.apache.tomcat.embed
tomcat-embed-jasper
javax.servletjstl
dependency>
<> (4)配置application.yml文件
注:Spring Boot工程默认的配置文件为application.properties,可选中配置文件,单击鼠标右键,选中Convert
.properties to .yaml后,转为application.yml文件。
<>application.yml:
#服务器配置 server: port: 8090 #spring配置 spring: #数据源配置 datasource: #配置mysql数据库
driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql:
//localhost/customer_manager?serverTimezone=CTT username: root password: 1314
#配置dbcp连接池 dbcp2: connection-init-sqls: characterEncoding=utf-8 initial-size: 5
max-idle: 100 max-wait-millis: 10000 min-idle: 5 test-on-borrow: true
test-while-idle: true time-between-eviction-runs-millis: 27800 #配置JSP视图 mvc:
view: prefix: /WEB-INF/jsp/ suffix: .jsp #配置mybatis框架 mybatis: #定义Mapper接口映射文件位置
mapper-locations: classpath:mapper/*.xml #定义实体类位置 type-aliases-package:
com.ming.ssm.pojo#控制台打印sql语句 logging: level: com.ming.ssm.mapper: debug
<>2、持久层实现
<>customer_manager数据库中customer表的构建:
<>Customer:
package com.ming.ssm.pojo; import java.io.Serializable; /** *
数据库(customer_manager)中表(customer)所对应的实体类(Customer) * @author Mr.F * */ public
class Customer implements Serializable{ private static final long
serialVersionUID= 1L; private Long c_id; private String c_name; private String
c_password; private String c_address; private String c_phone; private String
c_email; public Long getC_id() { return c_id; } public void setC_id(Long c_id) {
this.c_id = c_id; } public String getC_name() { return c_name; } public void
setC_name(String c_name) { this.c_name = c_name; } public String getC_password()
{ return c_password; } public void setC_password(String c_password) { this.
c_password= c_password; } public String getC_address() { return c_address; }
public void setC_address(String c_address) { this.c_address = c_address; }
public String getC_phone() { return c_phone; } public void setC_phone(String
c_phone) { this.c_phone = c_phone; } public String getC_email() { return c_email
; } public void setC_email(String c_email) { this.c_email = c_email; } }
<>CustomerMapper:
package com.ming.ssm.mapper; import java.util.List; import org.apache.ibatis.
annotations.Mapper; import com.ming.ssm.pojo.Customer; /** *
持久层实现Mybatis框架中的Mapper接口,声名对数据库的操作方法 * @author Mr.F * */ @Mapper public
interface CustomerMapper { List findAllCustomer(); //查询所有客户信息 }
<>CustomerMapper.xml:
<?xml version="1.0" encoding="UTF-8"?> /p>
"-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
namespace="com.ming.ssm.mapper.CustomerMapper">
SELECT * FROM `customer`
<>3、业务层实现
<>CustomerService:
package com.ming.ssm.service; import java.util.List; import com.ming.ssm.pojo.
Customer; /** * 定义业务层接口 * @author Mr.F * */ public interface CustomerService {
List findAllCustomer(); //查询所有客户信息 }
<>CustomerServiceImpl:
package com.ming.ssm.service.impl; import java.util.List; import org.
springframework.beans.factory.annotation.Autowired; import org.springframework.
stereotype.Service; import com.ming.ssm.mapper.CustomerMapper; import com.ming.
ssm.pojo.Customer; import com.ming.ssm.service.CustomerService; /** *
实现业务层的CustomerService接口 * @author Mr.F * */ @Service public class
CustomerServiceImpl implements CustomerService{ @Autowired private
CustomerMapper customerMapper; @Override public List findAllCustomer()
{ return customerMapper.findAllCustomer(); } }
<>4、控制层实现
<>CustomerController:
package com.ming.ssm.controller; import java.util.List; import org.
springframework.beans.factory.annotation.Autowired; import org.springframework.
stereotype.Controller; import org.springframework.ui.Model; import org.
springframework.web.bind.annotation.RequestMapping; import com.ming.ssm.pojo.
Customer; import com.ming.ssm.service.CustomerService; /** * 定义控制层类 * @author
Mr.F * */ @Controller public class CustomerController { @Autowired private
CustomerService customerService; @RequestMapping("findAll") public String
findAll(Model model) { List list = customerService.findAllCustomer();
model.addAttribute("list", list); return "index"; } }
<>index.jsp:
pageEncoding="UTF-8"%>
prefix="c"%>/p>
"http://www.w3.org/TR/html4/loose.dtd">
客户管理页面
客户管理系统
客户ID | 客户姓名 | 客户密码 |
客户地址
td> |
客户手机 | 客户邮箱 |
align="center">
${c.c_id} ${c.c_name} ${c.c_password}${c.c_address } ${c.c_phone } ${c.c_email }
c:forEach>
<>5、工程测试
在该工程下找到Spring Boot入口类:SpringbootCustomerApplication.java,单击鼠标右键,选中Run As
-->Spring Boot App运行。在浏览器地址栏访问http://localhost:8090/findAll,其结果如下:
springboot2整合mysql5_SpringBoot2整合SSM框架详解相关推荐
- Spring+SpringMVC+Mybatis SSM框架详解
一.JDBC编程 1.JDBC 简介 JDBC其实就是 Java 官方提供的一套规范(接口),用于帮助开发人员快速实现不同关系型数据库的连接. 程序运行的时候,数据都是在内存中的.当程序终止的时候,通 ...
- ssm学习之ssm框架详解
此文章转载:https://blog.csdn.net/khxu666/article/details/79913151 Java Web常见的三层结构 表现层:也就是Web层,常见的框架有Sprin ...
- java ssm框架详解_Java的SSM框架怎样才算真正掌握?
谢邀 理解并可以根据下面这个图写出代码,你就算掌握了. 第一步:用户发起请求到前端控制器(DispatcherServlet) 第二步:前端控制器请求处理器映射器(HandlerMappering)去 ...
- (转) shiro权限框架详解06-shiro与web项目整合(上)
http://blog.csdn.net/facekbook/article/details/54947730 shiro和web项目整合,实现类似真实项目的应用 本文中使用的项目架构是springM ...
- jQuery Validate表单验证框架详解
jQuery表单验证框架总结 jQuery Validate验证框架详解 jQuery校验官网地址:bassistance.de » jQuery plugin: Validation 一.导入js库 ...
- jQuery Validate验证框架详解
2019独角兽企业重金招聘Python工程师标准>>> 一.导入js库 <script type="text/javascript" src="& ...
- shiro放行_Shiro框架详解 tagline
部分面试资料链接:https://pan.baidu.com/s/1qDb2YoCopCHoQXH15jiLhA 密码:jsam 想获得全部面试必看资料,关注公众号,大家可以在公众号后台回复" ...
- [Cocoa]深入浅出 Cocoa 之 Core Data(1)- 框架详解
深入浅出 Cocoa 之 Core Data(1)- 框架详解 罗朝辉(http://blog.csdn.net/kesalin) CC 许可,转载请注明出处 Core data 是 Cocoa 中处 ...
- WebDriver自动化测试框架详解
webDriver自动化测试框架详解 一. 简介 WebDriver API相对于Selenium Remote Control API来说,虽然同样是控制浏览器,但它的编程接口更加简洁 WebDri ...
最新文章
- Java 8 失宠!开发人员向 Java 11 转移...
- 计算机视觉在生物力学和运动康复中的应用和研究
- 转:SAP 零售业POS心得分享
- spring boot 中@Mapper和@Repository的区别
- 修改Myecclipse servlet/jsp的默认模板
- vue横向树结构_vue组件横向树实现代码
- 晨读-如何打造出有效的“人脉关系”
- Matlab绘制隐式函数形成曲面的方法总结(转载)
- python毕业设计作品基于django框架 教室图书馆座位预约系统毕设成品(6)开题答辩PPT
- [原创]Base32加密解密工具
- 逃避追债?贾跃亭把法拉第未来股权转给了外甥,但他还有5套豪宅! | 焦点
- freeswitch实战六(呼叫转移)
- c语言编译笑脸,C语言快速入门——笑脸绘图程序:窗口实现
- 在线ARM仿真器知识(嵌入式系统设计师必备)
- GGS ERROR 160 Bad column index
- 用python六行代码写一个简单的键盘记录器
- 淘宝的虚拟产品怎么引?淘宝新店虚拟产品怎么引流?
- VC++ 远程控制 屏幕监控 (传说中的木马)
- 2016年度中国软件开发者白皮书正式发布(附全文下载)
- Rail 3流行插件与替换部件简介
热门文章
- 数据结构--队列Queue--循环顺序队列
- ggplot2中显示坐标轴_qplot()——ggplot2的快速绘图
- python2转python3代码_2to3 – 自动Python 2到3代码翻译 – 开发工具(Python教程)(参考资料)...
- vuedraggle choose_如何拆分员工工资条,教你一招一学就会。(五)函数CHOOSE
- 关于计算机书籍的收集与整理(一)
- python入门神图
- 缺失值处理 - 获取一段时间内所有日期的列表 - (Python、MySQL)
- 什么是document对象?如何获取文档对象上的元素?_dom对象
- 研发团队资源成本优化实践 1
- pip加速+百度镜像|清华镜像