Java SpringMVC项目未在视图的表中显示mysql数据

Java SpringMVC项目未在视图的表中显示mysql数据,java,mysql,spring,spring-mvc,Java,Mysql,Spring,Spring Mvc,我已经建立了一个maven、SpringMVCwebapp和crud项目。当我运行我的视图页面时,我的表不会显示数据库中的任何数据 我的控制器 import java.util.List; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controll

我已经建立了一个maven、SpringMVCwebapp和crud项目。当我运行我的视图页面时,我的表不会显示数据库中的任何数据

我的控制器

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.eoh.imp.service.AssetService;
import com.eoh.imp.model.Asset;

@Controller
public class AssetController {

@Autowired
private AssetService assetService;


@RequestMapping(value = "/ManageAssets", method = RequestMethod.GET)
public ModelAndView newAsset(ModelAndView model) {
    Asset asset = new Asset();
    List<Asset> listAsset = assetService.listAsset();
    model.addObject("asset", asset);
    model.addObject("listAssets",listAsset);
    model.setViewName("ManageInventory");
    return model;
}
我的刀

 import org.hibernate.SessionFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Repository;
 import java.util.List;
 import org.hibernate.Criteria;
 import org.hibernate.Session;
 import com.eoh.imp.model.Asset;

@Repository
public class AssetDAOImpl implements AssetDAO {

@Autowired
private SessionFactory sessionFactory;

public void addAsset(Asset a) {
    sessionFactory.getCurrentSession().saveOrUpdate(a);
}

public Asset updateAsset(Asset a) {
    sessionFactory.getCurrentSession().update(a);
    return a;
}

@SuppressWarnings("unchecked")
public List<Asset> listAsset() {
    Session session = sessionFactory.getCurrentSession();
    Criteria criteria = session.createCriteria(Asset.class);
    return (List<Asset>)criteria.list();
}
看法

输出

数据库有1个资产

mysql>从资产中选择*

|id |类型|品牌|型号|序列号|采购日期|供应商|评论|寿命|

|1 |笔记本电脑|联想| ThinkPad W510 | | | | | | | | | | | | | | | |

尝试使用c:out标签

<!-------------------------------------- ASSETS TABLE ---------------------------------------------->
<table class="table table-hover">

    <tr>
       <th>Asset Type</th>
        <th>Asset Make</th>
        <th>Asset Model</th>
        <th>Serial Number</th>
    <th>Date Of Purchase</th>
    <th>Supplier</th>
    <th>Comments</th>
    <th>Life Span</th>
    <th>Actions</th>
</tr>

<c:forEach var="assets" items="${listAssets}">
    <tr>
        <td><c:out value="${assets.getType()}"/></td>
        <td><c:out value="${assets.getMake()}"/></td>
        <td><c:out value="${assets.getModel()}"/></td>
        <td><c:out value="${assets.getSerialNumber()}"/></td>
        <td><c:out value="${assets.getDateOfPurchase()}"/></td>
        <td><c:out value="${assets.getSupplier()}"/></td>
        <td><c:out value="${assets.getComments()}"/></td>
        <td><c:out value="${assets.getLifeSpan()}"/></td>
        <td><a href="editAsset?id=${assets.getId()}"
            class="btn btn-info col-lg-6"><span
                class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a> <a
            href="deleteAsset?id=${assets.getId()}"
            class="btn btn-danger col-lg-6"><span
                class="glyphicon glyphicon-trash" aria-hidden="true"></span></a></td>
    </tr>
</c:forEach>

在JSP EL中,您不会这样调用该方法,而是使用属性名,或者如果它是一个名为Getting的方法,则编写asset.thing:

${assets.getType}错误

${assets.type}正确


编辑:这行吗

在表达式语言中,应该有变量名,如下所示

像这样

固定了!!!!! 问题出现在my web.xml中,缺少以下内容:

 xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
      version="3.0"

谢谢你的帮助

你试过调试吗?存储在模型中的listAsset是否为空?listAsset不为空。但是当我放置一个c标记来测试listAssets是否为空时,表不会显示;对我愿意。添加了-System.out.printlnlistAsset.get0;-在那之后。输出:id=1,type=Laptop,make=Lenovo,model=ThinkPad W510,serialnumber=,dateofpurchase=null,supplier=,comments=,lifespan=null谢谢…尝试过,但输出相同。奇怪。。我每天都这么做:你有没有试过把它和c:out标签结合起来?在答案中检查我的变化
 xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
      version="3.0"