feign starter 使用实例

This commit is contained in:
Administrator
2020-10-30 08:46:35 +08:00
parent 980a0fc2f1
commit 599d6bc70e
40 changed files with 976 additions and 0 deletions

View File

@ -0,0 +1,15 @@
package com.chinaunicom.mall.ebtp.cloud.swagger.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;
import com.chinaunicom.mall.ebtp.cloud.swagger.starter.SwaggerStarterConfiguration;
@SpringBootApplication
@Import(SwaggerStarterConfiguration.class)
public class SwaggerExampleApplication {
public static void main(String[] args) {
SpringApplication.run(SwaggerExampleApplication.class, args);
}
}

View File

@ -0,0 +1,60 @@
package com.chinaunicom.mall.ebtp.cloud.swagger.example.controller;
import java.util.HashMap;
import java.util.Map;
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.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chinaunicom.mall.ebtp.cloud.swagger.example.model.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;
@RestController
@RequestMapping("/swagger")
@Api(value = "试Controller")
public class SwaggerExampleController {
@ApiIgnore
@GetMapping("/hello")
public String hello() {
return "hello";
}
@ApiOperation(value = "回声服务", notes = "服务直接将客户消息返回")
@ApiImplicitParam(name = "message", value = "用户消息", required = true, dataType = "String", paramType = "path")
@GetMapping("/echo/{message}")
public String echo(@PathVariable("message") String message) {
return message;
}
@ApiOperation(value = "创建用户", notes = "创建新的用户信息, 服务器创建成功后返回结果")
@ApiImplicitParam(name = "user", value = "用户基本信息", required = true, dataType = "User")
@PostMapping("/createUser")
public ResponseEntity<User> createUser(@RequestBody User user) {
return ResponseEntity.ok(user);
}
@ApiOperation(value = "修改用户", notes = "修改用户信息, 服务器返回执行结果")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "用户id", required = true, dataType = "Long", paramType = "path"),
@ApiImplicitParam(name = "user", value = "要修改的用户信息", required = true, dataType = "User") })
@PutMapping("/updateUser/{id}")
public ResponseEntity<Map<String, Object>> updateUser(@PathVariable("id") Long id, @RequestBody User user) {
Map<String, Object> result = new HashMap<>();
result.put("result", "success");
return ResponseEntity.ok(result);
}
}

View File

@ -0,0 +1,11 @@
package com.chinaunicom.mall.ebtp.cloud.swagger.example.model;
import lombok.Data;
@Data
public class User {
private String username;
private Integer age;
}

View File

@ -0,0 +1,15 @@
server:
port: 8762
max-http-header-size: 1000000
unifast:
swagger:
basePackage: com.chinaunicom.mall.ebtp.cloud.swagger.example
# swagger 的基本配置信息(已经在starter中配置好)
#unifast.swagger.title=\u6d4b\u8bd5\u63a5\u53e3\u6587\u6863
#unifast.swagger.contactName=\u5409\u6797\u9879\u76ee\u7ec4
#unifast.swagger.contactUrl=http://chinaunicom.com
#unifast.swagger.contactEmail=chinaunicom@chinaunicom.com
#unifast.swagger.version=0.0.1
#unifast.swagger.description=\u7840\u540e\u53f0\u529f\u80fd\u6846\u67b6

View File

@ -0,0 +1,5 @@
spring:
profiles:
active: swagger
application:
name: mall-ebtp-cloud-demo

View File

@ -0,0 +1,38 @@
package com.chinaunicom.mall.ebtp.cloud.swagger.example;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}