SpringBoot项目中遇到的问题

x33g5p2x  于2022-05-20 转载在 Spring  
字(2.1k)|赞(0)|评价(0)|浏览(377)

1:首先是用户编辑问题,点击编辑出现弹窗以后,还没有点确定就数据已经修改了:

这里我们这样改:

this.form = Object.assign({},row)   //解决还没有点确定就已经数据改变的问题

2:怎样使得查询时在前端的返回数据类型中既有data数据也有count总数?:

首先,在后端我们将service中的全部用户查询方法的返回类型写成Hashmap,

这样就可以添加两个对象

3:怎样实现分页?

首先后端,我们写的分页查询方法,先默认给两个传参:

然后前端,使用element插件:

先默认给一个值:

pageNum代表第几页,pageSize代表每一页有几个,pageIndex代表开始展示的数据下标

4:Swagger的配置

springboot在配置Swagger的时候对于版本控制比较严格,springboot2.6之前是使用Swagger2,2.6以后使用Swagger3,我这里说一下怎样配置Swagger3:

依赖:

<dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
    </dependency>

配置类:

package com.example.demo.config;

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.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@EnableOpenApi
@Configuration
public class SwaggerConfig {
    /**
     * 创建API应用
     * apiInfo() 增加API相关信息
     * 通过select()函数返回一个ApiSelectorBuilder实例,用来控制哪些接口暴露给Swagger来展现,
     * 本例采用指定扫描的包路径来定义指定要建立API的目录。
     *
     * @return
     */
    @Bean
    public Docket restApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("标准接口")
                .apiInfo(apiInfo("Spring Boot中使用Swagger2构建RESTful APIs", "1.0"))
                .useDefaultResponseMessages(true)
                .forCodeGeneration(false)
                .select()
                //扫描哪个包
                .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 创建该API的基本信息(这些基本信息会展现在文档页面中)
     * 访问地址://访问地址http://localhost:8084/swagger-ui/index.html
     *
     * @return
     */
    private ApiInfo apiInfo(String title, String version) {
        return new ApiInfoBuilder()
                .title("项目标题")
                .description("更多请关注")
                .termsOfServiceUrl("")
                .contact(new Contact("", "", ""))
                .version(version)
                .build();
    }
}

.yml配置:

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

相关文章