diff --git a/springcloud-service-common/pom.xml b/springcloud-service-common/pom.xml index 4eed6cf69a1a14f9e90d9e9d81708c45a211d8bf..49f398a53f41c2ca260c1da60440cfc86f0d05a6 100644 --- a/springcloud-service-common/pom.xml +++ b/springcloud-service-common/pom.xml @@ -35,6 +35,13 @@ true + + + com.alibaba + fastjson + 1.2.83 + + \ No newline at end of file diff --git a/springcloud-service-common/src/main/java/com/kwan/springcloud/response/Result.java b/springcloud-service-common/src/main/java/com/kwan/springcloud/response/Result.java index 37b23ad0c77857ad4f7042cc078fc2f0b9da2864..ab10397e53a6764dd54a75511ef3c3aa5088b8ee 100644 --- a/springcloud-service-common/src/main/java/com/kwan/springcloud/response/Result.java +++ b/springcloud-service-common/src/main/java/com/kwan/springcloud/response/Result.java @@ -76,7 +76,7 @@ public class Result implements Serializable { } public static Result ok(String msg) { - Result r = new Result(); + Result r = new Result<>(); r.setSuccess(true); r.setCode(CommonConstant.SC_OK_200); r.setMessage(msg); diff --git a/springcloud-service-eureka/pom.xml b/springcloud-service-eureka/pom.xml index 86844d7ab5d25d0469773f8c137c9443c4ef04f1..0666cba0749a0a340d3874b2733551d7ba6b49f1 100644 --- a/springcloud-service-eureka/pom.xml +++ b/springcloud-service-eureka/pom.xml @@ -34,6 +34,11 @@ + + org.springframework.boot + spring-boot-starter-actuator + + diff --git a/springcloud-service-goods/pom.xml b/springcloud-service-goods/pom.xml index b2396b617df7ec4a7481b87e4b81047dab738dbc..43a7b29eea67a2a59d90d28677bfb723df322c01 100644 --- a/springcloud-service-goods/pom.xml +++ b/springcloud-service-goods/pom.xml @@ -23,6 +23,12 @@ 1.0.0 compile + + + org.springframework.boot + spring-boot-starter-web + + org.springframework.boot spring-boot-starter-test @@ -57,14 +63,6 @@ org.springframework.cloud spring-cloud-starter-netflix-eureka-server - - - com.google.code.gson - gson - 2.9.0 - - - diff --git a/springcloud-service-goods/src/main/java/com/kwan/springcloud/controller/HelloController.java b/springcloud-service-goods/src/main/java/com/kwan/springcloud/controller/HelloController.java index e4c225c16dc483e7b8b4ceb5c9667eb8969ea2de..71ebddacf6ff9c3265052b22fe154c5191375241 100644 --- a/springcloud-service-goods/src/main/java/com/kwan/springcloud/controller/HelloController.java +++ b/springcloud-service-goods/src/main/java/com/kwan/springcloud/controller/HelloController.java @@ -1,12 +1,14 @@ package com.kwan.springcloud.controller; -import com.google.gson.Gson; +import com.alibaba.fastjson.JSONArray; +import com.kwan.springcloud.response.Result; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.serviceregistry.Registration; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -22,14 +24,15 @@ public class HelloController { private Registration registration; - @RequestMapping("/hello") - public String index() { - + /** + * produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE + * 解决不是json显示问题 + */ + @RequestMapping(value = "/hello", produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE) + public Result index() { List instances = client.getInstances(registration.getServiceId()); - - log.info(new Gson().toJson(instances)); - - return "hello world"; + log.info(JSONArray.toJSONString(instances)); + return Result.ok(instances); } } diff --git a/springcloud-service-goods/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java b/springcloud-service-goods/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java index f47a0c9f244e68a5de1a4aa224fe3a6f2aa5d57b..35e64f9ff8476527fcf3c5bbad6a0eb175cf52b7 100644 --- a/springcloud-service-goods/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java +++ b/springcloud-service-goods/src/main/java/com/kwan/springcloud/controller/KwanGoodsInfoController.java @@ -1,23 +1,17 @@ package com.kwan.springcloud.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; - import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.kwan.springcloud.entity.KwanGoodsInfo; import com.kwan.springcloud.response.Result; import com.kwan.springcloud.service.KwanGoodsInfoService; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.io.Serializable; import java.util.List; -/** - * (KwanGoodsInfo)表控制层 - * - * @author makejava - * @since 2023-01-08 10:21:26 - */ @RestController @RequestMapping("kwanGoodsInfo") public class KwanGoodsInfoController { @@ -45,7 +39,7 @@ public class KwanGoodsInfoController { * @param id 主键 * @return 单条数据 */ - @GetMapping("{id}") + @GetMapping(value = "{id}", produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE) public Result selectOne(@PathVariable Serializable id) { return Result.ok(this.kwanGoodsInfoService.getById(id)); }