1. 程式人生 > >swagger與spring 進行物件傳遞

swagger與spring 進行物件傳遞

問題:

1.swagger解決傳遞json以為引數的方法

2.spring接受實體物件

問題一:

@ApiOperation(httpMethod = "POST",value = "測試能否使用application/x-www-form-urlencoded",consumes="application/x-www-form-urlencoded")
	@ResponseBody
引入consumes引數

問題二:

1.引入依賴,

<!-- swagger -->
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger2</artifactId>
			<version>2.4.0</version>
		</dependency>
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger-ui</artifactId>
			<version>2.4.0</version>
		</dependency>
2.匯入ui檔案,去官網下一個


3.swagger/index.html中有url中的引數改成你的專案的引數

4.controller中

@RequestMapping(value = "/insertVideo", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(httpMethod = "POST",value = "上傳視屏介面", notes = "上傳視屏")
	public Result<Integer> insertVideo(
			@RequestBody @ApiParam(name="視屏name",value="視屏物件11") TVideo tVideo
	) {
		System.out.println(Global.getFrontPath());
		System.out.println(tVideo.getLongtime());
		Result<Integer> result = Result.<Integer>getSucceedInstance();

		return result;

	}
5.實體類中
@ApiModel(value="視屏物件")
public class TVideo {
    private Integer videoId;
    @ApiModelProperty(value="視屏地址",example="/!!!/sss")
    private String url;