Java占位符替换

Java 占位替换
Java 替换源码:package  personal .caojx .placeholder ;import  org .apache mons .text .StringSubstitutor ;import  java .text .MessageFormat ;import  java .util .HashMap ;import  java .util .Map ;/** * 占位符替换,⼯具类 * * @author caojx  * @version $Id: PlaceholderUtil.java,v 1.0 2019-05-09 20:32 caojx  * @date 2019-05-09 20:32 */public  class  PlaceholderUtil {    public  static  void  main (String [] args ) {        //⽅式1 按位替换        String templateResult1 = String .format ("%s is at the age of %s", "john", "26");        System .out .println (templateResult1);        //⽅式2 数组索引位替换        Object [] object = new  Object []{"john", "24"};        MessageFormat messageFormat = new  MessageFormat ("{0} is at the age of {1}");        String templateResult2 = messageFormat .format (object );        System .out .println (templateResult2);        //⽅式3 ${} 替换        /*        *  引⼊commons-text          *  <dependency>        *      <groupId>s</groupId>        *      <artifactId>commons-text</artifactId>        *      <version>1.6</version>        *  </dependency>        * */        Map <String , String > paramMap = new  HashMap <>();        paramMap .put ("name", "john");        paramMap .put ("age", "27");        //s.text.StringSubstitutor        StringSubstitutor stringSubstitutor = new  StringSubstitutor (paramMap );        String template3 = "${name} is at the age of ${age}";        String templateResult3 = stringSubstitutor .replace (template3);        System .out .println (templateResult3);    }}1
调浆桶
2
3
4
5
6
7
8
9
10
11
12
13
14
widevine15
16
17
18
19
20149aa
21
22
23
24
25
26
27
28
29
30
31
32
33酚醛胶
34
35
36
37
38
39
windows下刷bios40
41
42
43
44
45
弹簧包
46
47
48

本文发布于:2024-09-21 13:55:28,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/2/107319.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:替换   占位   源码   数组
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议