feign指定json返回html,SpringCloud之Feign传递Json参数(我的使用)

SpringCloud之Feign传递Json参数(我的使用)

java

@SpringBootApplication

@EnableDiscoveryClient

@EnableFeignClients

public class FeignClientApplication {

public static void main(String[] args) {

SpringApplication.run(FeignClientApplication.class, args);

}

}spring

@RestController

@RequestMapping("/HelloController")

public class HelloController {

private Logger logger = LoggerFactory.getLogger(getClass());

@Autowired

private HelloService helloService;

@RequestMapping(value = "/hello1", method = RequestMethod.GET)

public String hello1(@RequestHeader("username") String username, @RequestHeader("phone") String phone) {

HelloPojo helloPojo = new HelloPojo();

helloPojo.setUsername(username);

helloPojo.setPhone(phone);

String json = JSONObject.toJSONString(helloPojo);

return helloService.select1(json);

}

}app

@FeignClient(value = "SpringCloud-Feign-Server")

@RequestMapping("/HelloController")

public interface HelloService {

@RequestMapping(value = "/hello/select1", method = RequestMethod.POST,consumes = "application/json")

String select1(@RequestParam("json") String json);

}ide

pojo:spring-boot

public class HelloPojo implements Serializable {

private String username;

private String phone;

public String getUsername() {

return username;

}

public void setUsername(String username) {

this.username = username;

}

public String getPhone() {

return phone;

}

public void setPhone(String phone) {

this.phone = phone;

}

}ui

spring:

application:

name: SpringCloud-Feign-Client

eureka:

client:

service-url:

defaultZone: http://localhost:8761/eureka

instance:

instance-id:  ${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}}

server:

port: 9090

org.springframework.boot

spring-boot-starter-parent

1.5.2.RELEASE

UTF-8

UTF-8

1.8

org.springframework.boot

spring-boot-starter-test

test

org.springframework.boot

spring-boot-starter-web

org.springframework.cloud

spring-cloud-starter-eureka

1.4.5.RELEASE

org.springframework.cloud

spring-cloud-starter-feign

1.4.5.RELEASE

com.alibaba

fastjson

1.2.4

org.springframework.cloud

spring-cloud-dependencies

Dalston.RC1

pom

import

org.springframework.boot

spring-boot-maven-plugin

spring-milestones

Spring Milestones

https://repo.spring.io/milestone

false

@SpringBootApplication

@EnableDiscoveryClient

public class FeignServerApplication {

public static void main(String[] args) {

SpringApplication.run(FeignServerApplication.class, args);

}

}

@RestController

public class HelloController implements HelloService {

private Logger logger = LoggerFactory.getLogger(getClass());

@Override

public String select1(String json) {

logger.info("SpringCloud-Feign-Server》》》》method--->select1:" + json);

return "SpringCloud-Feign-Server》》》》method--->select1:" + json;

}

}

@RequestMapping("/HelloController")

public interface HelloService {

@RequestMapping(value = "/hello/select1", method = RequestMethod.POST,consumes = "application/json")

String select1(@RequestParam("json") String json);

}

public class HelloPojo implements Serializable {

private String username;

private String phone;

public String getUsername() {

return username;

}

public void setUsername(String username) {

this.username = username;

}

public String getPhone() {

return phone;

}

public void setPhone(String phone) {

this.phone = phone;

}

}

server:

port: 9051

spring:

application:

name: SpringCloud-Feign-Server

eureka:

client:

serviceUrl:

defaultZone: http://127.0.0.1:8761/eureka/

instance:

instance-id:  ${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}}

org.springframework.boot

spring-boot-starter-parent

1.5.2.RELEASE

UTF-8

UTF-8

1.8

org.springframework.boot

spring-boot-starter-test

test

org.springframework.boot

spring-boot-starter-web

org.springframework.cloud

spring-cloud-starter-eureka

org.springframework.boot

spring-boot-starter-actuator

org.springframework.cloud

spring-cloud-starter-feign

org.springframework.cloud

spring-cloud-dependencies

Dalston.RC1

pom

import

org.springframework.boot

spring-boot-maven-plugin

spring-milestones

Spring Milestones

https://repo.spring.io/milestone

false

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值