I'm using thymeleaf on the front end of the application and I have the following configuration class, with the addViewControllers method in question:
@Configuration
public class WebConfig implements WebMvcConfigurer {
...
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("index");
registry.addViewController("/login").setViewName("login");
registry.addViewController("/admin/home").setViewName("adminhome");
registry.addViewController("/user/perfil/{email}").setViewName("userperfil");
registry.addViewController("/home").setViewName("home");
//registry.addViewController("/403").setViewName("403");
}
...
}
I was thinking that it would be responsible for modifying the urls shown in the browser bar, but did not do so. So I do not know what he does ..
I tested this url in one of the application's controllers, for example:
@Controller
@RequestMapping("user")
public class UserController {
private static final Logger LOG = LogManager.getLogger(UserController.class);
@Autowired
private UserService userService;
...
//metodo bastante simplificado..
@RequestMapping(value = "/perfil/{email}", method = RequestMethod.GET)
public ModelAndView perfil(@PathVariable("email") String email) {
ModelAndView view = new ModelAndView();
User user = userService.findByEmail(email);
view.addObject("user", user);
view.setViewName("usuario/perfil");
LOG.info("Metodo perfil");
return view;
}
...
}
So in the addViewControllers method I put:
registry.addViewController("/user/perfil/{email}").setViewName("userperfil");
imagining that in the browser it would look like this:
http://localhost:8080/userperfil
instead of:
http://localhost:8080/user/perfil/[email protected]
Besides what would be possible to define these "edited" urls?