[Java Spring] JPA CrudRepository query language
2021-03-11 12:27
标签:one dsc protect import where from too difficult get Entity: In Repository, you can do baisc extension: You can combine multi Entities: But function name become pretty long and hard to understand, then we can switch to @Query: [Java Spring] JPA CrudRepository query language 标签:one dsc protect import where from too difficult get 原文地址:https://www.cnblogs.com/Answer1215/p/14127054.htmlpackage com.example.ec.domain;
import javax.persistence.*;
@Entity
public class Tour {
@Id
@GeneratedValue
private Integer id;
@Column
private String title;
@Column(length = 2000)
private String description;
@Column(length = 2000)
private String blurb;
@Column
private Integer price;
@Column
private String duration;
@Column
private String keywords;
@Column(length = 2000)
private String bullets;
@ManyToOne
private TourPackage tourPackage;
@Column
@Enumerated
private Difficulty difficulty;
@Column
@Enumerated
private Region region;
public Tour(String title, String description, String blurb, Integer price, String duration, String bullets, String keywords, TourPackage tourPackage, Difficulty difficulty, Region region) {
this.title = title;
this.description = description;
this.blurb = blurb;
this.price = price;
this.duration = duration;
this.bullets = bullets;
this.keywords = keywords;
this.tourPackage = tourPackage;
this.difficulty = difficulty;
this.region = region;
}
protected Tour() {}
public Integer getId() {
return id;
}
public String getKeywords() {
return keywords;
}
public void setKeywords(String keywords) {
this.keywords = keywords;
}
public void setId(Integer id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getBlurb() {
return blurb;
}
public void setBlurb(String blurb) {
this.blurb = blurb;
}
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
this.price = price;
}
public String getDuration() {
return duration;
}
public void setDuration(String duration) {
this.duration = duration;
}
public String getBullets() {
return bullets;
}
public void setBullets(String bullets) {
this.bullets = bullets;
}
public TourPackage getTourPackage() {
return tourPackage;
}
public void setTourPackage(TourPackage tourPackage) {
this.tourPackage = tourPackage;
}
public Difficulty getDifficulty() {
return difficulty;
}
public void setDifficulty(Difficulty difficulty) {
this.difficulty = difficulty;
}
public Region getRegion() {
return region;
}
public void setRegion(Region region) {
this.region = region;
}
}
package com.example.ec.domain;
import javax.persistence.Column;
import javax.persistence.Id;
public class TourPackage {
@Id
private String code;
@Column
private String name;
protected TourPackage() {}
public TourPackage(String code, String name) {
this.code = code;
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public interface TourPackageRepository extends CrudRepository
package com.example.ec.repo;
import com.example.ec.domain.Difficulty;
import com.example.ec.domain.Region;
import com.example.ec.domain.Tour;
import org.springframework.data.repository.CrudRepository;
import java.util.*;
public interface TourRepository extends CrudRepository
package com.example.ec.repo;
import com.example.ec.domain.Difficulty;
import com.example.ec.domain.Region;
import com.example.ec.domain.Tour;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import java.util.*;
public interface TourRepository extends CrudRepository
文章标题:[Java Spring] JPA CrudRepository query language
文章链接:http://soscw.com/index.php/essay/63190.html