SpringBoot基础配置

SpringBoot常用配置

Mybatis-generatorConfig.xml

具体参数,包名根据项目自行修改




    
        
            
            
            
        
        
        
        
        
            
        
        
        
            
            
        
        
        
            
        
        
        
        
            
        

        
        

Maven添加生成实体类、接口xml(在pom.xml添加)


  org.mybatis.generator
  mybatis-generator-maven-plugin
  1.3.5
  
    
      mysql
      mysql-connector-java
      5.1.39
    
    
      org.mybatis.generator
      mybatis-generator-core
      1.3.5
    
  
  
    
      Generate MyBatis Artifacts
      deploy
      
        generate
      
    
  
  
    
    true
    
    true
    
    
      src/main/resources/generatorConfig.xml
    
  

添加Api接口请求网页(swagger)

添加swagger依赖


        
            io.springfox
            springfox-swagger2
            2.9.2
        
        
            io.springfox
            springfox-swagger-ui
            2.9.2
        

swagger配置类

@Configuration
@EnableSwagger2
@ConditionalOnProperty(name = "enabled", prefix = "swagger", havingValue = "true", matchIfMissing = false)
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.star.appapi.controller"))    //这里采用包扫描的方式来确定要显示的接口
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("swagger标题")
                .description("Api文档")
                .termsOfServiceUrl("")
                .version("1.0")
                .build();
    }
}

application.yml

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/database?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
    username: root
    password: root
    driver-class-name: com.mysql.cj.jdbc.Driver
  http:
    encoding:
      force: true
      charset: UTF-8
      enabled: true
server:
  tomcat:
    uri-encoding: UTF-8

重写SpringApplication启动类

@MapperScan(basePackages = {"com.包名.generator.dao", "com.包名.dao"})
@SpringBootApplication
public class LocalApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        JEditorPane response = new JEditorPane();
        response.setContentType("application/json;charset=utf-8");
        new SpringApplicationBuilder(LocalApplication.class).run(args);
    }

}

你可能感兴趣的:(SpringBoot基础配置)