常规的模板引擎是传入 template 和 params,得到 content,我想要根据 content 和 template 得到 params,有什么好办法吗?
1 zhaishunqi 2019-07-30 13:06:43 +08:00 正则 |
2 lituancheng OP @zhaishunqi 正则的话只能处理 value 为 String 的,如果 value 是 List 类型的,就没法处理了啊 |
3 DsuineGP 2019-07-30 15:33:06 +08:00 @lituancheng 正则捕获组 |
4 lituancheng OP |
5 lituancheng OP @DsuineGP 假设 content 为: 姓名:张三 年龄:20 姓名:李四 年龄:21 姓名:王五 年龄:22 template 为: <#list personList as person> 姓名:${person.name} 年龄:${person.age} </#list> 以上这种的没办法根据正则得到原始 personList 的,关键点在于 template 不知道 list 的实际条数 |
6 DsuineGP 2019-07-31 09:14:05 +08:00 @lituancheng 为啥不写 for 循环再用正则匹配呢 |
7 DsuineGP 2019-07-31 09:17:47 +08:00 @lituancheng 如果是模版渲染的是 HTML 还有一些 dom 解析的框架可以用,你这个渲染出来的是文本,只能一行一行的正则匹配 |