使用MessageFormat动态拼接字符串举例
源码:
String p = "测试:{0},{1},{2}"; String r = MessageFormat.format(p, "11", "22", "33"); String p2 = "'{'"prepareTypeCode":"commonStock","skc":"{0}","type":"skc"'}'"; String r2 = MessageFormat.format(p2, "shoes123"); String p3 = "SELECT {0} from dms_order a JOIN dms_order_size b ON a.id=b.order_id where a.skc = ''{1}''"; String r3 = MessageFormat.format(p3, "id", "shoes123");
运行结果:
测试:11,22,33 {"prepareTypeCode":"commonStock","skc":"shoes123","type":"skc"} SELECT id from dms_order a JOIN dms_order_size b ON a.id=b.order_id where a.skc = 'shoes123'