blog2.0--Springboot+MyBatis+maven+swagger框架搭建 IDEA上

blog2.0--Springboot+MyBatis+maven+swagger框架搭建 IDEA上_第1张图片

blog2.0--Springboot+MyBatis+maven+swagger框架搭建 IDEA上_第2张图片

 blog2.0--Springboot+MyBatis+maven+swagger框架搭建 IDEA上_第3张图片

blog2.0--Springboot+MyBatis+maven+swagger框架搭建 IDEA上_第4张图片

blog2.0--Springboot+MyBatis+maven+swagger框架搭建 IDEA上_第5张图片

然后进行pom.xml文件的整合



	4.0.0

	com.version2
	blog
	0.0.1-SNAPSHOT
	jar

	blog
	Demo project for Spring Boot

	
	
		org.springframework.boot
		spring-boot-starter-parent
		2.0.2.RELEASE
		 
	



	
	
		UTF-8
		UTF-8
		1.8
	


	
		
		
			org.springframework.boot
			spring-boot-starter-web
		
		
			org.springframework.boot
			spring-boot-starter-data-jpa
		
		
			org.springframework.boot
			spring-boot-starter-test
			test
		

		
		
			org.springframework.boot
			spring-boot-devtools
			true
		



		
		
			org.mybatis.spring.boot
			mybatis-spring-boot-starter
			1.3.2
		

		
		
			mysql
			mysql-connector-java
			runtime
		


		
		
			junit
			junit
			4.9
			test
		
		
			javax.servlet
			servlet-api
			2.5
			provided
		
		
			javax.servlet
			jsp-api
			2.0
			provided
		
	


	
		
			
			
				org.springframework.boot
				spring-boot-maven-plugin
			
		
	



  

然后创建如下结构

blog2.0--Springboot+MyBatis+maven+swagger框架搭建 IDEA上_第6张图片

进行数据库连接,在文件application.properties进行配置

spring.datasource.url=jdbc:mysql://118.24.116.158:3306/blog_V2?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=skyeBlog7!
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.max-active=20
spring.datasource.max-idle=8
spring.datasource.min-idle=8
spring.datasource.initial-size=10

  

补充BlogApplication.java

 

然后就是实体类的创建

mapper接口的创建

Service层

Controller层

 

blog2.0--Springboot+MyBatis+maven+swagger框架搭建 IDEA上_第7张图片

 java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;

 

添加Swgger

添加swagger依赖

 
            io.springfox
            springfox-swagger2
            2.7.0
        
        
            io.springfox
            springfox-swagger-ui
            2.7.0
        

  

在APP同包下添加swagger2的配置类

package com.version2.blog;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2 {

    @Bean
    public Docket webAPI(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("API 接口文档")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.version2.blog.controller"))
                .paths(PathSelectors.any())
                .build();
    }


    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("测试Swagger")
                .termsOfServiceUrl("http://localhost/")
                .contact("skye")
                .version("1.0")
                .description("部署信息")
                .build();
    }
}

  

然后在需要生成API的接口添加注解

package com.version2.blog.controller;

import com.version2.blog.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Skye on 2018/5/28.
 */
@Api(tags = "test")
@RestController
public class UserController {

    @Autowired
    UserService userService;

    /*@ApiOperation(value = “接口说明”, httpMethod = “接口请求方式”,
    response = “接口返回参数类型”, notes = “接口发布说明”;其他参数可参考源码;*/
    @ApiOperation(value = "查询用户是否存在", notes = "")
    @RequestMapping("/userName")
    public String findUser(String userName){
        return "Hello";
       /* return userService.findUser( userName );*/
    }
}

  

然后访问http://localhost:8080/swagger-ui.html#/就可以了

blog2.0--Springboot+MyBatis+maven+swagger框架搭建 IDEA上_第8张图片

 

转载于:https://www.cnblogs.com/SkyeAngel/p/9102859.html

你可能感兴趣的:(开发工具,java,数据库)