Spring
Internationalization
需要注入thymeleaf套件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
加入 @Bean 與 攔截器
@Configuration
public class WebMvcConfigurer extends WebMvcConfigurerAdapter {
/**
* 攔截器
* @return
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor());
}
/**
* 預設本地語言
* @return
*/
@Bean
public LocaleResolver localeResolver() {
SessionLocaleResolver slr = new SessionLocaleResolver();
slr.setDefaultLocale(Locale.TAIWAN);
return slr;
}
/**
* 修改語言
* @return
*/
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
lci.setParamName("lang");//根據取得GET[lang]的值,來決定顯示哪種語言
return lci;
}
}
greeting=你好
lang.change=選擇語言
lang.en=英文
lang.ch=中文
greeting=Hello! Welcome to our website!
lang.change=Change the language
lang.en=English
lang.ch=Chinese
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:th="http://www.thymeleaf.org">
<xsl:output
encoding="UTF-8"
media-type="text/html"
method="html"
indent="no"
omit-xml-declaration="yes"
/>
<xsl:template match="/">
<HTML lang="zh-TW" >
<HEAD>
<TITLE>首頁</TITLE>
<SCRIPT src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></SCRIPT>
<SCRIPT src="/page.js"></SCRIPT>
</HEAD>
<BODY>
<xsl:apply-templates select="document"/>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="document">
<H1 th:text="#{greeting}"></H1>
<SPAN th:text="#{lang.change}"></SPAN>
<SELECT id="locales">
<OPTION value=""></OPTION>
<OPTION value="ch" th:text="#{lang.ch}"></OPTION>
<OPTION value="en" th:text="#{lang.en}"></OPTION>
</SELECT>
</xsl:template>
</xsl:stylesheet>
根據GET[lang]的值決定要預設的語言包
Learn More →
Learn More →
前往 Spring Security
前往 Spring Security Acl
前往 Spring Boot Redis
前往 Spring Security防止暴力破解身份驗證
一、建立檔案 .gitignore //不上傳檔案 二、指令 git --version //檢查版本 git init //初始化git git add [--all] //加入檔案 git add -f [filename] //強制加入檔案 git commit -m "mag" //建立儲存檔 git config user.name "name" //使用者名稱
Feb 22, 2021SQL MongoDB 說明 database database 資料庫 table collection
Oct 7, 2020專案架構 com.zygroup.ilnd config CustomerConfig 第一個資料庫Config ProductConfig 第二個資料庫Config model 第一個資料表
Oct 5, 2020/pom.xml <!-- https://github.com/google/guava --> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>28.1-jre</version> </dependency> Guava is a set of core Java libraries from Google that includes new collection types (such as multimap and multiset), immutable collections, a graph library, and utilities for concurrency, I/O, hashing, caching, primitives, strings, and more! It is widely used on most Java projects within Google, and widely used by many other companies as well. https://github.com/google/guava
Mar 5, 2020or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up