jsrender简单例子

矫情吗;* 2022-08-27 10:57 250阅读 0赞
  1. <div id="tabContent"></div>
  2. <script type="text/javascript" src="${ rootpath}/res/js/jquery-1.11.1.min.js"></script>
  3. <script type="text/javascript" src="${ rootpath}/res/js/jsrender.min.js"></script>
  4. <script type="text/x-jsrender" id="tablist">
  5. <table cellspacing="0" cellpadding="0" width="100%" border="1">
  6. <tr style="height:30px;background-color: #6293bb;">
  7. <th>主题</th>
  8. <th>回复</th>
  9. <th>作者</th>
  10. <th>阅读</th>
  11. <th>更新时间</th>
  12. </tr>
  13. {
  14. {for topicList}}
  15. <tr>
  16. <td align="left" style="padding-left:5px;">
  17. {
  18. {if pstatus == '1'}}
  19. <img src="${rootpath}/res/images/read_topic.gif" />
  20. {
  21. {else}}
  22. <img src="${rootpath}/res/images/unread_topic.gif" />
  23. {
  24. {/if}}
  25. <a href="#" style="padding-left:5px;">{
  26. {:title }}</a>
  27. </td>
  28. <td>{
  29. {:reply }}</td>
  30. <td>{
  31. {:username }}</td>
  32. <td>{
  33. {:readcount }}</td>
  34. <td>{
  35. {:pdate }}</td>
  36. </tr>
  37. {
  38. {/for}}
  39. </table>
  40. </script>
  41. <script type="text/javascript">
  42. jQuery.post("${rootpath}/topic/list.action",{},
  43. function(data, textStatus, jqXHR)
  44. {
  45. var tabCon = $("#tablist").render(data);
  46. $("#tabContent").html(tabCon);
  47. },
  48. "json");
  49. </script>

后台逻辑:

  1. @RequestMapping(value="/list", method=RequestMethod.POST)
  2. public void indexForList(HttpServletRequest request, HttpServletResponse response) throws IOException
  3. {
  4. List<Topic> list = topicService.queryTopicList();
  5. response.setContentType("application/json;charset=UTF-8");
  6. Map<String, List<Topic>> map = new HashMap<>();
  7. map.put("topicList", list);
  8. response.getWriter().print(new Gson().toJson(map));
  9. response.getWriter().close();
  10. }

发表评论

表情:
评论列表 (有 0 条评论,250人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Spring简单例子

    1.引入包 强烈建议,学习使用下maven及类似依赖包管理工具,如果你以后学Java,基本上会用到的吧 maven:在pom添加依赖: <dependenc

    相关 JsRender (js模板引擎)

    最近学习了一下`Jsrender`模板渲染工具,非常不错,功能比较强大,官网说他是“简单直观 功能强大 可扩展的 快如闪电”确实如此。总结一下!! `jsRender` 三个