From ed6957948b800251dda4ab3e3c2d5ef1013b8646 Mon Sep 17 00:00:00 2001 From: qinyingjie Date: Sun, 8 Jan 2023 11:26:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=B7=BB=E5=8A=A0portal=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 1 + springcloud-service-common/pom.xml | 6 +++ .../kwan/springcloud/config/RestConfig.java | 14 ++++++ springcloud-service-portal/pom.xml | 47 +++++++++++++++++++ .../kwan/springcloud/PortalApplication.java | 13 +++++ .../controller/PortalController.java | 44 +++++++++++++++++ .../src/main/resources/application.yaml | 3 ++ .../springcloud/PortalApplicationTests.java | 13 +++++ 8 files changed, 141 insertions(+) create mode 100644 springcloud-service-common/src/main/java/com/kwan/springcloud/config/RestConfig.java create mode 100644 springcloud-service-portal/pom.xml create mode 100644 springcloud-service-portal/src/main/java/com/kwan/springcloud/PortalApplication.java create mode 100644 springcloud-service-portal/src/main/java/com/kwan/springcloud/controller/PortalController.java create mode 100644 springcloud-service-portal/src/main/resources/application.yaml create mode 100644 springcloud-service-portal/src/test/java/com/kwan/springcloud/PortalApplicationTests.java diff --git a/pom.xml b/pom.xml index f96137d..209f508 100644 --- a/pom.xml +++ b/pom.xml @@ -27,6 +27,7 @@ springcloud-service-goods springcloud-service-common + springcloud-service-portal diff --git a/springcloud-service-common/pom.xml b/springcloud-service-common/pom.xml index 7e6eb01..11c349e 100644 --- a/springcloud-service-common/pom.xml +++ b/springcloud-service-common/pom.xml @@ -23,6 +23,12 @@ org.projectlombok lombok + + + org.springframework.boot + spring-boot-starter-web + + \ No newline at end of file diff --git a/springcloud-service-common/src/main/java/com/kwan/springcloud/config/RestConfig.java b/springcloud-service-common/src/main/java/com/kwan/springcloud/config/RestConfig.java new file mode 100644 index 0000000..1901a31 --- /dev/null +++ b/springcloud-service-common/src/main/java/com/kwan/springcloud/config/RestConfig.java @@ -0,0 +1,14 @@ +package com.kwan.springcloud.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; + +@Configuration +public class RestConfig { + + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } +} diff --git a/springcloud-service-portal/pom.xml b/springcloud-service-portal/pom.xml new file mode 100644 index 0000000..5d17b47 --- /dev/null +++ b/springcloud-service-portal/pom.xml @@ -0,0 +1,47 @@ + + + 4.0.0 + + com.kwan.springcloud + springcloud-service-parent + 1.0.0 + + springcloud-service-portal + 0.0.1-SNAPSHOT + springcloud-service-portal + + 1.8 + + + + + com.kwan.springcloud + springcloud-service-common + 1.0.0 + compile + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/springcloud-service-portal/src/main/java/com/kwan/springcloud/PortalApplication.java b/springcloud-service-portal/src/main/java/com/kwan/springcloud/PortalApplication.java new file mode 100644 index 0000000..e3434bf --- /dev/null +++ b/springcloud-service-portal/src/main/java/com/kwan/springcloud/PortalApplication.java @@ -0,0 +1,13 @@ +package com.kwan.springcloud; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class PortalApplication { + + public static void main(String[] args) { + SpringApplication.run(PortalApplication.class, args); + } + +} diff --git a/springcloud-service-portal/src/main/java/com/kwan/springcloud/controller/PortalController.java b/springcloud-service-portal/src/main/java/com/kwan/springcloud/controller/PortalController.java new file mode 100644 index 0000000..3c955a4 --- /dev/null +++ b/springcloud-service-portal/src/main/java/com/kwan/springcloud/controller/PortalController.java @@ -0,0 +1,44 @@ +package com.kwan.springcloud.controller; + +import com.kwan.springcloud.response.Result; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +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.io.Serializable; + + +/** + * portal控制器 + * + * @author : qinyingjie + * @version : 2.2.0 + * @date : 2023/1/8 11:12 + */ +@RestController +@RequestMapping("portal") +public class PortalController { + private static final String GOODS_URL = "http://localhost:9100/kwanGoodsInfo/"; + /** + * 服务对象 + */ + @Autowired + private RestTemplate restTemplate; + + /** + * 通过主键查询单条数据 + * + * @param id 主键 + * @return 单条数据 + */ + @GetMapping("{id}") + public Result selectOne(@PathVariable Serializable id) { + //调用远程的controller + ResponseEntity forEntity = restTemplate.getForEntity(GOODS_URL + id, Result.class); + return Result.ok(forEntity); + } +} \ No newline at end of file diff --git a/springcloud-service-portal/src/main/resources/application.yaml b/springcloud-service-portal/src/main/resources/application.yaml new file mode 100644 index 0000000..3a43dd9 --- /dev/null +++ b/springcloud-service-portal/src/main/resources/application.yaml @@ -0,0 +1,3 @@ +#端口号 +server: + port: 8080 \ No newline at end of file diff --git a/springcloud-service-portal/src/test/java/com/kwan/springcloud/PortalApplicationTests.java b/springcloud-service-portal/src/test/java/com/kwan/springcloud/PortalApplicationTests.java new file mode 100644 index 0000000..1a8e650 --- /dev/null +++ b/springcloud-service-portal/src/test/java/com/kwan/springcloud/PortalApplicationTests.java @@ -0,0 +1,13 @@ +package com.kwan.springcloud; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class PortalApplicationTests { + + @Test + void contextLoads() { + } + +} -- GitLab