Project introduced some considerations of thymeleaf

Used in the project thymeleaf foreground and development notes together

1. Because thymeleaf labels have th:a prefix, the editor is not being given that recognize th: * like properties when parsing the page and without any problems, if you think this is wrong upset, please join in at the beginning of the document html as follows:

<html  xmlns:th="http://www.thymeleaf.org"></html>

2. to develop front-end process, the referenced resources are static resources, clearly does not meet the needs of dynamic pages. How to do it?
When we want to introduce some CSS static when I introduced like this
<link rel="stylesheet" type="text/css" href="../../../static/css/public.css"/>
dynamic is introduced in this way
<link rel="stylesheet" type="text/css" th:href="@{/static/css/public.css}"/>
in order to be able to properly refer to the local style, along with the need to Talia wrote:
<link rel="stylesheet" type="text/css" href="../../../static/css/public.css" th:href="@{/static/css/public.css}"/>
do not worry about the extra attributes, thymeleaf is handled automatically.
3. Many times we need to get the back end of the variable js front end. Before we get the best variable settings

<script type="text/javascript" th:inline="javascript">
    /*<![CDATA[*/

    /*]]>*/
</script>

Get the value:

<script type="text/javascript" th:inline="javascript">
    /*<![CDATA[*/
    var username = /*[[${sesion.user.name}]]*/ 'zhangsan';
    /*]]>*/
</script>

In the static pages of its analytical results are:

<script type="text/javascript">

    var username = 'zhangsan';

</script>

In its dynamic page analysis result is:

<script type="text/javascript">

    var username = 'admin';//获取session.user.name

</script>

3. Use thymeleaf page inheritance, when included, if the project configure the jsp and thymeleaf template, and configure access rules based on .html / .jsp form. Include Inherited failure.
Solution:
Modify viewNames property. Back To form prefix .for example:

return "html/index";
return "jsp/index";

After thymeleaf continue to supplement the pit.

Published 22 original articles · won praise 9 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_19408473/article/details/71542461