security获取错误信息以及提示信息修改为中文

我的login_p是formLogin里面配置登陆路径,

 @GetMapping("/login_p")
    public ModelAndView loginPage(@RequestParam(value = "error",required = false) String error) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("error",error);
        modelAndView.setViewName("/login");
        return modelAndView;
    }

login.html部分代码

 <form th:action="@{/login}" method="post" class="login-form">
            <h2>登录页面</h2>

            <br>
            <label th:if="${param.error} ne null">
                <span style="color: red" th:if="${param.error}" th:text="${session?.SPRING_SECURITY_LAST_EXCEPTION?.message}">
				//重点是这句session的值
				
                </span></label>
            <br><br>

            <input placeholder="用户名" name="username" type="text">
            <input type="password" placeholder="密码" name="password">
            <button>登录</button>

            <p class="message"><a href="forget.html">找回密码</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:">立即注册</a></p>

        </form>

这样提示出来是英文,想要改为中文只需要再配置一个类


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;

//security中文提示信息配置类
@Configuration
public class ReloadMessageConfig {
    @Bean //加载中文认证提示信息
    public ReloadableResourceBundleMessageSource messageSource(){
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        //加载org/springframework/security包下的中文提示信息 配置文件
        messageSource.setBasename("classpath:org/springframework/security/messages_zh_CN");
        return messageSource;
    }
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值