Jpa多表查詢

2021-09-12 18:42:36 字數 2496 閱讀 4135

作業題目~~~~

api###商品列表

get /sell/buyer/product/list引數無

返回]},]

}]}###建立訂單

post /sell/buyer/order/create

引數返回

}###訂單列表

get /sell/buyer/order/list

引數openid: 18eu2jwk2kse3r42e2e

page: 0 //從第0頁開始

size: 10返回,

]}###查詢訂單詳情

get /sell/buyer/order/detail

引數openid: 18eu2jwk2kse3r42e2e

orderid: 161899085773669363返回]

}}###取消訂單

post /sell/buyer/order/cancel

引數openid: 18eu2jwk2kse3r42e2e

orderid: 161899085773669363

返回###獲取openid

重定向到 /sell/wechat/authorize

引數returnurl: //【必填】

返回?openid=ozxsyw5ldcxv6h0eu67ggsxourvg

###支付訂單

重定向 /sell/pay/create

引數orderid: 161899085773669363

returnurl: /order/161899085773669363

返回/order/161899085773669363

5個表建立第乙個表

package com.zhj.foodorder.result;

import lombok.data;

@data

public class result

private result(int code, string msg) 

private result(codeandmsg codeandmsg)

}/**

* 成功時候的呼叫

* */

public static resultsuccess(t data)

/** * 失敗時候的呼叫

* */

public static resulterror(codeandmsg codeandmsg)

package com.zhj.foodorder.result;

public class codeandmsg

private codeandmsg( int code,string msg )

//通用的錯誤碼

public static codeandmsg success = new codeandmsg(0, "success");

public static codeandmsg server_error = new codeandmsg(500100, "服務端異常");

public static codeandmsg bind_error = new codeandmsg(500101, "引數校驗異常:%s");

public static codeandmsg request_illegal = new codeandmsg(500102, "請求非法");

public static codeandmsg access_limit_reached= new codeandmsg(500104, "訪問太頻繁!");

public int getcode()

public void setcode(int code)

public string getmsg()

public void setmsg(string msg) @entity

@data

public class food {

@id@generatedvalue(strategy = generationtype.identity)//自增

private long id;

private string name;

private double price;

private string description;

private string icon;

@manytoone(cascade=cascadetype.all)//解決1+n,級聯用all

@joincolumn(name=「type_item_type」)//指定外鍵名

@jsonbackreference

private typeitem typeitem;

public inte***ce typeitemrepository extends crudrepository{

public list findallbyorderbytypedesc();

第乙個建立完成了,去測試一下

結果如下

JPA多表關聯查詢

作用 就是實現使用乙個實體類物件操作或者查詢多個表的資料。回顧 配置多表聯絡查詢必須有兩個步驟 1.在實體類裡面建立表與表之間的關係。2.配置關聯關係,jpa使用註解配置 需求 指定oid查詢客戶的資訊 公司資訊 同時也查詢關聯的聯絡人資訊 配置步驟 通過客戶找聯絡人,所以再customer實體類配...

JPA 多條件 多表查詢

jpa對於簡單的查詢操作確實很給力,但是涉及到多表 多條件 分頁的場景就不是很好實現了。可行的解決方案 1 多條件 public inte ce baserepositoryextends jparepository,jpaspecificationexecutor使用specification來實...

JPA的多表複雜查詢

以乙個實體類user中的幾個屬性進行篩選。名字id 手機號這是乙個單錶的多條件複雜查詢,由於是在幾個屬性中進行篩選,其中的屬性的個數不知道有多少個,所以只需要利用specification 查詢就可以很方便的實現這個需求。下面請看 場景 頁面上通過條件篩選,查詢使用者列表 這裡有3個條件 在頁面上我...