aaa
commit
64d48dc994
|
@ -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/
|
|
@ -0,0 +1,99 @@
|
|||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.health.cloud.consultation</groupId>
|
||||
<artifactId>httptest</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>httptest</name>
|
||||
<description>httptest</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<spring-boot.version>2.6.13</spring-boot.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.50</version>
|
||||
</dependency>
|
||||
<!-- lombok依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<configuration>
|
||||
<mainClass>com.health.cloud.consultation.httptest.HttptestApplication</mainClass>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>repackage</id>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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<String, String> 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<String> 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<User> users = JSON.parseArray(data.toString(), User.class);
|
||||
for (User user : users) {
|
||||
userMapper.insertUser(user);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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<String, String> 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<String> 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<User> users = JSON.parseArray(data.toString(), User.class);
|
||||
for (User user : users) {
|
||||
userMapper.insertUser(user);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.health.cloud.consultation.httptest.mapper.UserMapper">
|
||||
<insert id="insertUser">
|
||||
INSERT INTO `ays`.`user` (`id`, `name`) VALUES (#{id}, #{namea})
|
||||
</insert>
|
||||
</mapper>
|
|
@ -0,0 +1,6 @@
|
|||
<html>
|
||||
<body>
|
||||
<h1>hello word!!!</h1>
|
||||
<p>this is a html page</p>
|
||||
</body>
|
||||
</html>
|
|
@ -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() {
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue