ResponseBodyAdvice 对于控制器: @Controller @RequestMapping("/test") private static class TestController { @GetMapping("/hello") @ResponseBody public User hello() { return new User("Tom", 20); } } hello方法调用后的响应体: {"name":"Tom","age":20} 详细调用过程见源码。 …
ResponseBodyAdvice 对于控制器: @Controller @RequestMapping("/test") private static class TestController { @GetMapping("/hello") @ResponseBody public User hello() { return new User("Tom", 20); } } hello方法调用后的响应体: {"name":"Tom","age":20} 详细调用过程见源码。 …
Formatter Spring 用于类型转换的接口: Printer:将其它类型转换为字符串 Parser:将字符串转换为其它类型 Formatter:同时具备 Printer 和 Parser 的功能 Converter:将一种类型 S 转换为另一种类型 T(不限制类型的类型转换) Converters:将上述类型转换接口封装成标准的GenericConverter 接口,并组成集合使用 ConversionService:转换服务,通过 Converters 完成转换 PropertyEditor Sprin…
全局和局部 initBinder @InitBinder注解定义的方法不仅可以在 Controller 中添加,还可以在@ControllerAdvice定义的类中: @ControllerAdvice private static class MyControllerAdvice { @InitBinder public void globalInitBinder(WebDataBinder binder) { } } Controller 中的 InitBinder 方法仅对所在的 Contro…
有时候,需要在项目中加入一些配置文件或“框架代码”,比如在测试环境添加一个简单的 Logback 配置文件: <?xml version="1.0" encoding="UTF-8"?> <configuration> <include resource="org/springframework/boot/logging/logback/base.xml"/> <logger name="org.springframework" level="INFO"/>…
HomeBrew 是一个 Linux/MacOS 平台的包管理工具,下面是 Linux 平台安装说明。 官网地址 Homebrew。 从网络下载安装脚本并执行: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 从 Github 下载脚本,可能需要魔法。 如果网络不稳定,可以先通过wget将脚本下载下来,再单独执行。 安装时候会要求输入管理员密码,输入后继续。 安装完成后会出…
查看当前已安装的 WSL 版本: ❯ wsl -l -v NAME STATE VERSION * Ubuntu Running 2 进入 WSL,运行命令查看具体的发行版版本号: icexmoon@Awalon:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.6 LTS Release: …
在前文中介绍了用于处理控制器方法的参数解析器和返回值解析器,本篇文章展开讨论 Spring 框架提供的不同类型的参数解析器的用途。 添加一个控制器类: @Controller @RequestMapping("/test") private static class TestController { @GetMapping public String test(@RequestParam String name, @RequestParam Integer a…
Spring 中,用于加载和启动 Web Server 的容器类型是AnnotationConfigServletWebServerApplicationContext: AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext(Config.class); new CountDownLatch(1).await(); 其配置类需要至少三个 B…
通过代理实现 AOP 下面演示怎么通过代理实现 AOP。 需要被 AOP 的类: interface Hello{ void sayHello(); void sayBye(); } static class Target implements Hello{ @Override public void sayHello() { System.out.println("Hello World"); } @Override public void sayBy…
有时候需要在代码中使用某个类的完整包名,比如: pointcut.setExpression("@annotation(org.springframework.transaction.annotation.Transactional)"); 大概有相当一部分人会先找到Transactional这个注解,再手动复制上边的包名,然后拼接: 实际上有个更方便的方式: 找到该注解,在其上右键选择复制引用,就可以将其完整类名复制到剪贴板。 当然也可以在注解定义文件中的类名上操作,效果是相同的。 当然也可以对类文件执行类似的操…
魔芋红茶
加一点PHP,加一点Go,加一点Python......
COPYRIGHT © 2021 icexmoon.cn. ALL RIGHTS RESERVED.
本网站由提供CDN加速/云存储服务
Theme Kratos Made By Seaton Jiang