SpringData JPA 整合Springboot

1.导入依赖

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>springdata</artifactId><groupId>com.kuang</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>springboot-jpa</artifactId><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><!--    声明springboot的版本号 --><spring-boot.version>2.2.9.RELEASE</spring-boot.version></properties><!--  引入springboot官方提供的所有依赖的版本号定义,如果项目中使用相关依赖,可以不必写版本号了--><dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>${spring-boot.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><dependencies><!--    引入springboot的web项目的依赖        --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>
<!--     data - jpa 启动器  --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.47</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId></dependency><!--        druid连接--><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.2.6</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency></dependencies></project>

2.yml

spring:datasource:driver-class-name: com.mysql.jdbc.Driverusername: rootpassword: 2001url: jdbc:mysql://localhost:3306/springdata_jpa?useSSL=true&useUnicode=true&characterEncoding=utf8type: com.alibaba.druid.pool.DruidDataSourcejpa:hibernate:ddl-auto: update #数据库表的生成策略show-sql: true  #是否显示SQLgenerate-ddl: true #是否生成建表语句打印在控制台上

3.CustomerRepository 接口

package com.kuang.springdata.repositories;import com.kuang.springdata.pojo.Customer;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Component;public interface CustomerRepository extends PagingAndSortingRepository<Customer,Long> {
}

4.service

package com.kuang.springdata.service;import com.kuang.springdata.pojo.Customer;public interface CustomerService {Iterable<Customer> getAll();
}
package com.kuang.springdata.service;import com.kuang.springdata.pojo.Customer;
import com.kuang.springdata.repositories.CustomerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class CustomerServiceImpl implements CustomerService{@Autowiredprivate CustomerRepository customerRepository;@Overridepublic Iterable<Customer> getAll() {return customerRepository.findAll();}
}

5.Controller

package com.kuang.springdata.controller;import com.kuang.springdata.pojo.Customer;
import com.kuang.springdata.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class CustomerController {@Autowiredprivate CustomerService customerService;@RequestMapping("/customer/all")public Iterable<Customer> getAll(){Iterable<Customer> iterable=customerService.getAll();return iterable;}
}

6.运行

7.可以配置的选项

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/233791.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

7-1 单身狗(PTA - 数据结构)

由于这道题在留的作业中&#xff0c;排序和查找都有&#xff0c;所以我先写这道题&#xff08;图的先放放&#xff09; “单身狗”是中文对于单身人士的一种爱称。本题请你从上万人的大型派对中找出落单的客人&#xff0c;以便给予特殊关爱。 输入格式&#xff1a; 输入第一行…

域架构下的功能安全思考

来源&#xff1a;联合电子 随着整车电子电气架构的发展&#xff0c;功能域控架构向整车集中式区域控制演进。新的区域控制架构下&#xff0c;车身控制模块(BCM)&#xff0c;整车控制单元&#xff08;VCU&#xff09;&#xff0c;热管理系统&#xff08;TMS&#xff09;和动力底…

PySide6 Tutorials (三)鼠标移动控件及其位置更新

问题描述 在graphicview中拖拽控件从A位置到B位置&#xff0c;但是从B位置再次拖拽控件的时候&#xff0c;控件依旧从A位置出发&#xff0c;与鼠标不处于同一位置。 解决方案 网上搜了一圈都是收费文章&#xff0c;什么时候开源精神都已经被xxxx用来中间商赚差价了嘛&#x…

python实现贪吃蛇游戏

文章目录 1、项目说明2、项目预览3、开发必备4、贪吃蛇代码实现4.1、窗口和基本参数实现4.2、绘制背景4.3、绘制墙壁4.4、绘制贪吃蛇4.5、绘制食物4.6、实现长度信息显示4.7、定义游戏暂停界面4.8、定义贪吃蛇死亡界面4.9、实现贪吃蛇碰撞效果4.10、实现添加食物功能4.11、实现…

String详解

String str new String&#xff08;“123”&#xff09;&#xff0c;和 String str “123” 区别 String str new String&#xff08;"123"&#xff09;;String str "123" ; new是创建对象&#xff0c;在堆中存储&#xff0c;非new 是在栈用的常量池中…

vuex--未完

一、 简介 vue3.0以上&#xff0c;本文是3.0 vue2.0 Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式 库&#xff08;全局管理&#xff0c;相当于一个全局变量&#xff0c;所有页面共享&#xff09;。它采用集中式存储管理应用的所有组件的状态&#xff0c;并以相应的规则…

elementui中的el-table,当使用fixed属性时,table主体会遮挡住滚动条的大半部分,导致很难选中。

情况&#xff1a; 解决&#xff1a; el-table加个类&#xff0c;这里取为class"table" 然后是样式部分&#xff1a; <style scoped lang"scss"> ::v-deep.table {// 滚动条高度调整::-webkit-scrollbar {height: 15px;}// pointer-events 的基本信…

处理HTTP响应状态码和错误处理

在Web开发的世界里&#xff0c;HTTP响应状态码和错误处理是不可或缺的一部分。它们就像是道路上的交通信号灯&#xff0c;指导着我们前进的方向&#xff0c;确保我们的应用程序能够正常运行。 HTTP响应状态码是Web服务器返回给客户端的数字代码&#xff0c;用于表示请求的处理…

以编程方式向 App 设计工具添加 UI 组件

App 设计工具组件库中提供了大多数 UI 组件&#xff0c;可以将它们拖放到画布上。有时&#xff0c;可能需要在代码视图中以编程方式添加组件。以下是一些常见情况&#xff1a; 创建在组件库中未提供的组件。例如&#xff0c;用于显示某对话框的 App 必须调用适当的函数来显示该…

Volta简单介绍

Volta是一款强大的JavaScript工具管理器&#xff0c;它简化了命令行工具的安装和管理。通过Volta&#xff0c;开发者可以轻松地在多个项目中切换和配置Node.js、npm以及其它JavaScript工具版本&#xff0c;提高开发效率和环境一致性。 什么是 Volta Volta 是一种管理 JavaScri…

数据之门:使用IPIDEA开启网络自由之旅~

本文目录 前言一、网络代理IP简介二、IPIDEA 优势2.1 多种类型IP代理2.2 海量纯净代理池2.3 稳定高效数据收集架构2.4 个人IP管理中心 三、IP代理实操小Tips3.1 查看本地网络IP3.2 使用浏览器IP代理3.3 使用IPIDEA进行爬虫实操 四、总结 前言 各位友友&#xff0c;大家好&…

ASP.NET MVC+EntityFramework图片头像上传

1&#xff0c;先展示一下整体的效果 2&#xff0c;接下来展示用户添加以及上传头像代码、添加用户界面 前端代码如下&#xff1a; <div class"form-group">Html.LabelFor(model > model.img, "头像&#xff1a;", htmlAttributes: new { class &…

【LeetCode】344.反转字符串

今日学习的文章链接和视频链接 leetcode题目地址&#xff1a;344.反转字符串 代码随想录题解地址&#xff1a;代码随想录 题目简介 编写一个函数&#xff0c;其作用是将输入的字符串反转过来。输入字符串以字符数组 s 的形式给出。 不要给另外的数组分配额外的空间&#xf…

【计算机组成与体系结构Ⅱ】多处理器部分讨论题目

多处理机课堂讨论 1.并行计算体系结构有哪些? SIMD、MIMD 2.多处理机的存储结构有哪些? 对称式共享存储器结构、分布式共享存储结构 3.什么是多处理机的一致性? 如果对某个数据项的任何读操作均可得到其最新写入的值&#xff0c;则认为这个存储系统是一致的。 4.监听协议的工…

easyexcel调用公共导出方法导出数据

easyexcel备忘 Slf4j public class ConditionDownloadUtil {//扫描在xboot 包下所有IService 接口的子类, 每次启动服务后, 重新扫描public final static Class[] classesExtendsIService ClassUtil.scanPackageBySuper("cn.exrick.xboot", IService.class).toArra…

UCloud + 宝塔 + PHP = 个人网站

UCloud 宝塔 PHP 个人网站 文章目录 1.概要2.UCloud使用教程&#xff08;租用云端服务器&#xff09;3.宝塔使用教程&#xff08;免费服务器运维面板&#xff09;4.总结 1.概要 今天主要是想教大家如何将在网络上白嫖到源码&#xff08;特指PHP源码!!!&#xff09;搭建运行…

uni-app 用于开发H5项目展示饼图,使用ucharts 饼图示例

先下载ucharts H5示例源码&#xff1a; uCharts: 高性能跨平台图表库&#xff0c;支持H5、APP、小程序&#xff08;微信小程序、支付宝小程序、钉钉小程序、百度小程序、头条小程序、QQ小程序、快手小程序、360小程序&#xff09;、Vue、Taro等更多支持canvas的框架平台&#…

使用bs4 分析html文件

首先需要 pip install beautifulsoup4安装 然后为了方便学习此插件&#xff0c;随便打开一个网页&#xff0c;然后鼠标右键&#xff0c;打开源网页&#xff0c;如下图片 这样就可以获得一个网页源码&#xff0c;全选复制粘贴到本地&#xff0c;存储为 .html 文件&#xff0c;…

WebLangChain_ChatGLM:结合 WebLangChain 和 ChatGLM3 的中文 RAG 系统

WebLangChain_ChatGLM 介绍 本文将详细介绍基于网络检索信息的检索增强生成系统&#xff0c;即 WebLangChain。通过整合 LangChain&#xff0c;成功将大型语言模型与最受欢迎的外部知识库之一——互联网紧密结合。鉴于中文社区中大型语言模型的蓬勃发展&#xff0c;有许多可供利…

自封组件-带边框的渐变色数据卡片

<template> <el-row :gutter"10"><el-col :span"8"><div class"dplay_green"><div class"dplay_num_green">{{ jhdl }}</div><div class"dplay_text_green">提示文字</div>…