SpringBoot在IDEA下使用JPA
1依赖
使用IDEA构建基于JPA的项目需要引用JPA、MYSQL依赖

2配置文件修改
2.1连接库
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=Aa123123
2.2开启jpa日志
spring.jpa.show-sql=true
3编写实体连接表
实体类增加注解
@Entity
@Table(name = "car")
主键增加注解
@Id()
字段增加注解
@Column(name = "car_id")
4定义JPA接口类
JPA接口默认提供保存、delByID,如果额外需要查询和更新需要手动定义接口,其中使用update接口有两点需要注意:
1用户手动编写SQL放在@Query注解中;
2增加注解@Transactional、@Modifying用于update方法。
package com.cloud.jpa.repository; import com.cloud.jpa.entity.Car;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository; import javax.transaction.Transactional; @Repository
public interface FirstJpaRepository extends JpaRepository<Car, Integer> { Car findByCarId(Integer carid); Car findByCarName(String carName); @Transactional
@Modifying
@Query(value = "update car c set c.car_name=? where car_id=?", nativeQuery = true)
int updateCarNameByCarId(String carName, Integer carId);
}
5开始使用
搭建好上述环境后就可以实现基本的基于JPA的CRUD了
项目地址 https://github.com/MingHaiTian/springboot-jpa.git
SpringBoot在IDEA下使用JPA的更多相关文章
- SpringBoot中使用Spring Data Jpa 实现简单的动态查询的两种方法
软件152 尹以操 首先谢谢大佬的简书文章:http://www.jianshu.com/p/45ad65690e33# 这篇文章中讲的是spring中使用spring data jpa,使用了xml ...
- alibaba druid 在springboot start autoconfig 下的bug
alibaba druid 在springboot start autoconfig下的bug 标签(空格分隔):druid springboot start autoconfig 背景 发现.分析过 ...
- SpringBoot系列之Spring Data Jpa集成教程
SpringBoot系列之Spring Data Jpa集成教程 Spring Data Jpa是属于Spring Data的一个子项目,Spring data项目是一款集成了很多数据操作的项目,其下 ...
- Springboot的resources下资源访问的问题
对于路径问题,是让我一直感到痛苦的事情,首先是因为我的眼高手低,感觉路径这么简单根本没必要去看,但是昨天项目组长的冷嘲热讽让我无地自容:“你竟然连linux和window的路径的区别都不知道,呵呵”. ...
- SpringBoot图文教程12—SpringData Jpa的基本使用
有天上飞的概念,就要有落地的实现 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例都敲一遍 先赞后看,养成习惯 SpringBoot 图文教程系列文章目录 SpringBoot图文教程1「概念+ ...
- SpringBoot入门:Spring Data JPA 和 JPA(理论)
参考链接: Spring Data JPA - Reference Documentation Spring Data JPA--参考文档 中文版 纯洁的微笑:http://www.ityouknow ...
- SpringBoot(三)thymeleaf+JPA+MySql
接着上一节的 第一步:在pom文件中加入以下代码: <!--JPA--> <dependency> <groupId>org.springframework.boo ...
- springboot(五):spring data jpa的使用
在上篇文章springboot(二):web综合开发中简单介绍了一下spring data jpa的基础性使用,这篇文章将更加全面的介绍spring data jpa 常见用法以及注意事项 使用spr ...
- SpringBoot(五) :spring data jpa 的使用
原文出处: 纯洁的微笑 在上篇文章springboot(二):web综合开发中简单介绍了一下spring data jpa的基础性使用,这篇文章将更加全面的介绍spring data jpa 常见用法 ...
随机推荐
- Git&GitHub-初步使用
Git 1.安装 下载安装包,安装,默认安装了 Git GUI Here 和 Git Bash Here. 需要在哪里使用 git,只需在文件夹空白处右键,选择Git Bash Here即可打开 gi ...
- 最优贸易(tarjan,spfa)
题目描述 C国有n个大城市和m 条道路,每条道路连接这 n个城市中的某两个城市.任意两个城市之间最多只有一条道路直接相连.这 m 条道路中有一部分为单向通行的道路,一部分为双向通行的道路,双向通行的道 ...
- uva_11806_Cheerleaders
In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...
- md5加密+盐方式一
这种方法是采用随机生成盐值加入password中组合成的新密码,下面是md5+盐的一个工具类,直接导入使用即可! 工具类 package com.oracle.utils; import java.s ...
- YII2.0 后台手动添加用户功能
后台添加管理员用户使用SignupForm类实现 步骤一.复制一份前台frontend/models/SignupForm.php 到后台模型文件夹中 backend/models/SignupFor ...
- hadoop生态搭建(3节点)-14.redis配置
# ==================================================================规划node1 redis:7000 7001 192.168. ...
- QOS-policy配置
QOS-QOS-policy配置 2018年7月7日 20:29 配置: 先匹配acl: [RT2]acl number 3000 [RT2-acl-adv-3000]description QOS ...
- 18CCPC网赛A 贪心
Buy and Resell Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- easyui设置行的背景色
var arr = new Array(3000082, 3000095); self.itemGrid.datagrid({ rowStyler: function (index, row) { f ...
- fedora/centos下gcc编译出现gcc: error trying to exec ‘cc1plus’: execvp: No such file or directory
fedora/centos下gcc编译出现gcc: error trying to exec 'cc1plus': execvp: No such file or directory解决办法 翻译自: ...