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

為了賬號安全,請及時綁定郵箱和手機立即綁定

建議更新jar包

老師啊,能不能把url里面的訪問網(wǎng)址也改成參數(shù)傳入后更新個jar包呀?這個API的訪問參數(shù)有變化了:?

http://img1.sycdn.imooc.com//600d7b82000105b703690054.jpg

正在回答

2 回答

購買的免費的api和視頻上的一致就不會有這個問題,如果一定要變url的話就把jar包里用到的文件復制出來,再修改url.

2 回復 有任何疑惑可以回復我~
#1

朱智琳 提問者

嗯,就是這么操作的。
2021-01-26 回復 有任何疑惑可以回復我~
#2

小樓倚月聽微風 回復 朱智琳 提問者

jar包里的文件是只讀的,問一下怎么改呢
2021-02-15 回復 有任何疑惑可以回復我~
可以新創(chuàng)建一個temp_WeatherUtilsImpl.java文件,來重寫WeatherUtilsImpl類,此處僅以24h查詢?yōu)槔?

package?com.imooc.weather;

import?com.google.gson.FieldNamingPolicy;
import?com.google.gson.Gson;
import?com.google.gson.GsonBuilder;
import?com.google.gson.reflect.TypeToken;
import?com.imooc.weather.impl.WeatherUtilsImpl;
import?ognl.Ognl;
import?ognl.OgnlContext;
import?ognl.OgnlException;
import?okhttp3.Call;
import?okhttp3.OkHttpClient;
import?okhttp3.Request;
import?okhttp3.Response;

import?java.io.IOException;
import?java.util.ArrayList;
import?java.util.List;
import?java.util.Map;

public?class?temp_WeatherUtilsImpl?extends?WeatherUtilsImpl?{
????//重載或重寫WeatherUtilsImpl.java
????private?<T>?T?getValue(Object?map,?String?path,?Class<T>?clazz)?{
????????try?{
????????????OgnlContext?context?=?new?OgnlContext();
????????????context.setRoot(map);
????????????T?value?=?(T)?Ognl.getValue(path,?context,?context.getRoot());
????????????return?value;
????????}?catch?(Exception?e)?{
????????????throw?new?RuntimeException(e);
????????}
????}
????public?List<HourWeather>?w24h(String?appCode,?String?area)?{
????????List<HourWeather>?resultList?=?new?ArrayList<HourWeather>();
????????try?{
????????????//新建查詢請求
????????????OkHttpClient?client?=?new?OkHttpClient();
????????????Request?request?=?new?Request.Builder()
????????????????????.get()
????????????????????.url("https://ali-weather.showapi.com/hour24?area="?+?area)
????????????????????.header("Authorization",?"APPCODE?"?+?appCode)
????????????????????.build();
????????????Call?call?=?client.newCall(request);
????????????Response?response?=?call.execute();
????????????Gson?gson?=?new?GsonBuilder()
????????????????????.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
????????????????????.create();
????????????//獲取服務器返回數(shù)據(jù)
????????????String?resBody?=?response.body().string();
????????????Map?result?=?gson.fromJson(resBody,?new?TypeToken<Map>()?{
????????????}.getType());
????????????//包裝為對象集合
????????????List<Map<String,?String>>?hourList?=?this.getValue(result,?"showapi_res_body.hourList",?ArrayList.class);
????????????//如果沒有找到對應地區(qū)天氣數(shù)據(jù),返回空的List列表
????????????if(hourList?==?null?||?hourList.size()?==?0){
????????????????return?new?ArrayList<HourWeather>();
????????????}
????????????for?(Map<String,?String>?hour?:?hourList)?{
????????????????HourWeather?hourWeather?=?new?HourWeather();
????????????????hourWeather.setYear(hour.get("time").substring(0,?4));
????????????????hourWeather.setMonth(hour.get("time").substring(4,?6));
????????????????hourWeather.setDay(hour.get("time").substring(6,?8));
????????????????hourWeather.setHour(hour.get("time").substring(8,?10));
????????????????hourWeather.setWindDirection(hour.get("wind_direction"));
????????????????hourWeather.setWindPower(hour.get("wind_power"));
????????????????hourWeather.setWeather(hour.get("weather"));
????????????????hourWeather.setTemperature(hour.get("temperature"));
????????????????resultList.add(hourWeather);
????????????}

????????}?catch?(Exception?e)?{
????????????throw?new?RuntimeException(e);
????????}
????????return?resultList;

????}

????public?static?void?main(String[]?args)?throws?IOException,?OgnlException?{
????????List<DayWeather>?list2?=?new?WeatherUtilsImpl().w3d("28a8e0cdea484fdd9cba138a72bc1778",?"DASDSADSA");
????????System.out.println(list2);
????}
}

這是Application.java:

package?com.imooc.weather;

import?com.imooc.weather.impl.WeatherUtilsImpl;

import?java.util.List;
import?java.util.Scanner;

public?class?Application?{
????public?static?void?main(String[]?args)?{
????????System.out.println("查詢最近天氣預報");
????????System.out.println("輸入1:?查詢未來24小時天氣預報");
????????System.out.println("輸入2:?查詢未來3天天氣預報");
????????System.out.println("輸入3:?查詢未來7天天氣預報");
????????System.out.print("請輸入您的選擇:?");
????????Scanner?scanner?=?new?Scanner(System.in);
????????int?i?=?scanner.nextInt();
????????System.out.println("用戶輸入數(shù)字:?"?+?i);

????????if(i?==?1){
????????????System.out.print("請輸入城市名稱查詢未來24小時天氣預報:?");
????????????String?city?=?scanner.next();
????????????temp_WeatherUtilsImpl?weatherUtils?=?new?temp_WeatherUtilsImpl();
????????????List<HourWeather>?weatherList1?=?weatherUtils.w24h("5f94543d72c44591bf4897e0f3d622ea",?city);
????????????System.out.println(weatherList1);
????????}
????}
}


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Java入門第二季 升級版
  • 參與學習       531090    人
  • 解答問題       6276    個

課程升級!以終為始告別枯燥,在開發(fā)和重構中體會Java面向對象編程的奧妙

進入課程

建議更新jar包

我要回答 關注問題
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

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