给别人弄一个小项目,随便找了个后台模板,然后模板引擎选了thymeleaf,发现有点玩不动。
js里面if判断&&时报了个错:在实体引用中,实体名称必须紧跟在'&' SAX解析异常。
controller返回的这个页面是使用sax解析的,thymeleaf是采用xml解析的方式进行替换的,所以javascript中&这样的xml实体转义字符会被识别为转义,所以会出sax解析错误。
xml里面我们怎么解决的?
<![CDATA[ ]]> <![CDATA[]]>标记所包含的内容为纯文本,里面想写什么就什么
这里面也是一样的,度了一下用法如下:
/*<![CDATA[*/ var exp = new Date(); exp.setTime(exp.getTime() + 60 * 1000 * 30 );//半小时 document.cookie = "token=" + data.token + ";expires=" + exp.toGMTString(); document.cookie = "name=" + data.name + ";expires=" + exp.toGMTString(); document.cookie = "mobile=" + data.mobile + ";expires=" + exp.toGMTString(); if (data!=null&&data.token!=null){ window.location.href = 'index' } /*]]>*/