版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ouyang111222/article/details/53586331
问题描述
velocity中设置如下,而$!{users}输出默认进行html转义,users为后端一个List对象
var USERS = '$!{users}';
user对象如下:
public class User{
private String name;
private int age;
private String department;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
@Override
public String toString() {
return JSON.toJSONString(this);
}
}
运行之后其前端USERS变量如下:
var USERS = '[{"age":20,"department":"devlop","name":"xiaoming"}, {"age":25,"department":"test","name":"xiaohua"}]';
引号全部被转义成:
"
解决方法
而现实却不想对其进行转义,怎么办?
var USERS = #noescape()$!{users}#end;
其结果如下:
var USERS = [{"age":20,"department":"devlop","name":"xiaoming"}, {"age":25,"department":"test","name":"xiaohua"}];