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>

td の子としてスパンが含まれているため、td の th:text が最終的に置換されるため、th:text を td に含める必要はありません。

さらにメタタグが閉じられていません..

これを試して

> <!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 に答える