Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize the change between Chinese and English in springboot

Shulou Source: shulou.com Published: 2022-06-02 09:09:47 10月04日 Update

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.

Tags: Help Chinese and English change clarity content containers for this articles novices more knowledge industry information information channels problems needs channels Chinese enter one learn Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information MySQL Redmi vpn Linux