swagger实现api接口可视化

1.pom.xml

 
		UTF-8
		4.3.6.RELEASE
	

	
		
		
			org.springframework
			spring-core
			${spring.framework.version}
		
		
			org.springframework
			spring-context
			${spring.framework.version}
		
		
			org.springframework
			spring-webmvc
			${spring.framework.version}
		
		
		  
		    
		    com.mangofactory    
		    swagger-springmvc    
		    1.0.2    
		  
		  
		    com.fasterxml.jackson.core  
		    jackson-core  
		    2.5.1  
		  
		  
		    com.fasterxml.jackson.core  
		    jackson-databind  
		    2.5.1  
		  
		  
		    com.fasterxml.jackson.core  
		    jackson-annotations  
		    2.5.1  
		   
	
	
	
		springfox-swagger-demo
	

2.spring-mvc.xml

 




	
	

	
	

	
	
	

3.web.xml



	Spring MVC
	
		spring-mvc
		org.springframework.web.servlet.DispatcherServlet
		
			contextConfigLocation
			classpath:spring-mvc.xml
		
		1
		true
	
	
		spring-mvc
		/
	
	
		encodingFilter
		org.springframework.web.filter.CharacterEncodingFilter
		
			encoding
			UTF-8
		
		
			forceEncoding
			true
		
	
	
		encodingFilter
		/*
	

 

4.controller类

 

package com.parwa.test.controll;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.parwa.test.entity.Product;


@RestController
@RequestMapping(value = { "/api/product/"})
public class ProductController {

	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public ResponseEntity get(@PathVariable Long id) {
		Product product = new Product();
		product.setName("测试spring mvc是否搭建完成1!");
		product.setId(1L);
		product.setProductClass("seven_filters");
		product.setProductId("T12345");
		return ResponseEntity.ok(product);
	}
}

5.实体类

package com.parwa.test.entity;

import java.io.Serializable;

/**
 * 
 * @author wude
 * @date 2018��5��11��
 * @version 2.0
 */
public class Product implements Serializable {

	private static final long serialVersionUID = 1L;

	/**ID*/
	private Long id;

	/**��Ʒ����*/
	private String name;

	/**��Ʒ�ͺ�*/
	private String productClass;

	/**��ƷID*/
	private String productId;

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the productClass
	 */
	public String getProductClass() {
		return productClass;
	}

	/**
	 * @param productClass
	 *            the productClass to set
	 */
	public void setProductClass(String productClass) {
		this.productClass = productClass;
	}

	/**
	 * @return the productId
	 */
	public String getProductId() {
		return productId;
	}

	/**
	 * @param productId
	 *            the productId to set
	 */
	public void setProductId(String productId) {
		this.productId = productId;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Product [id=" + id + ", name=" + name + ", productClass=" + productClass + ", productId=" + productId
				+ "]";
	}
}

 6.访问地址

http://localhost:6080/test/api/product/2

 

swagger实现api接口可视化_第1张图片

你可能感兴趣的:(swagger)