为什么 thymeleaf 无法正确呈现 table 中的数据

why thymeleaf does not render data in table properly

table 中的数据未正确显示...这是我在模板html 中的页面

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:th="http://www.thymeleaf.org">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</head>
<body>

    <form th:action="@{/indexone}">
        Filter <input type="text" name="keyword" id="keyword" size="50"
            th:value="${keyword}" required /> &nbsp; <input type="submit"
            value="Search"></input> &nbsp;

    </form>


    <table border="2">
        <thead>

        <tr>
            <th>modelNum</th>
            <th>companyName</th>
            <th>price</th>
        </tr>
        </thead>

        <tbody>
            <tr th:each="mobile:${listMobiles}">
                <td th:text="#{mobile.modelNum}"></td>
                <td th:text="#{mobile.companyName}"></td>
                <td th:text="#{mobile.price}"></td>
            </tr>
        </tbody>
    </table>
</body>

</html>

移动存储库

package login.example;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface MobileRepository extends JpaRepository<Mobile, String> {

    @Query("SELECT mobile FROM Mobile mobile  WHERE CONCAT(mobile.modelNum,' ',mobile.companyName,' ',mobile.price) LIKE %?1%")
    public List<Mobile> search(String keyword);
    
}

这里是移动服务

package login.example;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

@Service
public class MobileService {

    @Autowired
    private MobileRepository repo;
    public List<Mobile> listAll(String keyword) {
        if (keyword != null) {
            return repo.search(keyword);

        }else
        return repo.findAll();
    }

}

这里是mobileController

package login.example;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class MobileController {
    @Autowired
    private MobileService service;
    
    @RequestMapping("/indexone")
    public String viewHomePage(Model model, @Param("keyword") String keyword) {
        List<Mobile> listMobiles = service.listAll(keyword);
        model.addAttribute("listMobiles", listMobiles);
        model.addAttribute("keyword", keyword);
        return "indexone.html";
    }
}

我的手机 table 呈现效果不佳..我应该如何正确呈现 mysql 中的 table..即使在那之后搜索也运行良好..数据不是渲染..这个问题想说什么?它没有给出例外..

您应该使用 ${...} 表达式而不是 #{...} 表达式。 ${...} 是常规变量表达式,而 #{...} 表达式用于 system/internationalization 属性。

<tr th:each="mobile: ${listMobiles}">
  <td th:text="${mobile.modelNum}"></td>
  <td th:text="${mobile.companyName}"></td>
  <td th:text="${mobile.price}"></td>
</tr>

我有替换

     <td th:text="#{mobile.modelNum}"></td>
                    <td th:text="#{mobile.companyName}"></td>
                    <td th:text="#{mobile.price}"></td>
      <td th:text="#{mobile.price}"></td>

 <td th:text="${mobile.modelNum}"></td>
                    <td th:text="${mobile.companyName}"></td>
                    <td th:text="${mobile.price}"></td>
      <td th:text="${mobile.price}"></td>