
springboot笔记
sayshu
这个作者很懒,什么都没留下…
展开
-
springboot--跨域中HttpServletRequest不能共享数据
在注解上加入@CrossOrigin(allowedHeaders = "*",allowCredentials = "true")在前端的ajax请求中加入xhrFields:{withCredentials:true}原创 2022-02-21 16:07:02 · 384 阅读 · 0 评论 -
springboot笔记--数据校验的使用
数据校验在低版本的springboot中用的是hibernate validation要导入对应hibernate依赖但在高版本的springboot中,已经加入了validation的坐标直接使用<!-- hibernate 验证框架 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-原创 2022-02-16 22:23:43 · 414 阅读 · 0 评论 -
springboot笔记--自定义异常处理
自定义异常的使用1.首先自定义自己的异常/** * 自定义异常 * 目的:统一处理异常信息 * 便于解耦,拦截器、service与controller 异常错误的解耦, * 不会被service返回的类型而限制 */public class MyCustomException extends RuntimeException { private ResponseStatusEnum responseStatusEnum; public MyCustom原创 2022-02-16 22:22:47 · 570 阅读 · 0 评论 -
springboot笔记--拦截器的使用
拦截器使用1.首先定义一个类实现HandlerInterceptor接口中的三个方法preHandle 返回true放行,返回false拦截不做后续处理@Slf4jpublic class PassportInterceptor extends BaseController implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request,原创 2022-02-16 22:22:00 · 478 阅读 · 0 评论