Swagger入门

 

@RequestMapping(value="/simple/get", method=RequestMethod.GET)
	@ApiOperation(value="单个参数,GET")
	public Result simpleGet(@ApiParam("这是p1参数") @RequestParam("p1")String p1) throws Exception{
		return Result.success("hello,world");
	}
	
	@RequestMapping(value="/simple/get2", method=RequestMethod.GET)
	@ApiOperation(value="单个参数,GET2")
	@ApiImplicitParam(name="p1",value="这是p1参数", paramType="query")
	public Result simpleGet2() throws Exception{
		return Result.success("hello,world");
	}

效果是这样的:

 

Swagger入门_第1张图片
 

@RequestMapping(value="/complex/get", method=RequestMethod.POST)
	@ApiOperation(value="对象参数")
	public Result complexGet(@ApiParam @RequestBody User user) throws Exception{
		user.setId("newid");
		return Result.success(user);
	}

 

@ApiModel(value="用户对象")
public class User {
	@ApiModelProperty(value="用户ID")
	private String id;
	@ApiModelProperty(value="用户姓名")
	private String name;
	@ApiModelProperty(value="用户昵称")
	private String nickName;
	@ApiModelProperty(value="用户openid", hidden=true)
	private String openid;
	@ApiModelProperty(value="用户手机号", example="13112341234", required=true)
	private String mobile;
}


效果是这样的:

 

Swagger入门_第2张图片

 

@RequestMapping(value="/complex/get2", method=RequestMethod.POST)
	@ApiOperation(value="对象参数")
	@ApiImplicitParams(
			{
				@ApiImplicitParam(name="id", value="用户ID", paramType="query"),
				@ApiImplicitParam(name="name", value="用户姓名", paramType="query")
			}
	)
	public Result complexGet2(@ApiParam @RequestBody User user) throws Exception{
		user.setId("newid");
		return Result.success(user);
	}

效果是这样的:

 

Swagger入门_第3张图片
 

上面这几种情况掌握就完全足够用了!

 

你可能感兴趣的:(java)