spring boot + mybatis + mysql 只有一個實體類的demo

使用MyBatis進行數據庫操作,配置簡單。主要演示了mybatis可以不用只使用方法名來對應mapper.java和mapper.xml。

目錄結構

pom.xml
src/
├── main/
│   ├── java/
│   │   └── com/
│   │       └── springbootjdbcweb/
│   │           └── springbootjdbcweb/
│   │               ├── SpringbootjdbcwebApplication.java
│   │               ├── controller/
│   │               │   └── CertificationAuditController.java
│   │               ├── mapper/
│   │               │   ├── CertificationAuditMapper.java
│   │               │   └── CertificationAuditMapper.xml
│   │               ├── pojo/
│   │               │   └── CertificationAudit.java
│   │               └── service/
│   │                   └── CertificationAuditService.java
│   └── resources/
│       ├── application.yml
│       ├── static/
│       └── templates/
│           └── login.html
└── test/└── java/└── com/└── springbootjdbcweb/└── springbootjdbcweb/└── SpringbootjdbcwebApplicationTests.java

表sql


CREATE TABLE certificationaudit (serialnumber INT PRIMARY KEY AUTO_INCREMENT COMMENT '序號',applicationnumber INT NOT NULL COMMENT '申請編號',doctorname VARCHAR(50) NOT NULL COMMENT '醫生姓名',medicalestablishment VARCHAR(100) NOT NULL COMMENT '醫療機構',specificationcenter VARCHAR(100) NOT NULL COMMENT '規范中心',phonenumber VARCHAR(20) NOT NULL COMMENT '手機號碼',controlsystem VARCHAR(255) COMMENT '管理制度',coordinatesystem VARCHAR(255) COMMENT '協調體系',heartfailurearchitecture DATETIME COMMENT '心衰架構',creationtime DATETIME NOT NULL COMMENT '創建時間',filewritepeople VARCHAR(50) NOT NULL COMMENT '填表人員',auditstatus VARCHAR(20) NOT NULL COMMENT '審核狀態',operation VARCHAR(255) COMMENT '操作'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='認證審核表';

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.5.2</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.springbootjdbcweb</groupId><artifactId>springbootjdbcweb</artifactId><version>0.0.1-SNAPSHOT</version><name>springbootjdbcweb</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version></properties><dependencies>
<!--        <dependency>-->
<!--            <groupId>org.apache.httpcomponents</groupId>-->
<!--            <artifactId>httpcore</artifactId>-->
<!--            <version>4.3.3</version>-->
<!--        </dependency>--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--通用Mapepr--><dependency><groupId>tk.mybatis</groupId><artifactId>mapper-spring-boot-starter</artifactId><version>2.0.4</version></dependency><!--分頁插件--><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId><version>1.3.0</version></dependency><!--FastJson--><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.50</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>commons-codec</groupId><artifactId>commons-codec</artifactId><version>1.15</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-javadoc-plugin</artifactId><version>3.0.0</version></plugin></plugins><resources><resource><directory>src/main/java</directory><!--所在的目錄--><includes><!--包括目錄下的.properties,.xml文件都會掃描到--><include>**/*.yml</include><include>**/*.xml</include></includes><filtering>false</filtering></resource></resources></build></project>

配置文件

server:port: 8080
spring:datasource:username: rootpassword: 1234url: jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTCdriver-class-name: com.mysql.cj.jdbc.Driver
pagehelper:page-size-zero: truehelper-dialect: mysqlreasonable: truesupport-methods-arguments: trueparams: count=countsql
logging:level:com:springbootjdbcweb:springbootjdbcweb: debug

mybatis 使用 完全限定名+類名+方法名也可以關聯。

實體類映射

import java.util.Date;/*認證審核*/public class CertificationAudit{/*序號:serial number  int申請編號:application number  int醫生姓名:doctor name醫療機構:medical establishment規范中心:Specification center手機號碼:phone number管理制度:control system協調體系:Coordinate system心衰架構:Heart failure architecture創建時間:creation time  datetime填表人員:Fill out a form personnel--file write people審核狀態:audit status操作:operation*/private Integer serialNumber;private Integer applicationNumber;private String doctorName;private String medicalEstablishment;private String specificationCenter;private String phoneNumber;private String controlSystem;private String coordinateSystem;private Date heartFailureArchitecture;private Date creationTime;private String fileWritePeople;private String auditStatus;private String operation;/* 忽略get set 空參構造器,全參構造器 */
}

mapper.java


package com.springbootjdbcweb.springbootjdbcweb.mapper;import com.springbootjdbcweb.springbootjdbcweb.pojo.CertificationAudit;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.common.Mapper;@Component
public interface CertificationAuditMapper extends Mapper<CertificationAudit> {int delete1(@Param("serialnumber") Integer serialnumber);
}

mapper.xml


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.springbootjdbcweb.springbootjdbcweb.mapper.CertificationAuditMapper"><!--通用查詢映射結果--><resultMap id="sel" type="com.springbootjdbcweb.springbootjdbcweb.pojo.CertificationAudit"><!--column數據庫      property實體類對應--><id column="serialnumber" property="serialNumber"/><result column="applicationnumber" property="applicationNumber"/><result column="doctorname" property="doctorName"/><result column="medicalestablishment" property="medicalEstablishment"/><result column="specificationcenter" property="specificationCenter"/><result column="phonenumber" property="phoneNumber"/><result column="controlsystem" property="controlSystem"/><result column="coordinatesystem" property="coordinateSystem"/><result column="heartfailurearchitecture" property="heartFailureArchitecture"/><result column="creationtime" property="creationTime"/><result column="filewritepeople" property="fileWritePeople"/><result column="auditstatus" property="auditStatus"/><result column="operation" property="operation"/></resultMap><!--通用查詢結果列--><sql id="aaa">
serialnumber,applicationnumber,doctorname,medicalestablishment,specificationcenter,phonenumber,controlsystem,coordinatesystem,heartfailurearchitecture,creationtime,filewritepeople,auditstatus,operation</sql><select id="selCerList" resultMap="sel">select * from CertificationAudit</select><delete id="com.springbootjdbcweb.springbootjdbcweb.mapper.CertificationAuditMapper.delete1" parameterType="int">delete from certificationaudit where serialnumber=#{serialnumber}</delete>
</mapper>

service

import com.springbootjdbcweb.springbootjdbcweb.mapper.CertificationAuditMapper;
import com.springbootjdbcweb.springbootjdbcweb.pojo.CertificationAudit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;import java.util.List;@Service
@Transactional
public class CertificationAuditService {@Autowiredprivate CertificationAuditMapper certificationAuditMapper;public List<CertificationAudit> selCerList() {return certificationAuditMapper.selectAll();}public Integer delCertificationAudit(Integer serialnumber){return certificationAuditMapper.deleteByPrimaryKey(serialnumber);}public Integer delete1(Integer serialnumber){return certificationAuditMapper.delete1(serialnumber);}
}

controller

import com.springbootjdbcweb.springbootjdbcweb.service.CertificationAuditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;@RestController
//@ResponseBody
//@RequestMapping
public class CertificationAuditController {@Autowiredprivate CertificationAuditService certificationAuditService;@RequestMapping(value = "/cer")public String selCer(  Integer serialnumber) {Integer integer = certificationAuditService.delete1(serialnumber);System.out.println(integer);return "login";}@GetMapping("/k")public String s(){System.out.println("232232");return "login";}
}

啟動類

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import tk.mybatis.spring.annotation.MapperScan;@SpringBootApplication
@MapperScan("com.springbootjdbcweb.springbootjdbcweb")
public class SpringbootjdbcwebApplication {public static void main(String[] args) {SpringApplication.run(SpringbootjdbcwebApplication.class, args);}}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/917247.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/917247.shtml
英文地址,請注明出處:http://en.pswp.cn/news/917247.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

iRemovalPro完美繞iCloud插卡打電話,A12+支持iOS 18.1.1

iRemovalPro 專業工具全解析與操作指南 &#xff08;支持iOS 14.0 - 16.6.1&#xff0c;A7-A15芯片設備&#xff09; &#x1f449;下載地址見文末 iRemoval Pro iRemoval 專業版是一款來自外國安全研究員的工具&#xff0c;用來幫助一些人因為忘記自己的ID或者密碼&#xff0c…

安卓SELinux策略語法

目錄前言一、 通用AV規則語法1.1 allow source target:class permissions;1.2 neverallow source target:class permissions;二、type三、attribute四、typeattribute五、alias六、typealias七、init_daemon_domain7.1 init_daemon_domain 宏概述7.2 宏展開與實現7.2.1 展開后規…

vscode cursor配置php的debug,docker里面debug

VSCode PHP調試配置指南 概述 本文介紹如何在VSCode中配置PHP調試環境&#xff0c;包括本地和Docker環境。 前置要求 VSCodePHP 7.0Xdebug擴展PHP Debug VSCode擴展 本地調試配置 1. 安裝Xdebug # Ubuntu/Debian sudo apt-get install php-xdebug# MacOS brew install p…

elk部署加日志收集

清華大學鏡像源地址&#xff1a;Index of /elasticstack/8.x/yum/8.13.2/ | 清華大學開源軟件鏡像站 | Tsinghua Open Source Mirror 一、elasticsearch 1.安裝 rpm -ivh elastic-agent-8.13.2-x86_64.rpm 2.修改配置 vim /etc/elasticsearch/elasticsearch.yml 修改如下&…

dify 升級1.7.1 插件無法下載依賴

dify 升級1.7.1 插件無法下載依賴 1. 安裝通義千問插件&#xff0c;各種報錯&#xff1b; 使用下面命令查看docker 鏡像日志 docker logs -f --tail100 docker-plugin_daemon-1 2025/08/01 07:42:21 full_duplex.go:59: [INFO]init environment for plugin langgenius/tongyi…

linux中簡易云盤系統項目實戰:基于 TCP協議的 Socket 通信、json數據交換、MD5文件區別與多用戶文件管理實現

&#x1f4cb; 項目介紹 本項目是一個基于Linux環境的簡易云盤系統&#xff0c;采用C/S&#xff08;客戶端/服務器&#xff09;架構&#xff0c;實現了類似百度網盤的基本功能。系統通過TCP Socket進行網絡通信&#xff0c;使用JSON格式進行數據交換&#xff0c;利用SQLite3數據…

linux中posix消息隊列的使用記錄

在linux中使用posix中的消息隊列時遇到了一個問題&#xff0c;就是在發送消息時&#xff0c;如果隊列滿了&#xff0c;mq_send接口會一直阻塞&#xff0c;經過查找資料后才發現&#xff0c;該接口默認是阻塞的&#xff0c;也就是說&#xff0c;當隊列滿了以后&#xff0c;接口會…

01 基于sklearn的機械學習-機械學習的分類、sklearn的安裝、sklearn數據集及數據集的劃分、特征工程(特征提取與無量綱化、特征降維)

文章目錄機械學習機械學習分類1. 監督學習2. 半監督學習3. 無監督學習4. 強化學習機械學習的項目開發步驟scikit-learn1 scikit-learn安裝2 sklearn數據集1. sklearn 玩具數據集鳶尾花數據集糖尿病數據集葡萄酒數據集2. sklearn現實世界數據集20 新聞組數據集3. 數據集的劃分特…

n8n】n8n的基礎概念

以下是為初學者整理的 n8n 基本概念總結&#xff0c;幫助快速理解核心功能和使用邏輯&#xff1a;1. 工作流&#xff08;Workflow&#xff09;核心單元&#xff1a;n8n的一切操作基于工作流&#xff0c;代表一個自動化流程。組成&#xff1a;由多個節點&#xff08;Nodes&#…

機器學習基礎-matplotlib

一、相關知識點二、plotfrom pylab import mpl # 設置顯示中文字體 mpl.rcParams["font.sans-serif"] ["SimHei"] # 設置正常顯示符號 mpl.rcParams["axes.unicode_minus"] False #%%#%% import matplotlib.pyplot as plt import random# 畫出…

spring-ai-alibaba 學習(十九)——graph之條件邊、并行節點、子圖節點

前面了解了基礎的概念及流程&#xff0c;以及一些參數類下面了解一些特殊的邊和節點條件邊常見的流程圖可能長這個樣子&#xff1a;其中菱形的為條件節點&#xff08;或者叫判定節點&#xff09;&#xff0c;但是在spring-ai-alibaba-graph中&#xff0c;并沒有條件節點在sprin…

深入淺出設計模式——創建型模式之原型模式 Prototype

文章目錄原型模式簡介原型模式結構關于克隆方法&#xff1a;淺拷貝/深拷貝原型模式代碼實例定義原型類和克隆方法客戶端使用代碼示例示例一&#xff1a;淺拷貝示例二&#xff1a;深拷貝原型模式總結開閉原則代碼倉庫原型模式&#xff1a;用原型實例指定創建對象的種類&#xff…

.NET 10 中的新增功能系列文章3—— .NET MAUI 中的新增功能

.NET 10 預覽版 6 中的 .NET MAUI.NET 10 預覽版 5 中的.NET MAUI.NET 10 預覽版 4 中的 .NET MAUI.NET 10 預覽版 3 中的 .NET MAUI.NET 10 預覽版 2 中的 .NET MAUI.NET 10 預覽版 1 中的 .NET MAUI 一、MediaPicker 增強功能&#xff08;預覽版6&#xff09; .NET 10 預覽…

MT Photos圖庫部署詳解:Docker搭建+貝銳蒲公英異地組網遠程訪問

如今&#xff0c;私有化部署輕量級圖床/圖庫系統&#xff0c;已經成為越來越多用戶的高頻需求。而MT Photos&#xff0c;正是一款非常適合在Docker環境下運行的自托管圖床/圖庫系統。MT Photos基于Node.js與Vue構建&#xff0c;界面簡潔美觀&#xff0c;支持多用戶權限管理、多…

解決dbeaver連接不上oceanbase數據庫的問題

解決dbeaver連接不上oceanbase數據庫的問題 問題&#xff1a; 使用dbeaver連接oceanbase數據庫報錯如下&#xff1a; ORA-00900: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near ‘dat…

Kafka——請求是怎么被處理的?

引言在分布式消息系統中&#xff0c;請求處理機制是連接客戶端與服務端的"神經中樞"。無論是生產者發送消息、消費者拉取數據&#xff0c;還是集群內部的元數據同步&#xff0c;都依賴于高效的請求處理流程。Apache Kafka作為高性能消息隊列的代表&#xff0c;其請求…

區塊鏈技術如何確保智能合約的安全性和可靠性?

智能合約作為區塊鏈上自動執行的可編程協議&#xff0c;其安全性和可靠性直接決定了區塊鏈應用的信任基礎。區塊鏈通過底層技術架構、密碼學工具和機制設計的多重保障&#xff0c;構建了智能合約的安全防線。以下從技術原理、核心機制和實踐保障三個維度展開分析&#xff1a;一…

2020 年 NOI 最后一題題解

問題描述2020 年 NOI 最后一題是一道結合圖論、動態規劃與狀態壓縮的綜合性算法題&#xff0c;題目圍繞 "疫情期間的物資配送" 展開&#xff0c;具體要求如下&#xff1a;給定一個有向圖 G (V, E)&#xff0c;其中節點代表城市&#xff0c;邊代表連接城市的道路。每個…

加密與安全

目錄 一、URL編碼&#xff1a; 二、Base64編碼&#xff1a; 三、哈希算法&#xff1a; 四、Hmac算法&#xff1a; 五、對稱加密算法&#xff1a; 一、URL編碼&#xff1a; URL編碼是瀏覽器發送數據給服務器時使用的編碼&#xff0c;它通常附加在URL的參數部分。之所以需要…

EasyExcel 公式計算大全

EasyExcel 是基于 Apache POI 的封裝&#xff0c;主要專注于簡化 Excel 的讀寫操作&#xff0c;對于公式計算的支持相對有限。以下是 EasyExcel 中處理公式計算的全面指南&#xff1a;1. 基本公式寫入1.1 寫入簡單公式Data public class FormulaData {ExcelProperty("數值…