How to realize the change between Chinese and English in springboot
How to achieve Chinese and English changes in springboot, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
Html: Chinese
English
Controller:
@ RequestMapping ({"/", "index.html"})
Public String index () {return "index";} rewrite the LocaleResolver class
Public class MylocalResolver implements LocaleResolver {
[@ Override] (https://my.oschina.net/u/1162528)public Locale resolveLocale (HttpServletRequest request) {String l = request.getParameter ("l"); System.out.println (l); / / default request header Locale local=Locale.getDefault (); if (! StringUtils.isEmpty (l)) {String split [] = l.split ("_"); System.out.println (split [0]) Local = new Locale (split [0], split [1]);} return local;} [@ Override] (https://my.oschina.net/u/1162528)public void setLocale (HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {}
/ / inject @ Configuration into the container
Public class myConfig extends WebMvcConfigurerAdapter {
@ Beanpublic LocaleResolver localeResolver () {return new MylocalResolver ();}
}
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.