05、SpringBoot集成SpringSecurity实战:登录成功响应Json

前言

在前后端分离项目中,页面的跳转都是交由前端来处理,后端只需要返回Json数据即可。

实现

使用之前写好的统一返回结果类Result,并将Result对象转化成json字符串响应。

@Component
public class SignInSuccessHandler implements AuthenticationSuccessHandler {
   
   
     
    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication
            authentication) throws IOException {
   
   
     
        Result success = Result.ok().message("登录成功!");
        response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE)

版权声明:本文不是「本站」原创文章,版权归原作者所有 | 原文地址: