提交 8279e992 编写于 作者: Q qinyingjie

fix:微服务代码

上级 b941f0aa
...@@ -35,6 +35,13 @@ ...@@ -35,6 +35,13 @@
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
...@@ -76,7 +76,7 @@ public class Result<T> implements Serializable { ...@@ -76,7 +76,7 @@ public class Result<T> implements Serializable {
} }
public static Result<Object> ok(String msg) { public static Result<Object> ok(String msg) {
Result<Object> r = new Result<Object>(); Result<Object> r = new Result<>();
r.setSuccess(true); r.setSuccess(true);
r.setCode(CommonConstant.SC_OK_200); r.setCode(CommonConstant.SC_OK_200);
r.setMessage(msg); r.setMessage(msg);
......
...@@ -34,6 +34,11 @@ ...@@ -34,6 +34,11 @@
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>
......
...@@ -23,6 +23,12 @@ ...@@ -23,6 +23,12 @@
<version>1.0.0</version> <version>1.0.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
...@@ -57,14 +63,6 @@ ...@@ -57,14 +63,6 @@
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
package com.kwan.springcloud.controller; 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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.serviceregistry.Registration; 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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -22,14 +24,15 @@ public class HelloController { ...@@ -22,14 +24,15 @@ public class HelloController {
private Registration registration; 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<ServiceInstance> instances = client.getInstances(registration.getServiceId()); List<ServiceInstance> instances = client.getInstances(registration.getServiceId());
log.info(JSONArray.toJSONString(instances));
log.info(new Gson().toJson(instances)); return Result.ok(instances);
return "hello world";
} }
} }
......
package com.kwan.springcloud.controller; package com.kwan.springcloud.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kwan.springcloud.entity.KwanGoodsInfo; import com.kwan.springcloud.entity.KwanGoodsInfo;
import com.kwan.springcloud.response.Result; import com.kwan.springcloud.response.Result;
import com.kwan.springcloud.service.KwanGoodsInfoService; import com.kwan.springcloud.service.KwanGoodsInfoService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
/**
* (KwanGoodsInfo)表控制层
*
* @author makejava
* @since 2023-01-08 10:21:26
*/
@RestController @RestController
@RequestMapping("kwanGoodsInfo") @RequestMapping("kwanGoodsInfo")
public class KwanGoodsInfoController { public class KwanGoodsInfoController {
...@@ -45,7 +39,7 @@ public class KwanGoodsInfoController { ...@@ -45,7 +39,7 @@ public class KwanGoodsInfoController {
* @param id 主键 * @param id 主键
* @return 单条数据 * @return 单条数据
*/ */
@GetMapping("{id}") @GetMapping(value = "{id}", produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE)
public Result selectOne(@PathVariable Serializable id) { public Result selectOne(@PathVariable Serializable id) {
return Result.ok(this.kwanGoodsInfoService.getById(id)); return Result.ok(this.kwanGoodsInfoService.getById(id));
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册