2022/11/04 20:05 上传第9次作业题2
This commit is contained in:
commit
f811538bdc
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
14
.idea/compiler.xml
generated
Normal file
14
.idea/compiler.xml
generated
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="true" />
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="week10-work2" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
7
.idea/encodings.xml
generated
Normal file
7
.idea/encodings.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
20
.idea/jarRepositories.xml
generated
Normal file
20
.idea/jarRepositories.xml
generated
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://maven.aliyun.com/repository/public" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
14
.idea/misc.xml
generated
Normal file
14
.idea/misc.xml
generated
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
30
pom.xml
Normal file
30
pom.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>cn.czyx007.week10</groupId>
|
||||
<artifactId>week10-work2</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.20</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
46
src/main/java/cn/czyx007/week10/Driver.java
Normal file
46
src/main/java/cn/czyx007/week10/Driver.java
Normal file
@ -0,0 +1,46 @@
|
||||
package cn.czyx007.week10;
|
||||
|
||||
import cn.czyx007.week10.bean.*;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : 张宇轩
|
||||
* @createTime : 2022/11/4 - 18:53
|
||||
*/
|
||||
public class Driver {
|
||||
public static void main(String[] args) {
|
||||
try(BufferedReader br = new BufferedReader(new FileReader("src/main/resources/weather.json"))) {
|
||||
StringBuilder jsonStr = new StringBuilder();
|
||||
String aLine;
|
||||
while ((aLine= br.readLine()) != null){
|
||||
jsonStr.append(aLine);
|
||||
}
|
||||
|
||||
Response response = new Gson().fromJson(jsonStr.toString(), Response.class);
|
||||
Result result = response.getResult();
|
||||
Sk sk = result.getSk();
|
||||
Today today = result.getToday();
|
||||
List<FutureDay> future = result.getFuture();
|
||||
|
||||
// System.out.println(response);
|
||||
// System.out.println(sk);
|
||||
// System.out.println(today);
|
||||
// future.forEach(System.out::println);
|
||||
|
||||
System.out.println("当前温度:" + sk.getTemp());
|
||||
System.out.println("今日天气:" + today.getWeather());
|
||||
System.out.println("穿衣指数:" + today.getDressing_index());
|
||||
int dayCnt = 2;
|
||||
FutureDay futureDay = future.get(dayCnt - 1);
|
||||
System.out.println("未来的第二天的温度:" + futureDay.getTemperature());
|
||||
System.out.println("未来的第二天的天气:" + futureDay.getWeather());
|
||||
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
54
src/main/java/cn/czyx007/week10/bean/FutureDay.java
Normal file
54
src/main/java/cn/czyx007/week10/bean/FutureDay.java
Normal file
@ -0,0 +1,54 @@
|
||||
package cn.czyx007.week10.bean;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author : 张宇轩
|
||||
* @createTime : 2022/11/4
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
public class FutureDay {
|
||||
private String temperature;
|
||||
private String weather;
|
||||
private Map<String, String> weather_id;
|
||||
private String wind;
|
||||
private String week;
|
||||
private String date;
|
||||
|
||||
public String displayWeatherId(){
|
||||
StringBuilder weatherIdStr = new StringBuilder();
|
||||
weatherIdStr.append("\t\t\t\t\"weather_id\": {\n");
|
||||
Set<String> keys = weather_id.keySet();
|
||||
int size = keys.size();
|
||||
int cnt = 0;
|
||||
for (String key : keys) {
|
||||
weatherIdStr.append("\t\t\t\t\t\"").append(key).append("\": ");
|
||||
weatherIdStr.append("\"").append(weather_id.get(key)).append("\"");
|
||||
if (cnt++ < size-1){
|
||||
weatherIdStr.append(",");
|
||||
}
|
||||
weatherIdStr.append("\n");
|
||||
}
|
||||
weatherIdStr.append("\t\t\t\t},\n");
|
||||
return weatherIdStr.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "\t\t\t{\n" +
|
||||
"\t\t\t\t\"temperature\": " + "\"" + temperature + "\",\n" +
|
||||
"\t\t\t\t\"weather\": " + "\"" + weather + "\",\n" +
|
||||
displayWeatherId() +
|
||||
"\t\t\t\t\"wind\": " + "\"" + wind + "\",\n" +
|
||||
"\t\t\t\t\"week\": " + "\"" + week + "\",\n" +
|
||||
"\t\t\t\t\"date\": " + "\"" + date + "\"\n" +
|
||||
"\t\t\t}";
|
||||
}
|
||||
}
|
29
src/main/java/cn/czyx007/week10/bean/Response.java
Normal file
29
src/main/java/cn/czyx007/week10/bean/Response.java
Normal file
@ -0,0 +1,29 @@
|
||||
package cn.czyx007.week10.bean;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author : 张宇轩
|
||||
* @createTime : 2022/11/4
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
public class Response {
|
||||
private String resultcode;
|
||||
private String reason;
|
||||
private Result result;
|
||||
private Integer error_code;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{\n" +
|
||||
"\t\"resultcode\": " + "\"" + resultcode + "\",\n" +
|
||||
"\t\"reason\": " + "\"" + reason + "\",\n" +
|
||||
result +
|
||||
"\t\"error_code\": " + error_code + "\n" +
|
||||
"}";
|
||||
}
|
||||
}
|
43
src/main/java/cn/czyx007/week10/bean/Result.java
Normal file
43
src/main/java/cn/czyx007/week10/bean/Result.java
Normal file
@ -0,0 +1,43 @@
|
||||
package cn.czyx007.week10.bean;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : 张宇轩
|
||||
* @createTime : 2022/11/4
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
public class Result {
|
||||
private Sk sk;
|
||||
private Today today;
|
||||
private List<FutureDay> future;
|
||||
|
||||
public String displayFuture(){
|
||||
StringBuilder futureStr = new StringBuilder();
|
||||
futureStr.append("\t\t\"future\": [\n");
|
||||
for (int i = 0; i < future.size(); i++) {
|
||||
futureStr.append(future.get(i));
|
||||
if(i < future.size()-1){
|
||||
futureStr.append(",");
|
||||
}
|
||||
futureStr.append("\n");
|
||||
}
|
||||
futureStr.append("\t\t]\n");
|
||||
return futureStr.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "\t\"result\": {\n" +
|
||||
sk +
|
||||
today +
|
||||
displayFuture() +
|
||||
"\t},\n";
|
||||
}
|
||||
}
|
31
src/main/java/cn/czyx007/week10/bean/Sk.java
Normal file
31
src/main/java/cn/czyx007/week10/bean/Sk.java
Normal file
@ -0,0 +1,31 @@
|
||||
package cn.czyx007.week10.bean;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author : 张宇轩
|
||||
* @createTime : 2022/11/4
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
public class Sk {
|
||||
private String temp;
|
||||
private String wind_direction;
|
||||
private String wind_strength;
|
||||
private String humidity;
|
||||
private String time;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "\t\t\"sk\": {\n" +
|
||||
"\t\t\t\"temp\": " + "\"" + temp + "\",\n" +
|
||||
"\t\t\t\"wind_direction\": " + "\"" + wind_direction + "\",\n" +
|
||||
"\t\t\t\"wind_strength\": " + "\"" + wind_strength + "\",\n" +
|
||||
"\t\t\t\"humidity\": " + "\"" + humidity + "\",\n" +
|
||||
"\t\t\t\"time\": " + "\"" + time + "\"\n" +
|
||||
"\t\t},\n";
|
||||
}
|
||||
}
|
70
src/main/java/cn/czyx007/week10/bean/Today.java
Normal file
70
src/main/java/cn/czyx007/week10/bean/Today.java
Normal file
@ -0,0 +1,70 @@
|
||||
package cn.czyx007.week10.bean;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author : 张宇轩
|
||||
* @createTime : 2022/11/4 - 18:40
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
public class Today {
|
||||
private String city;
|
||||
private String date_y;
|
||||
private String week;
|
||||
private String temperature;
|
||||
private String weather;
|
||||
private Map<String, String> weather_id;
|
||||
private String wind;
|
||||
private String dressing_index;
|
||||
private String dressing_advice;
|
||||
private String uv_index;
|
||||
private String wash_index;
|
||||
private String travel_index;
|
||||
private String exercise_index;
|
||||
private String drying_index;
|
||||
|
||||
public String displayWeatherId(){
|
||||
StringBuilder weatherIdStr = new StringBuilder();
|
||||
weatherIdStr.append("\t\t\t\"weather_id\": {\n");
|
||||
Set<String> keys = weather_id.keySet();
|
||||
int size = keys.size();
|
||||
int cnt = 0;
|
||||
for (String key : keys) {
|
||||
weatherIdStr.append("\t\t\t\t\"").append(key).append("\": ");
|
||||
weatherIdStr.append("\"").append(weather_id.get(key)).append("\"");
|
||||
if (cnt++ < size-1){
|
||||
weatherIdStr.append(",");
|
||||
}
|
||||
weatherIdStr.append("\n");
|
||||
}
|
||||
weatherIdStr.append("\t\t\t},\n");
|
||||
return weatherIdStr.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "\t\t\"today\": {\n" +
|
||||
"\t\t\t\"city\": " + "\"" + city + "\",\n" +
|
||||
"\t\t\t\"date_y\": " + "\"" + date_y + "\",\n" +
|
||||
"\t\t\t\"week\": " + "\"" + week + "\",\n" +
|
||||
"\t\t\t\"temperature\": " + "\"" + temperature + "\",\n" +
|
||||
"\t\t\t\"weather\": " + "\"" + weather + "\",\n" +
|
||||
displayWeatherId() +
|
||||
"\t\t\t\"wind\": " + "\"" + wind + "\",\n" +
|
||||
"\t\t\t\"dressing_index\": " + "\"" + dressing_index + "\",\n" +
|
||||
"\t\t\t\"dressing_advice\": " + "\"" + dressing_advice + "\",\n" +
|
||||
"\t\t\t\"uv_index\": " + "\"" + uv_index + "\",\n" +
|
||||
"\t\t\t\"wash_index\": " + "\"" + wash_index + "\",\n" +
|
||||
"\t\t\t\"travel_index\": " + "\"" + travel_index + "\",\n" +
|
||||
"\t\t\t\"exercise_index\": " + "\"" + exercise_index + "\",\n" +
|
||||
"\t\t\t\"drying_index\": " + "\"" + drying_index + "\"\n" +
|
||||
"\t\t},\n";
|
||||
}
|
||||
}
|
57
src/main/resources/weather.json
Normal file
57
src/main/resources/weather.json
Normal file
@ -0,0 +1,57 @@
|
||||
{
|
||||
"resultcode": "200",
|
||||
"reason": "查询成功!",
|
||||
"result": {
|
||||
"sk": {
|
||||
"temp": "21",
|
||||
"wind_direction": "西风",
|
||||
"wind_strength": "2 级",
|
||||
"humidity": "4%",
|
||||
"time": "14:25"
|
||||
},
|
||||
"today": {
|
||||
"city": "武汉",
|
||||
"date_y": "2014 年 03 月 21 日",
|
||||
"week": "星期五",
|
||||
"temperature": "8℃~20℃",
|
||||
"weather": "晴转霾",
|
||||
"weather_id": {
|
||||
"fa": "00",
|
||||
"fb": "53"
|
||||
},
|
||||
"wind": "西南风微风",
|
||||
"dressing_index": "较冷",
|
||||
"dressing_advice": "建议着大衣、呢外套加毛衣、卫衣等服装。",
|
||||
"uv_index": "中等",
|
||||
"wash_index": "较适宜",
|
||||
"travel_index": "适宜",
|
||||
"exercise_index": "较适宜",
|
||||
"drying_index": ""
|
||||
},
|
||||
"future": [
|
||||
{
|
||||
"temperature": "28℃~36℃",
|
||||
"weather": "晴转多云",
|
||||
"weather_id": {
|
||||
"fa": "00",
|
||||
"fb": "01"
|
||||
},
|
||||
"wind": "南风 3-4 级",
|
||||
"week": "星期一",
|
||||
"date": "20140804"
|
||||
},
|
||||
{
|
||||
"temperature": "28℃~36℃",
|
||||
"weather": "晴转多云",
|
||||
"weather_id": {
|
||||
"fa": "00",
|
||||
"fb": "01"
|
||||
},
|
||||
"wind": "东南风 3-4 级",
|
||||
"week": "星期二",
|
||||
"date": "20140805"
|
||||
}
|
||||
]
|
||||
},
|
||||
"error_code": 0
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user