当前位置: 首页 > news >正文

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.可以配置的选项

相关文章:

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…...

打工人副业变现秘籍,某多/某手变现底层引擎-Stable Diffusion 黑白老照片上色修复

在这个时代,我们习惯于拥有高清、色彩丰富的照片,然而,那些古老的黑白色老照片由于年代的久远,往往会出现模糊、破损等现象。 那么今天要给大家介绍的是,用 Stable Diffusion 来修复老照片。 前段时间 ControlNet 的除了上线了“IP-Adapter”模型以外还增加另一个…...

第十三章总结

一.泛型 1.定义泛型类 泛型机制语法&#xff1a; 类名<T> 其中&#xff0c;T是泛型的名称&#xff0c;代表某一种类型。 【例13.6】创建带泛型的图书类 代码&#xff1a; 结果&#xff1a; 2.泛型的常规用法 (1)定义泛型类时声明多个变量 class MyClass<T1,T2…...

大模型应用_PrivateGPT

https://github.com/imartinez/privateGPT 1 功能 整体功能&#xff0c;想解决什么问题 搭建完整的 RAG 系统&#xff0c;与 FastGPT相比&#xff0c;界面比较简单。但是底层支持比较丰富&#xff0c;可用于知识库的完全本地部署&#xff0c;包含大模型和向量库。适用于保密级…...

[Android] ubuntu虚拟机上搭建 Waydroid 环境

1.安装虚拟机 略 2.安装waydroid Ubuntu/Debian and derivatives For Droidian and Ubuntu Touch, skip directly to the last step Install pre-requisites sudo apt install curl ca-certificates -y Add the official repository curl https://repo.waydro.id | sudo…...

LeedCode刷题---滑动窗口问题(二)

顾得泉&#xff1a;个人主页 个人专栏&#xff1a;《Linux操作系统》 《C/C》 《LeedCode刷题》 键盘敲烂&#xff0c;年薪百万&#xff01; 一、将X减到0的最小操作数 题目链接&#xff1a;将 x 减到 0 的最小操作数 题目描述 给你一个整数数组 nums 和一个整数 x 。每一…...

pycharm依赖管理(不要用pip freeze)

在使用python虚拟环境时&#xff0c;可以使用requirements.txt来管理当前项目的依赖。 注意&#xff0c;不要用 pip freeze > requirements.txt 这个命令&#xff0c;因为它会引入很多无关的包。 可以使用 pipreqs ./ --encodingutf-8 ./ 表示当前项目的目录&#xff0…...

[Kafka 常见面试题]如何保证消息的不重复不丢失

文章目录 Kafka1. Kafka如何保证不丢失消息&#xff1f;生产者数据的不丢失消费者数据的不丢失Kafka集群中的broker的数据不丢失 2. Kafka中的消息是否会丢失和重复消费&#xff1f;1. 消息发送2. 消息消费 3. Kafka 的设计是什么样的呢&#xff1f;4. 数据传输的事务定义有哪三…...

Java中System.setProperty()用法

Java中System.setProperty()用法 大家好&#xff0c;我是免费搭建查券返利机器人赚佣金就用微赚淘客系统3.0的小编&#xff0c;也是冬天不穿秋裤&#xff0c;天冷也要风度的程序猿&#xff01;今天&#xff0c;让我们一起深入了解Java中的System.setProperty()方法&#xff0c…...

Eclipse 自动生成注解,如果是IDEA可以参考编译器自带模版进行修改

IDEA添加自动注解 左上角选择 File -> Settings -> Editor -> File and Code Templates&#xff1b; 1、添加class文件自动注解&#xff1a; ​/*** <b>Function: </b> todo* program: ${NAME}* Package: ${PACKAGE_NAME}* author: Jerry* date: ${YEA…...

微信小程序vant安装使用过程中遇到无法构建npm的问题

官网地址&#xff0c;然而如果完全按照这个教程来&#xff0c;实际上是缺少步骤的&#xff0c;需要补充一些步骤&#xff08;参考https://www.bilibili.com/video/BV1vL41127Er&#xff09; # 这步init就是补充的 npm init npm i vant/weapp -S --production# 剩下的按照vant的…...

[python]用python获取EXCEL文件内容并保存到DBC

目录 关键词平台说明背景所需库实现过程方法1.1.安装相关库2.代码实现 关键词 python、excel、DBC、openpyxl 平台说明 项目Valuepython版本3.6 背景 在搭建自动化测试平台的时候经常会提取DBC文件中的信息并保存为excel或者其他文件格式&#xff0c;用于自动化测试。本文…...

Spring Boot 如何配置 log4j2

Log4j2 介绍 Spring Boot 中默认使用 Logback 作为日志框架&#xff0c;接下来我们将学习如何在 Spring Boot 中集成与配置 Log4j2。在配置之前&#xff0c;我们需要知道的是 Log4j2 是 Log4j 的升级版&#xff0c;它在 Log4j 的基础上做了诸多改进&#xff1a; 异步日志&…...

如何安装docker

安装Docker的步骤取决于您使用的操作系统。以下是常见操作系统上安装Docker的基本步骤&#xff1a; 对于Linux: 更新软件包索引&#xff1a; sudo apt-get update安装允许apt通过HTTPS使用仓库的包&#xff1a; sudo apt-get install apt-transport-https ca-certificates cur…...

Linux 之 性能优化

uptime $ uptime -p up 1 week, 1 day, 21 hours, 27 minutes$ uptime12:04:11 up 8 days, 21:27, 1 user, load average: 0.54, 0.32, 0.23“12:04:11” 表示当前时间“up 8 days, 21:27,” 表示运行了多长时间“load average: 0.54, 0.32, 0.23”“1 user” 表示 正在登录…...

用Go汇编实现一个快速排序算法

本代码全网首发&#xff0c;使用Go plan9 windows arm64汇编&#xff0c;实现基础版快速排序算法。 未引入随机因子的快速排序的普通Go代码长这样。 func QuickSort(arr []int) {if len(arr) < 1 {return}base, l, r : arr[0], 0, len(arr)-1for i : 1; i < r; {if arr…...

Spring-整合MyBatis

依赖 <dependencies><!--提供数据源--><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.1.9.RELEASE</version></dependency><!--提供sqlSessionFactory…...

sql宽字节注入

magic_quotes_gpc&#xff08;魔术引号开关&#xff09; https://www.cnblogs.com/timelesszhuang/p/3726736.html magic_quotes_gpc函数在php中的作用是判断解析用户提交的数据&#xff0c;如包括有&#xff1a;post、get、cookie过来的数据增加转义字符“\”&#xff0c;以…...

开源 LLM 微调训练指南:如何打造属于自己的 LLM 模型

一、介绍 今天我们来聊一聊关于LLM的微调训练&#xff0c;LLM应该算是目前当之无愧的最有影响力的AI技术。尽管它只是一个语言模型&#xff0c;但它具备理解和生成人类语言的能力&#xff0c;非常厉害&#xff01;它可以革新各个行业&#xff0c;包括自然语言处理、机器翻译、…...

Android hilt使用

一&#xff0c;添加依赖库 添加依赖库app build.gradle.kts implementation("com.google.dagger:hilt-android:2.49")annotationProcessor("com.google.dagger:hilt-android:2.49")annotationProcessor("com.google.dagger:hilt-compiler:2.49"…...

ARM错误恢复中断机制与ERRERICR2寄存器详解

1. ARM错误恢复中断机制概述在ARM架构的可靠性、可用性和可维护性&#xff08;RAS&#xff09;系统中&#xff0c;错误恢复中断是实现硬件容错的关键机制。当处理器检测到可恢复的错误条件时&#xff0c;通过这套机制能够快速通知系统进行错误处理&#xff0c;而ERRERICR2寄存器…...

FPGA加速脉冲神经网络:架构设计与优化实践

1. FPGA加速脉冲神经网络的核心架构解析脉冲神经网络(SNN)作为类脑计算的核心载体&#xff0c;其硬件实现面临三大核心挑战&#xff1a;生物可信度、计算效率和能效比。FPGA凭借其可重构特性成为SNN加速的理想平台&#xff0c;现代架构设计主要围绕以下关键技术展开&#xff1a…...

天线阻抗匹配原理与工程实践指南

1. 天线阻抗匹配基础概念解析阻抗匹配是射频工程师日常工作中最常遇到的技术挑战之一。简单来说&#xff0c;它就像是在为天线系统"调音"&#xff0c;确保射频能量能够顺畅地从发射电路传递到天线&#xff0c;而不会在连接处产生"回声"&#xff08;反射波&…...

企业真正缺的不是模型,而是“AI 协作系统”

过去两年&#xff0c;大模型的发展速度远远超出了很多人的预期。 模型越来越强&#xff0c;推理成本越来越低&#xff0c;开源生态也越来越成熟。 很多企业因此开始接入 AI&#xff0c;希望通过大模型提升效率。 但真正进入业务阶段后&#xff0c;一个问题开始越来越明显&am…...

八、命令行参数和环境变量

八、命令行参数和环境变量8.1 命令行参数8.2 环境变量概念8.3 常见环境变量8.4 查看环境变量指令测试 PATH8.5 环境变量相关命令8.6 环境变量组织方式8.7 环境变量通常具有全局属性进程创建机制环境变量的存储结构代码执行流程总结8.8 获取环境变量命令行第三个参数通过第三方变…...

汽车科技前沿:从上海车展看电动化、自动驾驶与供应链变革

1. 四月汽车科技前沿动态概览又到了每月梳理行业动态的时候了。四月份的汽车科技圈&#xff0c;用一个词来形容就是“多点开花”。上海车展的盛大回归&#xff0c;像一剂强心针&#xff0c;宣告了全球汽车产业活力的全面复苏。与此同时&#xff0c;软件定义汽车的浪潮下&#x…...

Windows Cleaner终极指南:5个技巧让C盘空间瞬间释放

Windows Cleaner终极指南&#xff1a;5个技巧让C盘空间瞬间释放 【免费下载链接】WindowsCleaner Windows Cleaner——专治C盘爆红及各种不服&#xff01; 项目地址: https://gitcode.com/gh_mirrors/wi/WindowsCleaner Windows Cleaner是一款专为Windows系统设计的开源…...

别再手动导网表了!巧用OrCAD Capture与Allegro PCB Editor联动,实现原理图变更一键同步

别再手动导网表了&#xff01;巧用OrCAD Capture与Allegro PCB Editor联动&#xff0c;实现原理图变更一键同步 在PCB设计领域&#xff0c;效率与准确性往往决定着项目成败。当工程师面对频繁的原理图修改时&#xff0c;传统的手动导出-导入网表流程不仅耗时费力&#xff0c;还…...

Ansible file模块实战:从创建目录到管理软硬链接,一篇搞定Linux文件系统日常运维

Ansible file模块实战&#xff1a;从创建目录到管理软硬链接&#xff0c;一篇搞定Linux文件系统日常运维 在当今云计算和自动化运维的时代&#xff0c;手动登录服务器执行文件操作已经成为效率的瓶颈。想象一下&#xff0c;当你需要在数百台服务器上统一创建应用目录结构、批量…...

基于AI与贝叶斯学习的开源LinkedIn自动化销售探索代理部署指南

1. 项目概述&#xff1a;一个能自己找客户的AI销售代理如果你在B2B销售、市场拓展或者创业&#xff0c;你一定对LinkedIn又爱又恨。爱的是&#xff0c;它几乎是全球最精准的B2B客户数据库&#xff1b;恨的是&#xff0c;手动寻找、筛选、联系潜在客户&#xff0c;是一个极其耗时…...