我有一个视图来检索公开的密码,但不会调用控制器,只有在用户登录并通过url进入此视图时,该视图才有效。我正在将Spring Boot 1.5.14与弹簧安全性配合使用。
function validar(){
var codigo= $('#codigo').val();
$.ajax({
type : "GET",
url : "/host/validar",
data: {
"codigo" : codigo
},
success: function(result) {
alert("success");
},
error : function(e) {
alert("error");
}
});
}
带有百里香的html
<div class="x_content">
<section class="text-center">
<h5><span>Ingrese codigo</span></h5>
<form id="formValidar">
<div>
<input type="text" class="form-control" placeholder="codigo" required="" id="codigo" name="codigo" />
</div>
<br>
<div>
<button class="btn btn-dark" type="button" onclick="validar()">Validar</button>
</div>
</form>
</section>
</div>
控制器
@RequestMapping(value = "/validar", method = RequestMethod.GET)
public @ResponseBody String validar(
@RequestParam("codigo") String codigo){
System.out.println("entro sdgsdgdsg");
System.out.println("codigo: "+codigo);
Usuario usuario = usuarioService.buscarPorCodigo(codigo);
if (usuario == null){
return "pagina-validar";
}
return "nueva-pagina";
}
编辑:添加配置安全性。
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/css/**", "/js/**","/images/**","/build/**","/vendors/**","/recuperar-clave","/nueva-clave").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.successHandler(successHandler)
.loginPage("/login").permitAll()
.and()
.logout().permitAll();
}