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

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

如何在實(shí)例化 Java Spring Webflux 時(shí)修改或更新 POJO 模型

如何在實(shí)例化 Java Spring Webflux 時(shí)修改或更新 POJO 模型

互換的青春 2023-06-04 15:38:42
我正在使用適用于 Java 的 Google Maps Geocoding API。我有一個(gè)基本地址 POJO。我想要做的是在lat 屬性上運(yùn)行createLatCord方法,主體響應(yīng)是地址、城市、州和郵政編碼我不知道我還應(yīng)該在哪里修改,在模型本身,Controller或Service/Repository處?方法我需要在創(chuàng)建時(shí)在 lat 屬性上運(yùn)行private double createLatCord() throws InterruptedException, ApiException, IOException {    GeoApiContext context = new     GeoApiContext.Builder().apiKey("abc").build();    GeocodingResult[] results = GeocodingApi.geocode(context, address+city+state+zipcode).await();//  Gson gson = new GsonBuilder().setPrettyPrinting().create();    return results[0].geometry.location.lat;}模型 :// all the imports ...public class User {    private String address;    private String zipcode;    private String city;    private String state;    private double lat; // <-- Run createLatCord method on this property    @Id    private String id;    public User() {    }    public User(String address, String zipcode, String city, String state, double lat) throws InterruptedException, ApiException, IOException {        this.address = address;        this.city = city;        this.state = state;        this.zipcode = zipcode;        this.lat = lat;    }// GETTERS AND SETTERS HERE FOR THE ABOVE// Leaving it out cause it's alot}控制器:@PostMapping(path = "", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)public Mono<User> createUser(@RequestBody Mono<User> user) {     return userService.createUser(user);}服務(wù)/存儲(chǔ)庫(kù):@Overridepublic Mono<User> createUser(Mono<User> userMono) {   return reactiveMongoOperations.save(userMono);}
查看完整描述

1 回答

?
慕姐4208626

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

如果我做對(duì)了,你想在保存用戶時(shí)更新緯度。由于您的服務(wù)已經(jīng)收到一個(gè) Mono,您可以對(duì)其進(jìn)行平面映射以調(diào)用 google api,然后調(diào)用存儲(chǔ)庫(kù)。它會(huì)是這樣的:

@Override
public Mono<User> createUser(Mono<User> userMono) {
    return userMono.flatMap(user -> 
                            methodToCallGoogleApiAndSetValueToUser(user))
                   .subscribe(reactiveMongoOperations::save)
}

有一點(diǎn)是methodToCallGoogleApiAndSetValueToUser應(yīng)該返回一個(gè)帶有更新用戶的 Mono。

希望這可能會(huì)有所幫助!


查看完整回答
反對(duì) 回復(fù) 2023-06-04
  • 1 回答
  • 0 關(guān)注
  • 147 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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