<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    不做浮躁的人
    正在行走的人...
    posts - 171,  comments - 51,  trackbacks - 0
    1、使用的是Spring EL而不是Ognl。
    2、訪問上下文的Bean用${@myBean.doSomething()}
    3、th:field,th:errors,th:errorclass用于form processing。
    4、要采用SpringTemplateEngine。
    5、基本配置:
    <bean id="templateResolver"
           class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
      <property name="prefix" value="/WEB-INF/templates/" />
      <property name="suffix" value=".html" />
      <property name="templateMode" value="HTML5" />
    </bean>
        
    <bean id="templateEngine"
          class="org.thymeleaf.spring3.SpringTemplateEngine">
      <property name="templateResolver" ref="templateResolver" />
    </bean>

    <bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
      <property name="templateEngine" ref="templateEngine" />
      <property name="order" value="1" />
      <property name="viewNames" value="*.html,*.xhtml" />
    </bean>

    6、被@ModelAttribute注釋的方法會在此controller每個方法執行前被執行,如果@ModelAttribute注釋的方法有返回值,則表示在model中存放隱含名稱的屬性對象,比如返回Account,則相當于model.addAttribute("account",account),如果@ModelAttribute(value="aname")注釋方法,則表示在model中增加aname的屬性值。@ModelAttribute注釋一個方法的參數則表示從model中或者從Form表單或者url中獲取。
    7、 @RequestMapping("/hello")public void novoid() { },返回視圖為前綴+/hello+后綴,當方法返回Map,ModelMap等時都是相當于Request.setAttribute()。
    8、<td th:text="${{sb.datePlanted}}">13/01/2011</td>雙括號表示自動使用轉換,常用于格式轉換。
    9、<td th:text="${#strings.arrayJoin(#messages.arrayMsg(#strings.arrayPrepend(sb.features,'seedstarter.feature.')),', ')}">Electric Heating, Turf</td>,首先將數組feathers都加上前綴,然后利用messages翻譯國際化,最終組合成一個字符串。
    10、用th:object指定command object,比如:<form action="#" th:action="@{/save}" th:object="${person}" method="post">,兩點限制,第一object只能是model 的直接attribute,不能使${person.baseInfo},第二,th:object的子級標簽內不能再使用th:object。inputField使用:<input type="text" th:field="*{datePlanted}" />。
    12、checkbox標簽:
    <div>
      <label th:for="${#ids.next('covered')}" th:text="#{seedstarter.covered}">Covered</label>
      <input type="checkbox" th:field="*{covered}" />
    </div>
    checkbox array:
    <ul>
      <li th:each="feat : ${allFeatures}">
        <input type="checkbox" th:field="*{features}" th:value="${feat}" />
        <label th:for="${#ids.prev('features')}" th:text="#{${'seedstarter.feature.' + feat}}">Heating</label>
      </li>
    </ul>

    13、radios:
    <ul>
      <li th:each="ty : ${allTypes}">
        <input type="radio" th:field="*{type}" th:value="${ty}" />
        <label th:for="${#ids.prev('type')}" th:text="#{${'seedstarter.type.' + ty}}">Wireframe</label>
      </li>
    </ul>

    14、dropdownlist or select。
    <select th:field="*{type}">
      <option th:each="type : ${allTypes}"
              th:value="${type}"
              th:text="#{${'seedstarter.type.' + type}}">Wireframe</option>
    </select>

    15、預處理:<select th:field="*{rows[__${rowStat.index}__].variety}">而不使用<select th:field="*{rows[rowStat.index].variety}">,因為spring el不會計算數組索引中的變量或者表達式。
    16、錯誤顯示:<input type="text" th:field="*{datePlanted}" th:class="${#fields.hasErrors('datePlanted')}? fieldError" />
    <ul>
      <li th:each="err : ${#fields.errors('datePlanted')}" th:text="${err}" />
    </ul>

    <input type="text" th:field="*{datePlanted}" />
    <p th:if="${#fields.hasErrors('datePlanted')}" th:errors="*{datePlanted}">Incorrect date</p>

    <input type="text" th:field="*{datePlanted}" class="small" th:errorclass="fieldError" />

    <ul th:if="${#fields.hasErrors('*')}">
      <li th:each="err : ${#fields.errors('*')}" th:text="${err}">Input is incorrect</li>
    </ul>
    全局錯誤:
    <ul th:if="${#fields.hasErrors('global')}">
      <li th:each="err : ${#fields.errors('global')}" th:text="${err}">Input is incorrect</li>
    </ul>
    在form外顯示錯誤:
    <div th:errors="${myForm}">...</div>
    <div th:errors="${myForm.date}">...</div>
    <div th:errors="${myForm.*}">...</div>

    <div th:if="${#fields.hasErrors('${myForm}')}">...</div>
    <div th:if="${#fields.hasErrors('${myForm.date}')}">...</div>
    <div th:if="${#fields.hasErrors('${myForm.*}')}">...</div>

    <form th:object="${myForm}">
        ...
    </form>
    17、利用功能類轉換:#conversions.convert(Object,Class),#conversions.convert(Object,String)
    18、渲染模板的片段,常用于ajax,返回一部分文本做替換使用。
    在ViewBean中指定片段:
    <bean name="content-part" class="org.thymeleaf.spring3.view.ThymeleafView">
      <property name="templateName" value="index" />
      <property name="fragmentSpec">
        <bean class="org.thymeleaf.standard.fragment.StandardDOMSelectorFragmentSpec"
              c:selectorExpression="content" />
      </property>
    </bean>

    @RequestMapping("/showContentPart")
    public String showContentPart() {
        ...
        return "content-part";//返回上面定義的bean名稱。
    }
    c:selectorExpression="content":需要在content節點加上th:fragment。
    c:selectorExpression="#content" :完全基于html dom selector,無需th:fragment。
    在controller中指定片段:
    @RequestMapping("/showContentPart")
    public String showContentPart() {
        ...
        return "index :: content";
    }
    "index :: content"和"index ::#content"區別一樣。
    還可以返回帶參數的片段:
    @RequestMapping("/showContentPart")
    public String showContentPart() {
        ...
        return "index :: #content ('myvalue')";
    }








    posted on 2014-02-11 16:16 不做浮躁的人 閱讀(23446) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    <2014年2月>
    2627282930311
    2345678
    9101112131415
    16171819202122
    2324252627281
    2345678

    常用鏈接

    留言簿(9)

    隨筆分類(31)

    隨筆檔案(75)

    文章分類(1)

    文章檔案(3)

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 香蕉视频在线观看免费| 亚洲另类古典武侠| 一区二区三区在线免费观看视频| 成人毛片免费在线观看| 亚洲欧美中文日韩视频| 成人免费无码大片a毛片| 亚洲日韩精品无码专区加勒比| 成年人免费网站在线观看| 亚洲人成77777在线观看网| 114一级毛片免费| 亚洲精品人成网线在线播放va| 午夜视频在线在免费| 久久久久亚洲AV无码去区首| 免费一级毛片不卡不收费| 日本免费精品一区二区三区| 国产亚洲av片在线观看18女人| 久久久久免费看黄a级试看| 久久久久亚洲AV无码永不| 免费观看AV片在线播放| 亚洲风情亚Aⅴ在线发布| 亚洲国产香蕉人人爽成AV片久久| 中文字幕成人免费高清在线 | 国产AV无码专区亚洲Av| 成全高清在线观看免费| 亚洲精品在线免费观看视频| 无人在线观看免费高清视频| 国产偷国产偷亚洲高清人| 亚洲一区二区三区影院| 亚洲黄色免费网站| 国产精品亚洲一区二区在线观看 | 精品国产亚洲一区二区三区 | 亚洲人成77777在线播放网站不卡| 日韩免费一级毛片| 热99RE久久精品这里都是精品免费| 亚洲激情中文字幕| 日本免费网站观看| 一区二区三区四区免费视频| 亚洲精品无码mⅴ在线观看| 亚洲日韩中文在线精品第一| 97免费人妻无码视频| 一级做a爰全过程免费视频毛片 |