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

fix:微服务代码

上级 b941f0aa
......@@ -35,6 +35,13 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -76,7 +76,7 @@ public class Result<T> implements Serializable {
}
public static Result<Object> ok(String msg) {
Result<Object> r = new Result<Object>();
Result<Object> r = new Result<>();
r.setSuccess(true);
r.setCode(CommonConstant.SC_OK_200);
r.setMessage(msg);
......
......@@ -34,6 +34,11 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
......
......@@ -23,6 +23,12 @@
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
......@@ -57,14 +63,6 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
</dependency>
</dependencies>
<build>
......
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<ServiceInstance> instances = client.getInstances(registration.getServiceId());
log.info(new Gson().toJson(instances));
return "hello world";
log.info(JSONArray.toJSONString(instances));
return Result.ok(instances);
}
}
......
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));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册