springboot默认的json配置
springboot默认的json配置
1.@JsonIgnore
返回前端时对应字段不进行序列化返回
public class User {
@JsonIgnore
private String name;
}
2.@JsonFormat
日期格式化
public class User {
@JsonFormat(pattern = "yyyy-mm-dd HH:mm:ss")
private String date;
}
3.@JsonInclude
满足某种条件返回
public class User {
@JsonInclude(JsonInclude.Include.NON_NULL)
private String name;
}
4.@JsonProperty
指定字段的别名
public class User {
@JsonProperty("agx")
private String age;
}
Json国际化
在springboot的resources文件下创建i18n文件夹
文件夹下创建三个文件
1.messages.properties
user.query.success=查询成功
2.messages_en_US.properties
user.query.success=query success
3.messages_zh_CN.properties
user.query.success=查询成功
4.application.yml
spring:
messages:
basename: i18.message
5.书写测试Controller
package com.wangfan.controller;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
public class TestAAController {
@Resource
private MessageSource messageSource;
@GetMapping("/aa")
public String aa(){
return messageSource.getMessage("user.query.success", null, LocaleContextHolder.getLocale());
}
}
SpringBoot同一异常处理
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.method.HandlerMethod;
@ControllerAdvice
public class ExceptionDealController {
@ExceptionHandler(Exception.class)
public void handler(Exception ex, HandlerMethod method){
System.out.println("统一异常处理!");
System.out.println(ex.getMessage());
System.out.println(method.getBean().getClass());
System.out.println(method.getMethod().getName());
}
}
springboot默认的json配置的更多相关文章
- SpringBoot 默认json解析器详解和字段序列化自定义
前言 在我们开发项目API接口的时候,一些没有数据的字段会默认返回NULL,数字类型也会是NULL,这个时候前端希望字符串能够统一返回空字符,数字默认返回0,那我们就需要自定义json序列化处理 Sp ...
- 【2.0】使用默认日志slf4j配置
一.SpringBoot日志简介 SpringBoot使用Commons Logging进行所有内部日志记录,但底层日志实现保持开放状态.为Java Util Logging,Log4j2和Logba ...
- springBoot日志框架自动配置与原理
1.日志框架 小张:开发一个大型系统: 1.System.out.println(""):将关键数据打印在控制台:去掉?写在一个文件? 2.框架来记录系统的一些运行时信息: ...
- Springboot 禁用数据库自动配置
转载至:https://blog.csdn.net/wyw815514636/article/details/80846545 https://blog.csdn.net/knqi007/articl ...
- springboot核心技术(二)-----自动配置原理、日志
自动配置原理 配置文件能配置的属性参照 1.自动配置原理: 1).SpringBoot启动的时候加载主配置类,开启了自动配置功能 @EnableAutoConfiguration 2).@Enable ...
- spring boot @ResponseBody转换JSON 时 Date 类型处理方法,Jackson和FastJson两种方式,springboot 2.0.9配置fastjson不生效官方解决办法
spring boot @ResponseBody转换JSON 时 Date 类型处理方法 ,这里一共有两种不同解析方式(Jackson和FastJson两种方式,springboot我用的1.x的版 ...
- 配置和修改springboot默认国际化文件
SpringBoot默认国际化文件为:classpath:message.properties,如果放在其它文件夹中,则需要在application.properties配置属性spring.mess ...
- SpringBoot默认日志的使用方法及常用配置
SpringBoot默认采用slf4j+logback 的组合形式,但也提供对JUL.log4j2.Logback提供了默认配置. 我们使用IDEA的spring初始化创建一个springboot项目 ...
- springboot情操陶冶-web配置(四)
承接前文springboot情操陶冶-web配置(三),本文将在DispatcherServlet应用的基础上谈下websocket的使用 websocket websocket的简单了解可见维基百科 ...
- springboot情操陶冶-web配置(三)
承接前文springboot情操陶冶-web配置(二),本文将在前文的基础上分析下mvc的相关应用 MVC简单例子 直接编写一个Controller层的代码,返回格式为json package com ...
随机推荐
- solt废弃,报错解决方法
1.饿了么组件库给出得文字提示框 写到项目里之后报错 提示 solt已经废弃 <el-tooltip placement="top"> <div slot=&qu ...
- window向linux传递文件
1.需要在window建一个ftp的server 2.在linux的指定目录下输入: curl ftp://192.168.98.90/libalgorithm.so -u "embftp: ...
- 初始化centos环境脚本
#! /bin/bashecho "java环境初始化开始"#功能描述: Centos8.5系统自动初始化脚本#自动配置:IP地址\Yum源\docer\docker-compos ...
- 【Anaconda】Jupyter 中添加 Anaconda 环境
两种方法: 1. 安装 nb_conda_kernels,将所有 conda 环境同步至 Jupyter Notebook,参考『Jupyter notebook选择conda环境 - 简书』. 2. ...
- Kubernetes学习笔记(三)
[查看某个node上的pod] > kubectl get pods -o wide --namespace=kube-system | grep master-0 #node ...
- python manage.py loaddata dumpdata 用于导出和导入数据库中的数据
1.数据导出python manage.py dumpdata python manage.py dumpdata [appname] > appname_data.json 指定appna ...
- unity tex2Dlod in vert
https://forum.unity.com/threads/how-to-sample-a-texture-in-vertex-shader.513816/ GreatWall said: ↑ ...
- h5:vue3 + ts + vite + vuex + axios + vant4 + scss + postcss+mockjs+element-plus
模板地址:https://gitee.com/zhang_meng_lei/mobile-template-h5-vue3/tree/master 1.安装element-plus:yarn add ...
- Vue v-once指令 和 v-pre指令
v-once指令: 1.v-once 所在节点在初始化动态渲染后,就视为静态内容了 2.以后数据的改变不会引起v-once所在结构的更新,可用于优化性能 v-pre指令: 1.跳过其所在节点的编译过程 ...
- Oracle 会话锁死
需要管理员用户下执行(sys/sysdba) --先查锁 select * from v$lock where lmode > 0 and type in ('TM','TX'); --查用户名 ...