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>

    结果展示:

  • 相关阅读:
    Python多线程笔记(三),queue模块
    Python多线程笔记(二)
    Python多线程笔记(一)
    Python3对时间模块的操作
    解决 ImportError: No module named 'pip._internal'问题
    Python字符串的操作
    Python 的AES加密与解密
    第十一周学习进度报告
    各组建议
    用户场景分析
  • 原文地址:https://www.cnblogs.com/ly-radiata/p/4380903.html
Copyright © 2011-2022 走看看