首页>代码>Spring Cloud微服务架构项目搭建实例,微服务组件介绍,基于maven多模块搭建>/springcloud/consumer-banji-80/src/main/java/com/neusoft/controller/BanjiComsumerController.java
package com.neusoft.controller;
import com.neusoft.entity.BanJi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.List;
@RestController
@RequestMapping("banji/consumer")//通过模板去获取提供者的服务
public class BanjiComsumerController {
@Autowired
private RestTemplate restTemplate; //提供一些便利的方法直接访问http请求
private String url_prefix="http://provider-banji";//"http://localhost:8001";
@RequestMapping("insert")
public ResponseEntity<Boolean> insert(BanJi bean) {
String uri =url_prefix + "/banji/insert";
return restTemplate.postForEntity(uri, bean, Boolean.class);
}
@RequestMapping("queryAll")
public Object queryAll() {
String uri = url_prefix + "/banji/queryAll";
return restTemplate.getForObject(uri, List.class);
}
@RequestMapping("queryById/{id}")
public Object queryById(@PathVariable Integer id) {
String uri = url_prefix + "/banji/queryById/" + id ;
return restTemplate.getForObject(uri, BanJi.class);
}
}
最近下载更多
1049066887 LV13
2024年8月22日
Zionism LV7
2024年6月5日
落后就要挨打 LV26
2023年11月23日
644106 LV8
2023年6月8日
heweimin LV13
2022年10月28日
aqin_qin LV1
2022年6月4日
mylzdy LV12
2022年3月8日
huangxiaoke20 LV17
2021年11月2日
newhaijun LV16
2021年9月2日
sunlzh888888 LV29
2021年6月21日
最近浏览更多
徐万强 LV9
2月27日
微信网友_7134912998903808 LV15
2024年9月12日
chn-lei LV2
2024年8月31日
ゆ 、 Hurt° LV2
2024年7月8日
sssnow
2024年6月24日
暂无贡献等级
Zionism LV7
2024年6月5日
kashen114230
2024年4月5日
暂无贡献等级
appleman988
2024年3月19日
暂无贡献等级
malagou LV1
2024年1月22日
whfuai LV14
2024年1月2日

