提交 ed695794 编写于 作者: Q qinyingjie

fix:添加portal模块

上级 cac144cc
......@@ -27,6 +27,7 @@
<modules>
<module>springcloud-service-goods</module>
<module>springcloud-service-common</module>
<module>springcloud-service-portal</module>
</modules>
<dependencyManagement>
......
......@@ -23,6 +23,12 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
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();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.kwan.springcloud</groupId>
<artifactId>springcloud-service-parent</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>springcloud-service-portal</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springcloud-service-portal</name>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.kwan.springcloud</groupId>
<artifactId>springcloud-service-common</artifactId>
<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>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
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);
}
}
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<Result> forEntity = restTemplate.getForEntity(GOODS_URL + id, Result.class);
return Result.ok(forEntity);
}
}
\ No newline at end of file
#端口号
server:
port: 8080
\ No newline at end of file
package com.kwan.springcloud;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class PortalApplicationTests {
@Test
void contextLoads() {
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册