首页 » codingbaby

java.lang.NoSuchMethodError: io.swagger.models.AbstractModel.addProperty(Lja

最后发现是io.swagger:swagger-models:jar:1.6.0:和swager依赖的版本冲突,exclude掉

<dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
            <exclusions>
                <exclusion>
                    <groupId>io.swagger</groupId>
                    <artifactId>swagger-models</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>io.swagger</groupId>
                    <artifactId>swagger-annotations</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
            <exclusions>
                <exclusion>
                    <groupId>io.swagger</groupId>
                    <artifactId>swagger-models</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>io.swagger</groupId>
                    <artifactId>swagger-annotations</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

Error running 'xxxApplication': Command line is too long. Shorten command line for xxxAPPlication or also for Application default configuration. 的解决办法

在.idea 下面的workspace.xml中加入

  <component name="PropertiesComponent">
    <property name="WebServerToolWindowFactoryState" value="false" />
    <property name="aspect.path.notification.shown" value="true" />
    <property name="last_opened_file_path" value="$PROJECT_DIR$/pom.xml" />
    <property name="settings.editor.selected.configurable" value="MavenSettings" />
    <property name="dynamic.classpath" value="true" />
  </component>

spring boot 引入swagger可以方便的测试api和查看api文档
1.引入依赖
 <!-- Swagger -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.8.0</version>
        </dependency>
 
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.8.0</version>
        </dependency>

2.加入SwaggerConfig.java

package tv.rr.panther.base.config;
 
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import tv.rr.panther.base.util.PropertiesUtil;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @title
 * @description
 * @usage

 * @author shenfeng
 * @create 2018/2/12 10:14
 */
 
@Profile({"dev","qtest"})
 
@Configuration
@EnableSwagger2
@ComponentScan
@EnableWebMvc
public class SwaggerConfig {
 
    private static final String SWAGGER_FLAG = PropertiesUtil.getPropertyValue("application", "swagger.enable");
 
    @Bean
    public Docket api(){
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build()
                .enable(true)
                .globalOperationParameters(getGlobalHeaderParameters())
                .apiInfo(apiInfo());
    }
 
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("拍客")
                .description("paike接口文档")
                .version("1.0.0")
                .build();
    }
 
    private List<Parameter> getGlobalHeaderParameters() {
        ParameterBuilder parameterBuilder = new ParameterBuilder();
        List<Parameter> parameters = new ArrayList<>(3);
        parameterBuilder.name("appId").description("客户端version_Platform")
                .modelRef(new ModelRef("string"))
                .parameterType("header").required(true).defaultValue("3.7.0_ios");
 
        parameterBuilder.name("token").description("客户端version_Platform")
                .modelRef(new ModelRef("string"))
                .parameterType("header").required(true).defaultValue("a261fdc8ddab4e8b8b233d9d011da442");
 
        parameters.add(parameterBuilder.build());
        parameterBuilder.name("sign").description("客户端签名md5(timestamp+token+appId)")
                .modelRef(new ModelRef("string"))
                .parameterType("header").required(true).defaultValue("md5(12132345645_token_3.7.2_ios)");
        parameters.add(parameterBuilder.build());
        return parameters;
    }
 
}

3.在controller上贴注解吧

package tv.rr.panther.controller;
 
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.ResponseBody;
import tv.rr.panther.base.controller.BaseController;
import tv.rr.panther.base.view.CommonResult;
import tv.rr.panther.responseData.tag.SelectTagListResponseData;
import tv.rr.panther.responseData.tag.TagListResponseData;
import tv.rr.panther.service.TagService;
import tv.rr.panther.view.TagView;
import tv.rr.panther.view.TagViewNoPic;
 
import java.util.List;
 
/**
 * @title
 * @description
 * @usage
 * @author shenfeng
 * @create 4/28/2018 3:36 PM
 *
 *                             _ooOoo_
 *                            o8888888o
 *                            88" . "88
 *                            (| -_- |)
 *                            O\  =  /O
 *                         ____/`---'\____
 *                       .'  \\|     |//  `.
 *                      /  \\|||  :  |||//  \
 *                     /  _||||| -:- |||||-  \
 *                     |   | \\\  -  /// |   |
 *                     | \_|  ''\---/''  |   |
 *                     \  .-\__  `-`  ___/-. /
 *                   ___`. .'  /--.--\  `. . __
 *                ."" '<  `.___\_<|>_/___.'  >'"".
 *               | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *               \  \ `-.   \_ __\ /__ _/   .-` /  /
 *          ======`-.____`-.___\_____/___.-`____.-'======
 *                             `=---='
 *          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 *                     佛祖保佑        永无BUG
 */
@RequestMapping("tag")
@Api
@Controller
public class TagController extends BaseController {
 
    @Autowired
    private TagService tagService;
 
    @RequestMapping("recommendList")
    @ApiOperation(value = "首页推荐标签列表",httpMethod = "GET")
    @ResponseBody
    public CommonResult<TagListResponseData> recommondList(){
        CommonResult<TagListResponseData> result = CommonResult.getInstance();
        TagListResponseData tagListResponseData = new TagListResponseData();
        List<TagView> list = tagService.recommendList();
        tagListResponseData.setTagList(list);
        result.setData(tagListResponseData);
        return result;
    }
 
    /**
     * 可选列表,目前是所有的
     * @return
     */
    @RequestMapping("selectList")
    @ApiOperation(value = "视频可选标签",httpMethod = "GET")
    @ResponseBody
    public CommonResult<SelectTagListResponseData> selectList(){
        CommonResult<SelectTagListResponseData> result = CommonResult.getInstance();
 
        SelectTagListResponseData selectTagListResponseData = new SelectTagListResponseData();
 
        List<TagViewNoPic> list = tagService.allList();
        selectTagListResponseData.setTagList(list);
        result.setData(selectTagListResponseData);
 
        return result;
    }
 
}
  1. WebAppConfig 中web mvc注册路径
package tv.rr.panther.base.config;
 
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
 
/**
 * @title
 * @description
 * @usage
 * @author shenfeng
 * @create 2018/2/12 10:19
 */
@Profile({"dev","qtest"})
@Configuration
@EnableWebMvc
public class WebAppConfig extends WebMvcConfigurerAdapter {
 
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
 
}

windows 下启动mysql比较麻烦,用命令行安装成mysql服务,然后启动服务来运行mysql

1.首先下载解压mysql--- https://dev.mysql.com/downloads/mysql/ ,解压后在根目录下创建mysql.ini,注意这里好多教程都没说明,路径要用双引号,否则win10报错

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8 
[mysqld]
# 设置3306端口
port = 3306 
# 设置mysql的安装目录
basedir="E:\\baiduDown\\mysql-5.7.29-winx64"
datadir="E:\\baiduDown\\mysql-5.7.29-winx64\\data"
# 允许最大连接数
max_connections=200
# 设置mysql服务端默认字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB 
# 注意这个参数,MySQL默认值导致在Windows 10 专业版上无法安装
innodb_flush_method=normal

2.管理员模式命令行执行下面的指令,注意执行的路径必须是mysql所在路径

mysqld.exe --initialize-insecure  --explicit_defaults_for_timestamp
mysqld.exe --install 

3.启动mysql服务

net start mysql

有时候算法的复杂度跟数据的排列由很大关系,这种复杂度不能简单的用一个复杂度来分析,而是由最好,最坏,平均复杂度来分析

1.如下面的,如果x在第0个位置,就是O(1),如果在第n-1个位置,就是O(n),这里就带表了最好和最坏


// n 表示数组 array 的长度,
int find(int[] array, int n, int x) {
  int i = 0;
  int pos = -1;
  for (; i < n; ++i) {
    if (array[i] == x) {
       pos = i;
       break;
    }
  }
  return pos;
}

2.最好最坏的都是极端的,大概率不会发生,那么就引入了平均(情况)时间复杂度,那么x的位置,由n+1种情况,即在0~n-1的位置,还有不在数组种

  • 我们把每种情况的时间复杂度相加,除以可能出现的情况个数,就是平均时间复杂度---即1+2+3+4+...+ n 除以n+1,平均情况时间复杂度就是:n*(n+3)/2(n+1) 分子分母,逐步忽略常量,就是O(n)

3.加权平均时间复杂度,第二步中有点问题,就是没有考虑各种情况的概率,如果x出现在某个位置的概率非常大,那么上面的计算是把所有复杂度的情况都认为是1/(n+1)。

  • 实际上我们可以考虑,x在数组中的概率是1/2,x在每个位置的概率是1/n,那么x在某个位置的概率退化为1/2n,不在数组中的概率为1/2
  • 所以加权平均值是11/2n + 21/2n +...+ n1/2n + n1/2 = (3n+1)/4
  • 第二步的算法,是理想化了,每个情况的权重都看成了1/(n+1)

4.均摊时间复杂度---摊还分析,均摊时间复杂度就是一种特殊的平均时间复杂度,即只有1/n的情况复杂度是n(这里出现的概率很规律,比如数组插入n个数后必然发生扩容,不需要概率),那么均摊下来是O(1),而不需要通过平均计算