springboot2.7以上版本配置swagger3.0.0版本浏览器无法打开swagger-ui

1.最实用解决方式:将pom里的swagger依赖降到2.9.0即可 过低无法启动项目
1.2 Springboot2.6以后将SpringMVC 默认路径匹配策略从AntPathMatcher 更改为PathPatternParser
Springfox 使用的路径匹配是基于AntPathMatcher的,而Spring Boot 2.6.X使用的是PathPatternMatcher

spring:
   mvc:
    pathmatch:
      matching-strategy: ant_path_matcher
<!-- swagger-annotations -->
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger2</artifactId>
			<version>2.9.0</version>
		</dependency>
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger-ui</artifactId>
			<version>2.9.0</version>
		</dependency>

2.3.0.0版本swagger2访问地址为:http://localhost:8034/swagger-ui.index.html 3.0.0以下访问地址为:http://localhost:8034/swagger-ui.html#/
3.配置中的.enable(true)设置为true

@Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.spring_mybatis.base.controller"))
                .paths(PathSelectors.any())
                //.build().securityContexts(securityContexts())
                //.build().securitySchemes(securitySchemes())
                .build().enable(true); //是否启用
    }
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("接口大全")
                .description(initContextInfo())
                .version("V1.0")
                .build();
    }
    private String initContextInfo() {
        return "REST API 设计在细节上有很多自己独特的需要注意的技巧,并且对开发人员在构架设计能力上比传统 API 有着更高的要求。" +
                "<br/> 本文通过翔实的叙述和一系列的范例,从整体结构,到局部细节,分析和解读了为了提高易用性和高效性," +
                "REST API 设计应该注意哪些问题以及如何解决这些问题。";
    }

4.配置webmvcconfig

@Slf4j
@Configuration
public class WebConfig extends WebMvcConfigurationSupport {

    @Autowired
    ComponentDirectoryPathReader pathReader;

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        String filePath = "C:\\Users\\Administrator\\Desktop";
        log.info("filePath:"+filePath);
        registry.addResourceHandler("/**").
                addResourceLocations("classpath:/static/").addResourceLocations("classpath:META-INF/resources/").
                addResourceLocations("file:"+filePath);
    }

}

5.配置项确定正确

 public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.spring_mybatis.base.controller"))//你配置swagger扫描的controller
                .paths(PathSelectors.any())
                //.build().securityContexts(securityContexts())
                //.build().securitySchemes(securitySchemes())
                .build().enable(true); //是否启用
    }

6.springboot位指定配置文件时,默认使用 application.yml

<think>好的,我需要回答用户关于如何在WinUI3中设置窗口大小的问题。首先,我得回忆一下WinUI3的相关知识,特别是窗口管理的部分。根据用户提供的引用内容,特别是引用[2]提到的AppWindow类,这可能是一个关键点。记得在传统的Win32 API中,设置窗口大小通常涉及CreateWindowEx和AdjustWindowRect等函数,如引用[1]和[3]所述。但WinUI3可能采用了不同的方法,更现代化一些。 用户提到的引用[2]提到了AppWindow类,并链接到微软文档,所以应该优先考虑使用AppWindow来设置窗口尺寸。我需要确认在WinUI3中如何获取主窗口的AppWindow实例。通常,在WinUI3中,主窗口是继承自Microsoft.UI.Xaml.Window类,而AppWindow是用于更底层控制的。 另外,引用[4]提到了获取窗口句柄和窗口大小的方法,但在WinUI3中,可能不需要直接调用这些API,而是通过封装好的方法来实现。不过,如果有需要,可能还是可以通过某些方式获取句柄来操作。 接下来,我应该分步骤说明如何设置窗口大小,包括初始设置和运行时调整。需要提到如何设置初始窗口大小,以及如何通过代码动态调整。同时,要指出设置窗口大小时的注意事项,比如最小尺寸和屏幕尺寸限制,如引用[1]中提到的SM_CXMIN和SM_CYMIN,以及屏幕尺寸检查。 可能还需要提到WinUI3传统UWP的不同之处,比如在UWP中可以使用ApplicationView类,但在WinUI3中可能推荐使用AppWindow。同时,要确保代码示例正确,比如如何在Window的Loaded事件中获取AppWindow并设置大小。 还需要检查是否有相关的命名空间需要引入,比如Microsoft.UI.Windowing是否需要在项目中添加引用。另外,是否需要处理DPI缩放的问题,或者WinUI3是否自动处理这些。 最后,生成的相关问题需要围绕WinUI3窗口管理,比如如何限制最小尺寸,如何全屏,如何获取屏幕尺寸等,这样用户可以有进一步了解的途径。</think>在WinUI3中设置窗口大小可以通过以下步骤实现: ### 一、设置初始窗口尺寸 1. 在创建主窗口时,通过`Window`类的属性设置初始尺寸: ```csharp public MainWindow() { this.InitializeComponent(); // 设置窗口初始尺寸 this.AppWindow.Resize(new Windows.Graphics.SizeInt32(800, 600)); } ``` 注意:WinUI3使用`AppWindow`类进行窗口管理,需要先获取当前窗口的`AppWindow`实例[^2] ### 二、动态调整窗口尺寸 ```csharp // 获取当前窗口的AppWindow实例 var appWindow = this.AppWindow; // 设置新的窗口尺寸(单位:像素) appWindow.Resize(new Windows.Graphics.SizeInt32(1024, 768)); // 或单独设置宽高 appWindow.Resize(new Windows.Graphics.SizeInt32 { Width = 1280, Height = 720 }); ``` ### 三、重要注意事项 1. **最小尺寸限制**: ```csharp // 设置窗口最小尺寸 this.AppWindow.SetPresenter(AppWindowPresenterKind.Overlapped); this.AppWindow.ResizeClient(new SizeInt32(300, 200)); // 最小客户区尺寸 ``` 实际最小尺寸受系统限制(参考`SM_CXMIN`和`SM_CYMIN`系统指标)[^1] 2. **屏幕适配**: ```csharp // 获取屏幕尺寸 var displayArea = DisplayArea.GetFromWindowId( this.AppWindow.Id, DisplayAreaFallback.Primary ); var screenWidth = displayArea.WorkArea.Width; var screenHeight = displayArea.WorkArea.Height; ``` 建议窗口尺寸不要超过屏幕尺寸的80% ### 四、完整示例代码 ```csharp using Microsoft.UI.Xaml; using Microsoft.UI.Windowing; public sealed partial class MainWindow : Window { public MainWindow() { this.InitializeComponent(); this.AppWindow.Resize(new Windows.Graphics.SizeInt32(800, 600)); // 设置尺寸改变事件 this.AppWindow.Changed += (sender, args) => { if(args.DidSizeChange) { // 处理尺寸变化 } }; } } ``` ### 五、传统Win32 API的区别 | 功能 | Win32 API | WinUI3 方法 | |-----------------|-----------------------------|-------------------------| | 获取屏幕尺寸 | GetSystemMetrics | DisplayArea类 | | 设置窗口尺寸 | SetWindowPos | AppWindow.Resize | | 计算窗口尺寸 | AdjustWindowRect | 自动处理DPI缩放 |
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值