-
全局异常处理
@RestControllerAdvice public class ExceptionConf { @ExceptionHandler public String handler(Exception e) { return "{\"status\":\"error\",\"mes\":\"" + e.getMessage() + "\"}"; } }
-
返回统一时间格式
可以参考上一篇文章,对于springboot的jackson配置
注入对象映射器,在中间做操作@Configuration public class MyConfig { /*能自动注入到jack2的转换器中*/ @Bean public ObjectMapper o1() { return new ObjectMapper() { private static final long serialVersionUID = 3525547493446290019L; { setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); } }; } }
-
参数转化
/*转换参数*/ @Bean public Converter<String, Date> o2() { return new Converter<String, Date>() { @Override public Date convert(String s) { try { return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(s); } catch (Exception e) { return null; } } }; }
统一时间处理
最新推荐文章于 2023-09-24 12:00:00 发布