commit 64d48dc994f85f8d2711a895049e5de7f73ecc6d
Author: An Yong Shuai <1539893812@qq.com>
Date: Wed Jun 19 17:34:41 2024 +0800
aaa
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..549e00a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,33 @@
+HELP.md
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..3f1f950
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,99 @@
+
+
+ 4.0.0
+ com.health.cloud.consultation
+ httptest
+ 0.0.1-SNAPSHOT
+ httptest
+ httptest
+
+ 1.8
+ UTF-8
+ UTF-8
+ 2.6.13
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jdbc
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+ 2.2.2
+
+
+ com.mysql
+ mysql-connector-j
+ runtime
+
+
+ com.alibaba.fastjson2
+ fastjson2
+ 2.0.50
+
+
+
+ org.projectlombok
+ lombok
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework
+ spring-web
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-dependencies
+ ${spring-boot.version}
+ pom
+ import
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ 1.8
+ 1.8
+ UTF-8
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+ ${spring-boot.version}
+
+ com.health.cloud.consultation.httptest.HttptestApplication
+ true
+
+
+
+ repackage
+
+ repackage
+
+
+
+
+
+
+
+
diff --git a/src/main/java/com/health/cloud/consultation/httptest/HttptestApplication.java b/src/main/java/com/health/cloud/consultation/httptest/HttptestApplication.java
new file mode 100644
index 0000000..7c568e4
--- /dev/null
+++ b/src/main/java/com/health/cloud/consultation/httptest/HttptestApplication.java
@@ -0,0 +1,11 @@
+package com.health.cloud.consultation.httptest;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class HttptestApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(HttptestApplication.class, args);
+ }
+}
diff --git a/src/main/java/com/health/cloud/consultation/httptest/controller/OneController.java b/src/main/java/com/health/cloud/consultation/httptest/controller/OneController.java
new file mode 100644
index 0000000..1544f46
--- /dev/null
+++ b/src/main/java/com/health/cloud/consultation/httptest/controller/OneController.java
@@ -0,0 +1,23 @@
+package com.health.cloud.consultation.httptest.controller;
+
+import com.health.cloud.consultation.httptest.sync.TestHttpPost;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 接口一
+ */
+@RestController
+public class OneController {
+ @Autowired
+ private TestHttpPost testHttpPost;
+
+ /**
+ * 添加接口一 数据到数据库
+ */
+ @GetMapping("/addUser")
+ public void addUser(){
+ testHttpPost.testDoSome();
+ }
+}
diff --git a/src/main/java/com/health/cloud/consultation/httptest/domain/Result.java b/src/main/java/com/health/cloud/consultation/httptest/domain/Result.java
new file mode 100644
index 0000000..376ede1
--- /dev/null
+++ b/src/main/java/com/health/cloud/consultation/httptest/domain/Result.java
@@ -0,0 +1,10 @@
+package com.health.cloud.consultation.httptest.domain;
+
+import lombok.Data;
+
+@Data
+public class Result {
+ private Long code;
+ private String msg;
+ private Object data;
+}
diff --git a/src/main/java/com/health/cloud/consultation/httptest/domain/User.java b/src/main/java/com/health/cloud/consultation/httptest/domain/User.java
new file mode 100644
index 0000000..c960d95
--- /dev/null
+++ b/src/main/java/com/health/cloud/consultation/httptest/domain/User.java
@@ -0,0 +1,11 @@
+package com.health.cloud.consultation.httptest.domain;
+
+import com.alibaba.fastjson2.annotation.JSONField;
+import lombok.Data;
+
+@Data
+public class User {
+ private Long id;
+ @JSONField(name = "package")
+ private String packages;
+}
diff --git a/src/main/java/com/health/cloud/consultation/httptest/mapper/UserMapper.java b/src/main/java/com/health/cloud/consultation/httptest/mapper/UserMapper.java
new file mode 100644
index 0000000..b22ac85
--- /dev/null
+++ b/src/main/java/com/health/cloud/consultation/httptest/mapper/UserMapper.java
@@ -0,0 +1,9 @@
+package com.health.cloud.consultation.httptest.mapper;
+
+import com.health.cloud.consultation.httptest.domain.User;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface UserMapper {
+ void insertUser(User user);
+}
diff --git a/src/main/java/com/health/cloud/consultation/httptest/run/One.java b/src/main/java/com/health/cloud/consultation/httptest/run/One.java
new file mode 100644
index 0000000..a45c6c3
--- /dev/null
+++ b/src/main/java/com/health/cloud/consultation/httptest/run/One.java
@@ -0,0 +1,53 @@
+package com.health.cloud.consultation.httptest.run;
+
+import com.alibaba.fastjson2.JSON;
+import com.health.cloud.consultation.httptest.domain.Result;
+import com.health.cloud.consultation.httptest.domain.User;
+import com.health.cloud.consultation.httptest.mapper.UserMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+@Component
+public class One {
+ @Autowired
+ private UserMapper userMapper;
+
+ public void insert() {
+ // 1.请求URL
+ String postUrl = "http://47.109.47.113:9703/admin/datadepartment/datadepartmentteamlist?secretkey=43112785d4723cfed95caf0fbc068044";
+ // 2.请求参数JSON格式
+ Map map = new HashMap<>();
+ String json = JSON.toJSONString(map);
+ // 3.创建RestTemplate
+ RestTemplate restTemplate = new RestTemplate();
+ // 4.设置RestTemplate参数(请求头和body)
+ HttpHeaders headers = new HttpHeaders();
+ MediaType mediaType = MediaType.parseMediaType("application/json; charset=UTF-8");
+ headers.setContentType(mediaType);
+ headers.add("Accept", "application/json");
+ HttpEntity entity = new HttpEntity<>(json, headers);
+ // 5.使用RestTemplate发起请求与接收返回值
+ String resultData = restTemplate.postForObject(postUrl, entity, String.class);
+ //System.out.println("从服务端返回结果: " + resultData);
+ Result result = JSON.parseObject(resultData, Result.class);
+ if(result.getCode()==0){
+ System.out.println("数据为"+result.getData());
+ }
+ Object data = result.getData();
+ if(userMapper==null){
+ System.out.println("aaa");
+ }
+ List users = JSON.parseArray(data.toString(), User.class);
+ for (User user : users) {
+ userMapper.insertUser(user);
+ }
+
+ }
+}
diff --git a/src/main/java/com/health/cloud/consultation/httptest/sync/TestHttpPost.java b/src/main/java/com/health/cloud/consultation/httptest/sync/TestHttpPost.java
new file mode 100644
index 0000000..e543233
--- /dev/null
+++ b/src/main/java/com/health/cloud/consultation/httptest/sync/TestHttpPost.java
@@ -0,0 +1,60 @@
+package com.health.cloud.consultation.httptest.sync;
+
+import com.alibaba.fastjson2.JSON;
+import com.health.cloud.consultation.httptest.domain.Result;
+import com.health.cloud.consultation.httptest.domain.User;
+import com.health.cloud.consultation.httptest.mapper.UserMapper;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+
+/**
+ * @Author gyc
+ * @ClassName TestHttp
+ * @Date 2024/5/30 下午5:46
+ */
+//post请求无参
+@Service
+public class TestHttpPost {
+ private final UserMapper userMapper;
+
+ public TestHttpPost(UserMapper userMapper) {
+ this.userMapper = userMapper;
+ }
+ public void testDoSome(){
+ // 1.请求URL
+ String postUrl = "http://47.109.47.113:9703/admin/datadepartment/datadepartmentteamlist?secretkey=43112785d4723cfed95caf0fbc068044";
+ // 2.请求参数JSON格式
+ Map map = new HashMap<>();
+ String json = JSON.toJSONString(map);
+ // 3.创建RestTemplate
+ RestTemplate restTemplate = new RestTemplate();
+ // 4.设置RestTemplate参数(请求头和body)
+ HttpHeaders headers = new HttpHeaders();
+ MediaType mediaType = MediaType.parseMediaType("application/json; charset=UTF-8");
+ headers.setContentType(mediaType);
+ headers.add("Accept", "application/json");
+ HttpEntity entity = new HttpEntity<>(json, headers);
+ // 5.使用RestTemplate发起请求与接收返回值
+ String resultData = restTemplate.postForObject(postUrl, entity, String.class);
+ //System.out.println("从服务端返回结果: " + resultData);
+ Result result = JSON.parseObject(resultData, Result.class);
+ if(result.getCode()==0){
+ System.out.println("数据为"+result.getData());
+ }
+ Object data = result.getData();
+
+ List users = JSON.parseArray(data.toString(), User.class);
+ for (User user : users) {
+ userMapper.insertUser(user);
+ }
+ }
+}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
new file mode 100644
index 0000000..e407cad
--- /dev/null
+++ b/src/main/resources/application.properties
@@ -0,0 +1,9 @@
+
+server.port=8080
+mybatis.typeAliasesPackage=com.health.cloud.consultation.httptest.domain
+mybatis.mapperLocations=classpath*:mapper/**/*.xml
+mybatis.configuration.map-underscore-to-camel-case=true
+spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+spring.datasource.url=jdbc:mysql://localhost:3306/ays?serverTimezone=GMT%2B8
+spring.datasource.username=root
+spring.datasource.password=ays@123
diff --git a/src/main/resources/mapper/LoginMapper.xml b/src/main/resources/mapper/LoginMapper.xml
new file mode 100644
index 0000000..c758f7a
--- /dev/null
+++ b/src/main/resources/mapper/LoginMapper.xml
@@ -0,0 +1,9 @@
+
+
+
+
+ INSERT INTO `ays`.`user` (`id`, `name`) VALUES (#{id}, #{namea})
+
+
diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html
new file mode 100644
index 0000000..f67da0a
--- /dev/null
+++ b/src/main/resources/static/index.html
@@ -0,0 +1,6 @@
+
+
+hello word!!!
+this is a html page
+
+
diff --git a/src/test/java/com/health/cloud/consultation/httptest/HttptestApplicationTests.java b/src/test/java/com/health/cloud/consultation/httptest/HttptestApplicationTests.java
new file mode 100644
index 0000000..439ab0a
--- /dev/null
+++ b/src/test/java/com/health/cloud/consultation/httptest/HttptestApplicationTests.java
@@ -0,0 +1,13 @@
+package com.health.cloud.consultation.httptest;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+class HttptestApplicationTests {
+
+ @Test
+ void contextLoads() {
+ }
+
+}