1、maven引入jar包(jpa和mysql)

        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>

2、配置文件

spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver server.port=8080

3、创建实体类(示例)

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable; @Entity
@Table(name="student")
public class Student implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private Integer sid;
private String sname;
private Integer sage;
private String ssex; public Integer getSid() {
return sid;
} public void setSid(Integer sid) {
this.sid = sid;
} public String getSname() {
return sname;
} public void setSname(String sname) {
this.sname = sname;
} public Integer getSage() {
return sage;
} public void setSage(Integer sage) {
this.sage = sage;
} public String getSsex() {
return ssex;
} public void setSsex(String ssex) {
this.ssex = ssex;
}
}

4、创建对应实体的接口

import com.demo.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;

//1、这个类中自带一些简单的增删改查方法,可以直接调用
public interface StudentRepository extends JpaRepository<Student,Integer> { /*2、也支持执行sql语句(例如)*/
@Query("from Student where sage = ?1")
List<Student> getStudentsBySage(@Param("sage") Integer sage); /*3、支持根据方法名的查询(例如)*/
Student findBySid(Integer sid); }
Keyword Sample JPQL snippet

And

findByLastnameAndFirstname

… where x.lastname = ?1 and x.firstname = ?2

Or

findByLastnameOrFirstname

… where x.lastname = ?1 or x.firstname = ?2

Is,Equals

findByFirstname,findByFirstnameIs,findByFirstnameEquals

… where x.firstname = ?1

Between

findByStartDateBetween

… where x.startDate between ?1 and ?2

LessThan

findByAgeLessThan

… where x.age < ?1

LessThanEqual

findByAgeLessThanEqual

… where x.age <= ?1

GreaterThan

findByAgeGreaterThan

… where x.age > ?1

GreaterThanEqual

findByAgeGreaterThanEqual

… where x.age >= ?1

After

findByStartDateAfter

… where x.startDate > ?1

Before

findByStartDateBefore

… where x.startDate < ?1

IsNull

findByAgeIsNull

… where x.age is null

IsNotNull,NotNull

findByAge(Is)NotNull

… where x.age not null

Like

findByFirstnameLike

… where x.firstname like ?1

NotLike

findByFirstnameNotLike

… where x.firstname not like ?1

StartingWith

findByFirstnameStartingWith

… where x.firstname like ?1 (parameter bound with appended %)

EndingWith

findByFirstnameEndingWith

… where x.firstname like ?1 (parameter bound with prepended %)

Containing

findByFirstnameContaining

… where x.firstname like ?1 (parameter bound wrapped in %)

OrderBy

findByAgeOrderByLastnameDesc

… where x.age = ?1 order by x.lastname desc

Not

findByLastnameNot

… where x.lastname <> ?1

In

findByAgeIn(Collection<Age> ages)

… where x.age in ?1

NotIn

findByAgeNotIn(Collection<Age> age)

… where x.age not in ?1

True

findByActiveTrue()

… where x.active = true

False

findByActiveFalse()

… where x.active = false

IgnoreCase

findByFirstnameIgnoreCase

… where UPPER(x.firstame) = UPPER(?1)

详细介绍:

https://blog.csdn.net/ityouknow/article/details/52688664

springboot之jpa(简述)的更多相关文章

  1. Springboot+Atomikos+Jpa+Mysql实现JTA分布式事务

    1 前言 之前整理了一个spring+jotm实现的分布式事务实现,但是听说spring3.X后不再支持jotm了,jotm也有好几年没更新了,所以今天整理springboot+Atomikos+jp ...

  2. 【极简版】SpringBoot+SpringData JPA 管理系统

    前言 只有光头才能变强. 文本已收录至我的GitHub仓库,欢迎Star:https://github.com/ZhongFuCheng3y/3y 在上一篇中已经讲解了如何从零搭建一个SpringBo ...

  3. 带你搭一个SpringBoot+SpringData JPA的环境

    前言 只有光头才能变强. 文本已收录至我的GitHub仓库,欢迎Star:https://github.com/ZhongFuCheng3y/3y 不知道大家对SpringBoot和Spring Da ...

  4. 二、springboot使用jpa

    花了几天时间,好好看了看springboot的jpa部分,总结了常用的形式. 1.通过STS工具添加jpa的依赖项 要连mysql,测试的时候需要web,顺便添加了lombok不写set和get方法了 ...

  5. Springboot+MyBatis+JPA集成

      1.前言 Springboot最近可谓是非常的火,本人也在项目中尝到了甜头.之前一直使用Springboot+JPA,用了一段时间发现JPA不是太灵活,也有可能是我不精通JPA,总之为了多学学Sp ...

  6. 第11章—使用对象关系映射持久化数据—SpringBoot+SpringData+Jpa进行查询修改数据库

    SpringBoot+SpringData+Jpa进行查询修改数据库 JPA由EJB 3.0软件专家组开发,作为JSR-220实现的一部分.但它又不限于EJB 3.0,你可以在Web应用.甚至桌面应用 ...

  7. 集成Springboot+MyBatis+JPA

    1.前言 Springboot最近可谓是非常的火,本人也在项目中尝到了甜头.之前一直使用Springboot+JPA,用了一段时间发现JPA不是太灵活,也有可能是我不精通JPA,总之为了多学学Spri ...

  8. SpringBoot Data JPA 关联表查询的方法

    SpringBoot Data JPA实现 一对多.多对一关联表查询 开发环境 IDEA 2017.1 Java1.8 SpringBoot 2.0 MySQL 5.X 功能需求 通过关联关系查询商店 ...

  9. 用SpringBoot+MySql+JPA实现对数据库的增删改查和分页

    使用SpringBoot+Mysql+JPA实现对数据库的增删改查和分页      JPA是Java Persistence API的简称,中文名Java持久层API,是JDK 5.0注解或XML描述 ...

  10. springboot使用Jpa连接数据库

    springboot使用Jpa连接数据库 1.pom.xml: <?xml version="1.0" encoding="UTF-8"?> < ...

随机推荐

  1. neo4j中cypher语句多个模糊查询

    总结一下经验: neo4j中,cypher语句的模糊查询,好像是个正则表达式结构. 对于一个属性的多个模糊查询,可以使用如下写法: 比如,查询N类型中,属性attr包含'a1'或者'a2'的所有节点. ...

  2. neo4j安装APOC插件

    1.APOC下载地址:https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/3.4.0.1 只要下载.jar这一个压缩文件就好 ...

  3. Linux QtCreator 创建工程

    这一天天的,都快成废物了, 每天忙得要死, 各种乱七八糟杂事,连点学习的时间都没有了, 这才一年不碰Linux,创建工程都不会了, Ubuntu 1N.N.N + QtCreator 创建工程 不安装 ...

  4. h5对接jssdk支付分并调用开启支付分页面

    1.ws.config签名   调用ticket等获取ws.config的签名,下面会调用方法再调用方法时需要再次按照调用方法的签名 wx.config({ debug: true, // 开启调试模 ...

  5. 微信小程序前后台调用

    // pages/ruquestexer/index.js Page({ /** * 页面的初始数据 */ data: { }, getUserData:function(){ wx.request( ...

  6. P3718 [AHOI2017初中组]alter

    贪心+二分答案 二分最终答案长度 主要问题在check上 ~~我代码写得巨丑,大家还是不要看我的代码了~~ ------------ 1:当mid大于1的时候,贪心策略是这样的: 当前连续的长度大于m ...

  7. HZOI20190816模拟23 mine/water/gcd

    A:mine 只是一个简单的dp....是博主太蒻了... 设f[i][j],表示到第i位,状态是j的方案数,其中$j\in[0,5]$ j==0表示填0,j==1表示填1,且i-1位是雷; j==2 ...

  8. [复习]平衡树splay

    明天要考试了…… 出来写一个splay的复习总结. 怕忘…… ^废话^ 以下内容学习自yyb大神的博客, 由于yyb大神内容不全, 部分是博主本人自行脑补... 这个模板还是比较全的^-^ ^又是一堆 ...

  9. ssm框架,出现xxx不能加载,或者bean不能加载时的解决方案之一

    有可能是你在项目的mapper.xml文件中添加了本项目没有的实体类, 你把日志中找不到的最后一个实体类全项目搜索下,改成本项目可以引用的即可

  10. Ubuntu 快速安装配置Odoo 12

    Odoo 12预计将于今年10月正式发布,这是一次大版本更新,带来了一些不错的新特性,如 文件管理系统(DMS) 用户表单中新增字段(Internal user, Portal, Public) HR ...