161250169 6 лет назад
Родитель
Сommit
e66bc8eaa2
1 измененных файлов с 54 добавлено и 0 удалено
  1. 54 0
      src/main/java/com/es/demo/proxy/Neo4jProxyController.java

+ 54 - 0
src/main/java/com/es/demo/proxy/Neo4jProxyController.java

@@ -0,0 +1,54 @@
+package com.es.demo.proxy;
+
+import com.es.demo.back.ChoiceQuestion;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.MediaType;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.http.*;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/api/neo")
+public class Neo4jProxyController {
+
+
+
+    @PostMapping(value = "/getAll",consumes="application/json", produces="application/json")
+    public List getAll(@RequestBody Map body) {
+        System.out.println(body.toString());
+        return proxyToNeo4j(body);
+    }
+    private List proxyToNeo4j(Map body){
+
+        List ret= null;
+        try {
+            ret = sendPostRequest("http://bok-neo-backend.seecoder.cn/api/user/getAll",body);
+        } catch (JsonProcessingException e) {
+            System.out.println(e.getMessage());
+            e.printStackTrace();
+        }
+        return ret;
+    }
+
+    public static List sendPostRequest(String url, Map<String, String> params) throws JsonProcessingException {
+        RestTemplate client = new RestTemplate();
+        HttpHeaders headers = new HttpHeaders();
+        HttpMethod method = HttpMethod.POST;
+        headers.setContentType(MediaType.APPLICATION_JSON);
+        HttpEntity<Map> requestEntity = new HttpEntity<>(params, headers);
+        ResponseEntity ret = client.postForEntity(url, requestEntity, List.class);
+        return (List) ret.getBody();
+    }
+}