zoukankan      html  css  js  c++  java
  • JavaWeb学习记录(二十二)——模式字符串与占位符

    一、Java代码案例

    @Test
        public void test10(){
            int planet=7;
            String event="a disturbance in the Force";
            
            String result=MessageFormat.format("At {1,time} on {1,date},there was {2} on planet {0,number,integer}", planet,new Date(),event);
            System.out.println(result);
            
            //At 14:41:12 on 2015-3-31,there was a disturbance in the Force on planet 7
        }

    二、网页中的案例

    在.properties文件中加入以下内容

    msgs=At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.

    在jsp文件中的用法:

     <!-- 定义使用的日期 -->
                  <fmt:parseDate value="2015-3-31 10:36:47" pattern="yyyy-MM-dd HH:mm:ss" var="t1"/>
                 <!-- 定义使用的数字 -->
                  <fmt:parseNumber value="7" type="number" var="tnum"/>
                 <h1>动态文本</h1>
                 
                 <!-- 使用基名 -->
                 <fmt:bundle basename="hytc">
                 <!-- 输出的文本名称key -->
                  <fmt:message key="msgs">
                      <!-- 整数 -->
                      <fmt:param value="${tnum}"/>
                      <!-- 日期 -->
                      <fmt:param value="${t1}"/>
                      <!-- 字符串 -->
                      <fmt:param value="chenhj"/>
                  </fmt:message>
                 </fmt:bundle>

    结果展示:

  • 相关阅读:
    centos搭建window下写的flask程序
    【MTK】iwpriv命令说明
    vs2019专业版离线安装方法
    Python文件编译成exe
    python3升级与安装
    谷歌浏览器https和flash禁用的解决方法
    SQL注入常见函数
    nmap简介与运用
    WPF 万维网对战象棋 客户端+服务端(全套可执行代码在文章末尾)
    《软件工程实践》2020春季学期教学回顾--线上教学,化弊为利
  • 原文地址:https://www.cnblogs.com/ly-radiata/p/4380903.html
Copyright © 2011-2022 走看看