0

我正在使用 Spring MVC 3 和 Thymeleaf。我想在表格中显示字符串,但没有结果(空白表格单元格)。我究竟做错了什么?我的控制器类:

@Controller
@RequestMapping(value="table", method = RequestMethod.GET)
public class TableController {
@Autowired
DaneEndpoint daneEndpoint;
public String tabela(Model model){
model.addAttribute("tytul", daneEndpoint.getAll().get(0));
model.addAttribute(model);
 return "table";
    } 
 }


和html页面(table.html):

<!DOCTYPE html> 
<html xmlns:th="http://www.thymeleaf.org"> 
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
    <h3 align="center">table</h3> 
    <div align="left">
    <form action="table.html"  th:object="${tytul}" method="get">
      <fieldset> 
        <div align="center">
        <table border="1">
          <thead>
             <tr>
               <th th:text="">tytul</th>
             </tr>
          </thead>
          <tbody>
             <tr>
                <td th:text=""><span th:text="#{table.tytul}"/></td>
             </tr>
          </tbody>
        </table> 
        </div>
      </fieldset>    
    </form> 
    </div> 
</body>
</html>


感谢帮助。

4

2 回答 2

1

<span th:text="#{table.tytul}"/>

` 从消息属性中获取值,因此如果 table.html 直接在浏览器中打开,它将为空

如果这个页面是通过应用程序访问的,因为,

<th th:text="">

不是有效的thymeleaf表达式语法(因为空字符串),会发生解析错误..和

<td th:text=""><span th:text="#{table.tytul}"/></td>

包含 span 作为 td 的子项,因此 th:text 不需要包含在 td 中,因为 td 中的 th:text 最终将替换..

进一步的元标记未关闭..

尝试这个

> <!DOCTYPE html>  <html xmlns:th="http://www.thymeleaf.org">  <head>
>     <title></title>
>     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
> </head> <body>
>     <h3 align="center">table</h3> 
>     <div align="left">
>     <form action="table.html"  th:object="${tytul}" method="get">
>       <fieldset> 
>         <div align="center">
>         <table border="1">
>           <thead>
>              <tr>
>                <th >tytul</th>
>              </tr>
>           </thead>
>           <tbody>
>              <tr>
>                 <td><span th:text="#{table.tytul}"/></td>
>              </tr>
>           </tbody>
>         </table> 
>         </div>
>       </fieldset>    
>     </form> 
>     </div>  </body> </html>

如果在浏览器中直接打开时需要显示表上的值以进行原型制作,请尝试此操作

> <!DOCTYPE html>  <html xmlns:th="http://www.thymeleaf.org">  <head>
>     <title></title>
>     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body>
>     <h3 align="center">table</h3> 
>     <div align="left">
>         <form action="table.html"  th:object="${tytul}" method="get">
>             <fieldset> 
>                 <div align="center">
>                     <table border="1">
>                         <thead>
>                             <tr>
>                                 <th >tytul</th>
>                             </tr>
>                         </thead>
>                         <tbody>
>                             <tr>
>                                 <td><span th:text="#{table.tytul}"/> <span th:remove="all">content</span></td>
> 
>                             </tr>
>                         </tbody>
>                     </table> 
>                 </div>
>             </fieldset>    
>         </form> 
>     </div>  </body> </html>
于 2013-07-08T02:25:38.013 回答
0

好像你错过了一个结局</tr>和结局</div>。尝试添加。

于 2013-07-08T00:11:28.043 回答