日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

springboot2整合mysql5_SpringBoot2整合SSM框架详解

發布時間:2024/7/19 数据库 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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框架详解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。