gpt4 book ai didi

java - 使用传递参数的第三方 RESTful API

转载 作者:行者123 更新时间:2023-12-02 02:53:25 26 4
gpt4 key购买 nike

我需要使用第三方 RESTful API。这是我的 Controller 类:

@Controller
public class BrokerController {

@RequestMapping(value = "/broker", method = RequestMethod.POST)
public @ResponseBody MyPojo brokers(@RequestBody BrokerRequest brokerRequest){

RestTemplate restTemplate = new RestTemplate();
final String uri = "http://www.nepalipaisa.com/Modules/MarketMovers/Services/MarketMoversServices.asmx/GetTopBrokers";

MyPojo myPojo = restTemplate.postForObject(uri,brokerRequest,MyPojo.class);
return myPojo;
}

}

编辑:-我的 pojo 类:

public class MyPojo {
private String __type;
private Integer RowTotal;
private Integer StockID;
private Object CodedCompany;
private Object ClosingPrice;
private Integer Amount;
private Integer PreviousClosing;
private Integer DifferenceRS;
private Object Symbol;
private Integer Price;
private Integer Diff;
private Integer PercentageDiff;
private Object Volume;
private Integer TotalTurnOverAmount;
private String FirmName;
private Integer BrokerID;
private String BrokerCode;
private Integer TotalTransactions;
private Object Traded;
private Object MaxPrice;
private Object MinPrice;
private Object OpeningPrice;
private Object TotalShare;
private Integer NoOfTransaction;
private Integer Purchase;
private Integer Sales;
private Integer Matching;


public String get__type() {
return __type;
}

public void set__type(String __type) {
this.__type = __type;
}

public Integer getRowTotal() {
return RowTotal;
}

public void setRowTotal(Integer rowTotal) {
this.RowTotal = rowTotal;
}

public Integer getStockID() {
return StockID;
}

public void setStockID(Integer stockID) {
this.StockID = stockID;
}

public Object getCodedCompany() {
return CodedCompany;
}

public void setCodedCompany(Object codedCompany) {
this.CodedCompany = codedCompany;
}

public Object getClosingPrice() {
return ClosingPrice;
}

public void setClosingPrice(Object closingPrice) {
this.ClosingPrice = closingPrice;
}

public Integer getAmount() {
return Amount;
}

public void setAmount(Integer amount) {
this.Amount = amount;
}

public Integer getPreviousClosing() {
return PreviousClosing;
}

public void setPreviousClosing(Integer previousClosing) {
this.PreviousClosing = previousClosing;
}

public Integer getDifferenceRS() {
return DifferenceRS;
}

public void setDifferenceRS(Integer differenceRS) {
this.DifferenceRS = differenceRS;
}

public Object getSymbol() {
return Symbol;
}

public void setSymbol(Object symbol) {
this.Symbol = symbol;
}

public Integer getPrice() {
return Price;
}

public void setPrice(Integer price) {
this.Price = price;
}

public Integer getDiff() {
return Diff;
}

public void setDiff(Integer diff) {
this.Diff = diff;
}

public Integer getPercentageDiff() {
return PercentageDiff;
}

public void setPercentageDiff(Integer percentageDiff) {
this.PercentageDiff = percentageDiff;
}

public Object getVolume() {
return Volume;
}

public void setVolume(Object volume) {
this.Volume = volume;
}

public Integer getTotalTurnOverAmount() {
return TotalTurnOverAmount;
}

public void setTotalTurnOverAmount(Integer totalTurnOverAmount) {
this.TotalTurnOverAmount = totalTurnOverAmount;
}

public String getFirmName() {
return FirmName;
}

public void setFirmName(String firmName) {
this.FirmName = firmName;
}

public Integer getBrokerID() {
return BrokerID;
}

public void setBrokerID(Integer brokerID) {
this.BrokerID = brokerID;
}

public String getBrokerCode() {
return BrokerCode;
}

public void setBrokerCode(String brokerCode) {
this.BrokerCode = brokerCode;
}

public Integer getTotalTransactions() {
return TotalTransactions;
}

public void setTotalTransactions(Integer totalTransactions) {
this.TotalTransactions = totalTransactions;
}

public Object getTraded() {
return Traded;
}

public void setTraded(Object traded) {
this.Traded = traded;
}

public Object getMaxPrice() {
return MaxPrice;
}

public void setMaxPrice(Object maxPrice) {
this.MaxPrice = maxPrice;
}

public Object getMinPrice() {
return MinPrice;
}

public void setMinPrice(Object minPrice) {
this.MinPrice = minPrice;
}

public Object getOpeningPrice() {
return OpeningPrice;
}

public void setOpeningPrice(Object openingPrice) {
this.OpeningPrice = openingPrice;
}

public Object getTotalShare() {
return TotalShare;
}

public void setTotalShare(Object totalShare) {
this.TotalShare = totalShare;
}

public Integer getNoOfTransaction() {
return NoOfTransaction;
}

public void setNoOfTransaction(Integer noOfTransaction) {
this.NoOfTransaction = noOfTransaction;
}

public Integer getPurchase() {
return Purchase;
}

public void setPurchase(Integer purchase) {
this.Purchase = purchase;
}

public Integer getSales() {
return Sales;
}

public void setSales(Integer sales) {
this.Sales = sales;
}

public Integer getMatching() {
return Matching;
}

public void setMatching(Integer matching) {
this.Matching = matching;
}
}

我需要使用的JSON,即下面给出的确切结果:

{
"d": [
{
"__type": "SageFrame.MarketMovers.MarketInfo",
"RowTotal": 0,
"StockID": 0,
"CodedCompany": null,
"ClosingPrice": null,
"Amount": 0,
"PreviousClosing": 0,
"DifferenceRS": 0,
"Symbol": null,
"Price": 0,
"Diff": 0,
"PercentageDiff": 0,
"Volume": null,
"TotalTurnOverAmount": 109969058,
"FirmName": "Vision Securities Pvt. Ltd.",
"BrokerID": 0,
"BrokerCode": "34",
"TotalTransactions": 0,
"Traded": null,
"MaxPrice": null,
"MinPrice": null,
"OpeningPrice": null,
"TotalShare": null,
"NoOfTransaction": 0,
"Purchase": 70691939,
"Sales": 39277119,
"Matching": 6381555
},
{
"__type": "SageFrame.MarketMovers.MarketInfo",
"RowTotal": 0,
"StockID": 0,
"CodedCompany": null,
"ClosingPrice": null,
"Amount": 0,
"PreviousClosing": 0,
"DifferenceRS": 0,
"Symbol": null,
"Price": 0,
"Diff": 0,
"PercentageDiff": 0,
"Volume": null,
"TotalTurnOverAmount": 104830489,
"FirmName": "Online Securities Pvt. Ltd.",
"BrokerID": 0,
"BrokerCode": "49",
"TotalTransactions": 0,
"Traded": null,
"MaxPrice": null,
"MinPrice": null,
"OpeningPrice": null,
"TotalShare": null,
"NoOfTransaction": 0,
"Purchase": 51927902,
"Sales": 52902587,
"Matching": 3049044
}
]
}

当前当我发送带有两个参数的 POST 请求时

{
"offset":"1",
"limit":"2000"
}

我可以得到上面给出的结果。现在我需要通过我自己的 Controller 返回相同的结果。上面的 Controller 返回 MyPojo 类,每个属性上都有 null 值。

最佳答案

您始终可以尝试将第三方 API 的结果放入 map 中。

Map results = restTemplate.postForObject(uri,brokerRequest, Map.class);

或者您可以为第三方 API 创建一个新的 pojo。

ThirdPartyPojo results = restTemplate.postForObject(uri,brokerRequest, ThirdPartyPojo.class);

关于java - 使用传递参数的第三方 RESTful API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43449980/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com