Home avatar

线偶的IT笔记

Spring Mvc 统一添加请求前缀

解决方法

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
@Configuration
public class WebMvcPrefixConfig implements WebMvcConfigurer {

    // 全局前缀(所有 Controller)
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        // 添加统一前缀 /api/v2
        configurer.addPathPrefix("/api/v2", clazz -> true);
        // 若需仅对特定包下的 Controller 加前缀:
        // configurer.addPathPrefix("/api/v2", clazz -> clazz.getPackageName().startsWith("com.example.controller.api"));
    }

    // (可选)方案 2.2:自定义 HandlerMapping(进阶,可兼容更多场景)
    @Bean
    public RequestMappingHandlerMapping requestMappingHandlerMapping() {
        RequestMappingHandlerMapping handlerMapping = new RequestMappingHandlerMapping();
        // 设置全局前缀
        handlerMapping.setPrefix("/api/v2");
        return handlerMapping;
    }
}

禁用win快捷键

操作

  1. 按下 Win+ R 快捷键,运行 regedit 打开注册表。
  2. 找到路径 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies
  3. 新建子项 System, 创建DWORD(32位元)的DisableLockWorkstation,值为1。

参考

禁用win + L

16 CountDownLatch

jdk 基于 8 版本

在平时的开发中,我们经常会用到 CountDownLatch, 它是用于线程通信的工具类。
常用使用场景就是,主线程等待子线程操作完成,然后继续执行

使用方式

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
public class CountDownLatchTest {

    @Test
    @SneakyThrows
    void test() {
        CountDownLatch countDownLatch = new CountDownLatch(1);
        System.out.println(Thread.currentThread() + ": 1");

        new Thread(() -> {
            System.out.println(Thread.currentThread() + ": 2");
            countDownLatch.countDown();
        }).start();

        System.out.println(Thread.currentThread() + ": 3");
        countDownLatch.await();
        System.out.println(Thread.currentThread() + ": 4");
    }
}

执行结果: