diff --git a/pom.xml b/pom.xml index f96137d095e8da01e7697f494c36d99d0213cdc9..209f5084dd499f9383ecab5e240964f3c70342a0 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 7e6eb01a4c622a1806c73c27e8a75e17a9c24afe..11c349ed9025972733498db93e763ea1ded16ac3 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 0000000000000000000000000000000000000000..1901a31cb7cd6e6addc1bc8984e498df38175230 --- /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 0000000000000000000000000000000000000000..5d17b47660d9e547327adf269c5e93b4ebc0d712 --- /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 0000000000000000000000000000000000000000..e3434bf3b12bd71fba28432581fbede0568c0e99 --- /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 0000000000000000000000000000000000000000..3c955a475dd97caae2f394a7834162b69756e46a --- /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 0000000000000000000000000000000000000000..3a43dd9ddbc5a3d5d9a13192a793c167d5b28254 --- /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 0000000000000000000000000000000000000000..1a8e650e3ec9e02f15e843b39496d32bf600724b --- /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() { + } + +}