Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the internationalization process of SpringBoot

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

How to understand SpringBoot to achieve internationalization process, 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.

Implementation method: thymeleaf template engine plus BootStrap

Preparatory work:

1. Put the prepared Bootstrap template under templates and let SpringBoot configure it automatically.

SpringBoot auto configuration will automatically (idea shif key double press to enter the global search)

The introduction of 2.Bootstrp (here maven is introduced in the form of depency)

Org.webjars bootstrap 4.0.0

The introduction of 3.thymeleaf

Org.springframework.boot spring-boot-starter-thymeleaf

4. Write internationalization profile

Use ResourceBundleMessageSource to manage internationalized resource files

SpringBoot default configuration

The internationalized code that you configure yourself:

Package com.zyb.webdemo.component;import org.springframework.web.servlet.LocaleResolver;import org.thymeleaf.util.StringUtils;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.util.Locale;/** * carries region information on the link * / public class MyLocaleResolver implements LocaleResolver {@ Override public Locale resolveLocale (HttpServletRequest request) {String l = request.getParameter ("l"); Locale locale = Locale.getDefault () If (! StringUtils.isEmpty (l)) {String [] split = l.split ("_"); locale = new Locale (split [0], split [1]);} return locale;} @ Override public void setLocale (HttpServletRequest request, HttpServletResponse response, Locale locale) {}}

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report