1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| package com.bohu.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.bohu.pojo.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.*; import org.springframework.stereotype.Service; import com.bohu.entity.PageResult; import com.bohu.entity.YmlConfig;
import com.bohu.service.HJ212Service; import lombok.Data; import org.springframework.context.annotation.Configuration; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.client.RestTemplate;
@Service @Transactional @Configuration @Data public class HJ212ServiceImpl implements HJ212Service {
@Autowired private RestTemplate restTemplate;
@Autowired private YmlConfig ymlConfig;
@Override public PageResult gethj212() { System.out.println("ccccccccc"); String json = doGetWith1(String.valueOf(11)); System.out.println(json); return null; }
public String doGetWith1(String url){ url = "https://cover.yixinda.com/cover-device?companyId=111"; ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); String body = responseEntity.getBody(); return body; }
public User doGetWith2(String url){ User user = restTemplate.getForObject(url, User.class); return user; }
public String doPostWith1(String url){ User user = new User(); ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, user, String.class); String body = responseEntity.getBody(); return body; }
public String doPostWith2(String url){ User user = new User(); String body = restTemplate.postForObject(url, user, String.class); return body; }
public String doExchange(String url, Integer age, String name){ HttpHeaders headers = new HttpHeaders(); String token = "asdfaf2322"; headers.add("authorization", token); headers.setContentType(MediaType.APPLICATION_JSON);
JSONObject obj = new JSONObject(); obj.put("age", age); obj.put("name", name);
HttpEntity<JSONObject> request = new HttpEntity<>(obj, headers); String s = request.toString(); return s; }
}
|