Sring boot学习笔记(二)
2017-07-19 00:00
295 查看
1.常用注解标签:
2.yml文件配置替代properties文件
application.yml 文件位于src/main/resources文件夹下
3.国际化
首先我们先定义国际化资源文件,spring boot默认就支持国际化的,而且不需要你过多的做什么配置,只需要在resources/下定义国际化配置文件即可,注意名称必须以messages开发。
我们定义如下几个文件:
messages.properties (默认,当找不到语言的配置的时候,使用该文件进行展示)。
messages_zh_CN.properties(中文)
messages_en_US.properties(英文)
具体的代码如下:
messages.properties:
messages_en_US.properties:
前端展示使用#{key}的方式进行使用messages中的字段信息:
@Controller:修饰class,用来创建处理http请求的对象
@RestController:Spring4之后加入的注解,原来在
@Controller中返回json需要
@ResponseBody来配合,如果直接用
@RestController替代
@Controller就不需要再配置
@ResponseBody,默认返回json格式。
@RequestMapping:配置url映射
2.yml文件配置替代properties文件
application.yml 文件位于src/main/resources文件夹下
# spring 配置 spring: # 当前激活配置项 profiles: active: dev # thymeleaf 配置 thymeleaf: cache: false check-template-location: true content-type: text/html enabled: true encoding: utf-8 excluded-view-names: mode: HTML5 prefix: classpath:/templates/ suffix: .html template-resolver-order: # HTTP ENCODING http: encoding.charset: UTF-8 encoding.enabled: true encoding.force: true
3.国际化
首先我们先定义国际化资源文件,spring boot默认就支持国际化的,而且不需要你过多的做什么配置,只需要在resources/下定义国际化配置文件即可,注意名称必须以messages开发。
我们定义如下几个文件:
messages.properties (默认,当找不到语言的配置的时候,使用该文件进行展示)。
messages_zh_CN.properties(中文)
messages_en_US.properties(英文)
具体的代码如下:
messages.properties:
welcome=欢迎光临本站!
messages_en_US.properties:
welcome=Welcome to our weijuer's website!
前端展示使用#{key}的方式进行使用messages中的字段信息:
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.w3.org/1999/xhtml"> <head> <meta charset="UTF-8" /> <title>weijuer Demos</title> </head> <body> <p th:text="#{welcome}">Welcome to weijuer's store!</p> <p>Today is: <span th:text="${today}">13 February 2011</span></p> <p>Established locale country: <span th:text="${#locale.country}">US</span></p> </body> </html>
相关文章推荐
- Sring boot学习笔记(一)
- Spring事务异常回滚,捕获异常不抛出就不会回滚
- 在Eclipse下使用Maven开发Spring Boot应用
- Maven简介
- Spring Boot 添加MySQL数据库及JPA
- Spring基础知识汇总
- Spring Bean 中的线程安全
- 湖南生第八届大学生程序设计大赛原题 C-Updating a Dictionary(UVA12504 - Updating a Dictionary)
- spring REST 不能映射问题解决
- Spring--使用 Spring 进行单元测试
- [Python]学习基础篇:字符串的处理
- 前端修炼H5篇--视频音频
- go-grpc 使用
- canvas-任意画多个凸多边形
- Maven下载不了jar包。自己下载到本地装载到本地Maven仓库。
- 有听过abspeak在线英语的吗,abspeak英语怎么样?
- ArcGIS Server10.1 +Oracle11g直接连接数据库发布地图,数据增删改查,MapServer实时更新方法
- Android 百分比布局库(percent-support-lib) 解析与扩展
- log4j.properties配置详解与实例-全部测试通过
- 设计模式之工厂模式(一)