第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在 Spring Boot 中使存儲(chǔ)庫 findBy() 具有多個(gè)字段?

如何在 Spring Boot 中使存儲(chǔ)庫 findBy() 具有多個(gè)字段?

白衣非少年 2023-05-10 13:47:36
我想在 Spring Boot java 應(yīng)用程序中創(chuàng)建 restcontroller findbyProductIdandYear,但出現(xiàn)錯(cuò)誤,如何以很好的方式實(shí)現(xiàn)它?這是我的模型:   @Entity   @Table(name="view_disbursement_by_project")   public class ViewDisbursement {@Id@GeneratedValue(strategy = GenerationType.IDENTITY)@Column(name="id")private int id;@Column(name="project_id")private String projectId;@Column(name="stage")private String stage;@Column(name="no")private Integer no;@Column(name="months")private Integer months;@Column(name="years")private Integer years;@Column(name="count")private Integer count;public int getId() {    return id;}public void setId(int id) {    this.id = id;}public String getProject_id() {    return projectId;}public void setProject_id(String project_id) {    this.projectId = project_id;}public String getStage() {    return stage;}public void setStage(String stage) {    this.stage = stage;}public Integer getNo() {    return no;}public void setNo(Integer no) {    this.no = no;}public String getProjectId() {    return projectId;}public void setProjectId(String projectId) {    this.projectId = projectId;}public Integer getMonths() {    return months;}public void setMonths(Integer months) {    this.months = months;}public Integer getYears() {    return years;}public void setYears(Integer years) {    this.years = years;}public Integer getCount() {    return count;}public void setCount(Integer count) {    this.count = count;}    }這是我的存儲(chǔ)庫:    @Repository    public interface ViewDisbursementRepository extends     JpaRepository<ViewDisbursement, Integer> {List<ViewDisbursement> findByProjectIdandYear(String projectId,     Integer years);    }
查看完整描述

2 回答

?
元芳怎么了

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超7個(gè)贊

您的字段名稱是:

@Column(name="years")
private Integer years;

你有同樣的適當(dāng)?shù)奈鼩鈩┖臀鼩鈩?/p>

并且您在存儲(chǔ)庫中使用查詢方法為:

List<ViewDisbursement> findByProjectIdandYear(String projectId, Integer years);

findByProjectIdAndYears最后應(yīng)該是一個(gè)'s'。然后只有它會(huì)匹配字段名稱。還有'and'而不是'And'。


查看完整回答
反對 回復(fù) 2023-05-10
?
慕萊塢森

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊

使用

findByProductIdAndYears(String?projectId,?Integer?years)
  • 當(dāng)對多個(gè)參數(shù)使用 findBy 時(shí),應(yīng)該使用 And 來完成,我們必須保留 A 而不是 a。

  • 我們必須使用實(shí)體中定義的名稱(因?yàn)檫@里我們有 Year,應(yīng)該是 Years)

例如

@Entity

private String productId;


findById(String id) //wiil not work

findByProductId(String id) //work

?@Repository

? ? public interface ViewDisbursementRepository extends JpaRepository<ViewDisbursement, Integer> {


? ? List<ViewDisbursement> findByProjectIdAndYears(String projectId, Integer years);


? ? }

除了和/或


帶有謂詞 IsStartingWith、StartingWith、StartsWith、IsEndingWith"、EndingWith、EndsWith、IsNotContaining、NotContaining、NotContains、IsContaining、Containing、包含這些查詢的相應(yīng)參數(shù)的派生查詢將被清理。


查看完整回答
反對 回復(fù) 2023-05-10
  • 2 回答
  • 0 關(guān)注
  • 165 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號