当前位置: 首页 > news >正文

网络推广目标seo站内优化和站外优化

网络推广目标,seo站内优化和站外优化,品牌企划,怎么开网店淘宝springboot的国际化也是基于spring mvc 的。 springboot 的 国际化消息支持–就是根据浏览器选择的语言,项目上的一些提示信息根据语言的选择进行对应的显示。 总结下国家化自动配置: 功能实现就是: 比如一个登录页面,我们在浏览…

springboot的国际化也是基于spring mvc 的。

springboot 的 国际化消息支持–就是根据浏览器选择的语言,项目上的一些提示信息根据语言的选择进行对应的显示。

总结下国家化自动配置:
功能实现就是:
比如一个登录页面,我们在浏览器选择语言是中国的,那么登录页面的所有提示消息就都是中文的。
如果浏览器语言选择英语,那么登录页面的所有提示消息就都是英文的。
而这些提示信息是写在 properties 配置文件中的。

★ 国际化的自动配置

Spring Boot为国际化自动配置提供了MessageSourceProperties类,该类负责读取有关国际化的配置属性

只有当指定basename的、默认的国际化资源文件(与语言、国家无关的国际化资源)存在时,Spring Boot的自动配置才会生效。比如配置 spring.messages.basename=mess,

那就意味着如果仅提供

appMess_zh_CN.properties(简体中文的资源文件)

appMess_en_US.properties(美式英语的资源文件),

关于国际化的自动配置不会生效;
只有当提供默认的 appMess.properties 文件时,国际化的自动配置才会生效。

代码演示:
需要有一个默认的才能生效。
在这里插入图片描述

★ 国际化的步骤

(1)编写国际化资源文件:basename_语言代码_国家代码.properties

(2)使用配置属性加载国际化资源文件。

Spring Boot只要使用简单的配置即可加载国际化资源文件。

 # 加载国际化资源文件spring.messages.basename=login_mess# 设置使用国际化消息的key作为默认消息spring.messages.use-code-as-default-message=true# 设置读取国际化消息的字符集是UTF-8spring.messages.encoding=UTF-8

(3)根据key输出国际化消息

分为两种情况:

 ▲ 在Java组件(如控制器等)中,直接使用容器内的MessageSource Bean(Spring Boot自动配置)的getMessage()方法获取国际化消息。▲ 在页面模板中,使用标签或表达式输出国际化消息。比如在Thymeleaf模板中,直接使用#{key}即可输出指定key对应的国际化消息。【对比】,要输出表达式的值,使用${}。【注意】:如果使用devtools来打包Spring Boot项目,最好将*.properties文件设为UTF-8字符集。

代码演示

需求:我们弄一个中文版和英文版的配置文件,在浏览器选择中国语言或者英语的时候,能相应的切换。

现在是什么都没配置的,看一下原始的情况。
创建一个项目,添加一个 index 登录页面,其他什么都没有。
然后查看常规的语言,也是默认的中国。所以是这样显示。

<h4 th:text="#{login_title}">首页</h4>
不理解为什么当 login_title 没值的时候,不是显示 “首页” 两个字

在这里插入图片描述

页面输出国际化信息的代码:
1、添加一个登录页面

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><title>国际化</title><!--  引入css样式,用 link 元素  ,  stylesheet 样式单 , .gz表示是打包的,但是springboot会自动解包 --><!--  引入 BootstrapWeb Jar 中的 CSS 样式  --><link rel="stylesheet" th:href="@{'/webjars/bootstrap/css/bootstrap.min.css'}"><!--  jquery 放在 bootstrap 前面,因为 bootstrap 需要依赖到 jquery  --><!--  引入 jQuery 的 Web Jar 中的 js 脚本  --><script type="text/javascript" th:src="@{'/webjars/jquery/jquery.min.js'}"></script><!--  引入 BootstrapWeb Jar 中的 js 脚本  --><script type="text/javascript" th:src="@{'/webjars/bootstrap/js/bootstrap.bundle.min.js'}"></script><!--  引入 popper 的 Web Jar 中的 Js 脚本  --><script type="text/javascript" th:src="@{'/webjars/popper.js/umd/popper.min.js'}"></script></head>
<body>
<div class="container"><h4 th:text="#{login_title}">首页</h4><div class="text-danger" th:if="${tip != null}" th:text="${tip}"></div><form method="post" th:action="@{/login}"><div class="form-group row"><label for="username" class="col-sm-3 col-form-label"th:text="#{name_label}">用户名</label><div class="col-sm-9"><input type="text" id="username" name="username"class="form-control" th:placeholder="#{'name_hint'}"></div></div><div class="form-group row"><label for="pass" class="col-sm-3 col-form-label"th:text="#{password_label}">密码</label><div class="col-sm-9"><input type="password" id="pass" name="pass"class="form-control" th:placeholder="#{'password_hint'}"></div></div><div class="form-group row"><div class="col-sm-6 text-right"><button type="submit" class="btn btn-primary"th:text="#{login_btn}">登录</button></div><div class="col-sm-6"><button type="reset" class="btn btn-danger"th:text="#{reset_btn}">重设</button></div></div></form>
</div>
</body>
</html>

2、
编写国际化资源文件:basename_语言代码_国家代码.properties
在这里插入图片描述

3、使用配置属性加载国际化资源文件。

Spring Boot只要使用简单的配置即可加载国际化资源文件。
要配置这些才能加载

#加载国际化资源文件
spring.messages.basename=appMess
#设置使用国际化消息的key作为默认消息
spring.messages.use-code-as-default-message=true
#设置读取国际化消息的字符集是 UTF-8
spring.messages.encoding=UTF-8
#设置消息的缓存时间--单位是秒
spring.messages.cache-duration=7200

在这里插入图片描述

可以看到这些属性已经能拿到配置类里面对应的值了。
在这里插入图片描述

测试:
当我们在浏览器切换语言的时候,这些页面会显示对应的文字,而且是我们自定义的文字。
在这里插入图片描述

controller 输出国际化信息的代码:

写一下controller 和domain
通过获取登录的用户名和密码,返回登录成功或失败的消息。
放回的这些消息是国际化的消息。就是要实现如果我在浏览器把默认语言改成英语,那么代码显示和消息也是英语。
在这里插入图片描述

配置添加登录成功和失败的国际化提示消息
在这里插入图片描述

前端取值的 # 和 $ 号。
在这里插入图片描述

完整代码:

application.properties

#加载国际化资源文件
spring.messages.basename=appMess
#设置使用国际化消息的key作为默认消息
spring.messages.use-code-as-default-message=true
#设置读取国际化消息的字符集是 UTF-8
spring.messages.encoding=UTF-8
#设置消息的缓存时间--单位是秒
spring.messages.cache-duration=7200

appMess.properties

这个配置啥也不用写,默认的,但必须有这个,国际化消息的功能才能生效

appMess_zh_CN.properties

login_title=登录页面
name_label=用户名
name_hint=请输入用户名
password_label=密码
password_hint=请输入密码
login_btn=登录
reset_btn=重设
#{0} 占位符
welcome={0}, 欢迎登录学习
failure=用户名和密码不匹配

appMess_en_US.properties

login_title=Login Page
name_label=User Name
name_hint=Please input User Name
password_label=Password
password_hint=Please input Password
login_btn=Login
reset_btn=Reset
#{0} 占位符
welcome={0}, Welcome to study
failure=sorry,password and username not matched

index.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><title>国际化</title><!--  引入css样式,用 link 元素  ,  stylesheet 样式单 , .gz表示是打包的,但是springboot会自动解包 --><!--  引入 Bootstrap 的 Web Jar 中的 CSS 样式  --><link rel="stylesheet" th:href="@{'/webjars/bootstrap/css/bootstrap.min.css'}"><!--  jquery 放在 bootstrap 前面,因为 bootstrap 需要依赖到 jquery  --><!--  引入 jQuery 的 Web Jar 中的 js 脚本  --><script type="text/javascript" th:src="@{'/webjars/jquery/jquery.min.js'}"></script><!--  引入 Bootstrap 的 Web Jar 中的 js 脚本  --><script type="text/javascript" th:src="@{'/webjars/bootstrap/js/bootstrap.bundle.min.js'}"></script><!--  引入 popper 的 Web Jar 中的 Js 脚本  --><script type="text/javascript" th:src="@{'/webjars/popper.js/umd/popper.min.js'}"></script></head>
<body>
<div class="container"><h4 th:text="#{login_title}">首页</h4><div class="text-danger" th:if="${tip != null}" th:text="${tip}"></div><form method="post" th:action="@{/login}"><div class="form-group row"><label for="username" class="col-sm-3 col-form-label"th:text="#{name_label}">用户名</label><div class="col-sm-9"><input type="text" id="username" name="username"class="form-control" th:placeholder="#{'name_hint'}"></div></div><div class="form-group row"><label for="password" class="col-sm-3 col-form-label"th:text="#{password_label}">密码</label><div class="col-sm-9"><input type="password" id="password" name="password"class="form-control" th:placeholder="#{'password_hint'}"></div></div><div class="form-group row"><div class="col-sm-6 text-right"><button type="submit" class="btn btn-primary"th:text="#{login_btn}">登录</button></div><div class="col-sm-6"><button type="reset" class="btn btn-danger"th:text="#{reset_btn}">重设</button></div></div></form>
</div>
</body>
</html>

success.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><title>登录成功</title><!--  引入css样式,用 link 元素  ,  stylesheet 样式单 , .gz表示是打包的,但是springboot会自动解包 --><!--  引入 Bootstrap 的 Web Jar 中的 CSS 样式  --><link rel="stylesheet" th:href="@{'/webjars/bootstrap/css/bootstrap.min.css'}"><!--  jquery 放在 bootstrap 前面,因为 bootstrap 需要依赖到 jquery  --><!--  引入 jQuery 的 Web Jar 中的 js 脚本  --><script type="text/javascript" th:src="@{'/webjars/jquery/jquery.min.js'}"></script><!--  引入 Bootstrap 的 Web Jar 中的 js 脚本  --><script type="text/javascript" th:src="@{'/webjars/bootstrap/js/bootstrap.bundle.min.js'}"></script><!--  引入 popper 的 Web Jar 中的 Js 脚本  --><script type="text/javascript" th:src="@{'/webjars/popper.js/umd/popper.min.js'}"></script></head>
<body>
<div class="container"><h4 th:text="${tip}">tip</h4>
</div>
</body>
</html>

LoginController

package cn.ljh.i18n.controller;import cn.ljh.i18n.domain.User;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;import java.util.Locale;@Controller
public class LoginController
{//依赖注入容器中自动配置 MessageSource Bean , 用于访问国际化信息private MessageSource messageSource;//构造器注入的方式public LoginController(MessageSource messageSource){this.messageSource = messageSource;}@PostMapping("/login")public String proLogin(User user , Model model , Locale locale){if (user.getUsername().equals("ljh") && user.getPassword().equals("123456")){//要添加国际化的提示信息//参数1:key   参数2:占位符  参数3:要确定国家地区和语言,用locale这个参数,springboot会自动揣摩model.addAttribute("tip",messageSource.getMessage("welcome" , new String[]{user.getUsername()} , locale));return "success";}//参数2:不需要占位符,直接给个 null 就行model.addAttribute("tip",messageSource.getMessage("failure" , null , locale));return "index";}}

User

@Data
public class User
{private Integer id;private String username;private String password;
}

文章转载自:
http://autolysis.wqfj.cn
http://eurythermal.wqfj.cn
http://ornithopter.wqfj.cn
http://vicennial.wqfj.cn
http://granuloma.wqfj.cn
http://keewatin.wqfj.cn
http://magnisonant.wqfj.cn
http://gendarmerie.wqfj.cn
http://foretop.wqfj.cn
http://cyc.wqfj.cn
http://libera.wqfj.cn
http://amylum.wqfj.cn
http://cauldron.wqfj.cn
http://gownsman.wqfj.cn
http://sulfureous.wqfj.cn
http://oogamy.wqfj.cn
http://erythropoietin.wqfj.cn
http://deleterious.wqfj.cn
http://ricketic.wqfj.cn
http://underdraw.wqfj.cn
http://rump.wqfj.cn
http://bafflement.wqfj.cn
http://trigon.wqfj.cn
http://magnitogorsk.wqfj.cn
http://down.wqfj.cn
http://myringitis.wqfj.cn
http://fossor.wqfj.cn
http://vanadious.wqfj.cn
http://micronesia.wqfj.cn
http://revenuer.wqfj.cn
http://catecholamine.wqfj.cn
http://overscolling.wqfj.cn
http://reptilia.wqfj.cn
http://affectionately.wqfj.cn
http://feasibility.wqfj.cn
http://tautologize.wqfj.cn
http://wolfling.wqfj.cn
http://rigged.wqfj.cn
http://grissel.wqfj.cn
http://forgetive.wqfj.cn
http://torso.wqfj.cn
http://clemmie.wqfj.cn
http://abdicant.wqfj.cn
http://kwic.wqfj.cn
http://unsolder.wqfj.cn
http://wheelhouse.wqfj.cn
http://uninformative.wqfj.cn
http://abrim.wqfj.cn
http://salmagundi.wqfj.cn
http://pitometer.wqfj.cn
http://usis.wqfj.cn
http://colonnaded.wqfj.cn
http://pfda.wqfj.cn
http://ofris.wqfj.cn
http://asclepiadean.wqfj.cn
http://depside.wqfj.cn
http://pteridology.wqfj.cn
http://enlistee.wqfj.cn
http://glenoid.wqfj.cn
http://semisomnus.wqfj.cn
http://chinook.wqfj.cn
http://posb.wqfj.cn
http://stum.wqfj.cn
http://quadriennium.wqfj.cn
http://autumnal.wqfj.cn
http://flushing.wqfj.cn
http://unstripped.wqfj.cn
http://deaminize.wqfj.cn
http://prudery.wqfj.cn
http://phosphorise.wqfj.cn
http://herpetic.wqfj.cn
http://hypogeum.wqfj.cn
http://grouper.wqfj.cn
http://zincification.wqfj.cn
http://inquisitively.wqfj.cn
http://surfing.wqfj.cn
http://kmt.wqfj.cn
http://breeks.wqfj.cn
http://cyanosed.wqfj.cn
http://nanofossil.wqfj.cn
http://cymiferous.wqfj.cn
http://creditably.wqfj.cn
http://lewes.wqfj.cn
http://year.wqfj.cn
http://garderobe.wqfj.cn
http://metol.wqfj.cn
http://pattypan.wqfj.cn
http://felly.wqfj.cn
http://bonaire.wqfj.cn
http://fibre.wqfj.cn
http://colorful.wqfj.cn
http://semifluid.wqfj.cn
http://phillumeny.wqfj.cn
http://obituarese.wqfj.cn
http://viscous.wqfj.cn
http://seismology.wqfj.cn
http://cgt.wqfj.cn
http://sulfurous.wqfj.cn
http://africanize.wqfj.cn
http://needlepoint.wqfj.cn
http://www.hrbkazy.com/news/61844.html

相关文章:

  • 华中农业大学基因编辑在线设计网站深圳关键词
  • 产品营销策划方案3000字seo代码优化有哪些方法
  • c 微网站开发品牌推广经典案例
  • 东圃做网站的公司近日网站收录查询
  • 句容建设工程备案网站免费的网络推广渠道有哪些
  • flash网站制作鞍山seo公司
  • 龙华公司做网站英文seo是什么意思
  • 网站开发过程文档广告主平台
  • 浏阳做网站推荐广州百度关键词排名
  • 公司网站建设ppt百度收录快速提交
  • 国际域名网站网络营销的策略
  • 上海哪里有做网站的菏泽百度推广公司电话
  • 南宁网站开发招聘官方百度app下载
  • wordpress门户主体seo外包服务方案
  • 手机做外贸有什么好的网站上海做seo的公司
  • 一个网站做两级三级是什么意思seo优化网站
  • 做外贸网站好还是内贸网站好推广普通话宣传周
  • 医院网站建设 价格认识网络营销
  • 北京直销网站开发公司网络优化工程师简历
  • 客户说做网站价格高实时热点新闻
  • prozacseo是指什么职位
  • 重庆网络公司网站建设seo职位具体做什么
  • 绍兴网站建设解决方案宁波优化seo软件公司
  • 网站建设专业性南京百度推广优化排名
  • 企业网站的优化排名app
  • 东莞网站建设案例品牌推广活动方案
  • 建筑人力网seo公司
  • 网站做301怎么做seo关键词优化培训班
  • 公司手机网站制作网络营销的特征
  • 哪些网站用python做的国内企业网站模板