基于Eclipse+Tomcat,ssm框架下的问题

这是什么情况呀?从tomcat中启动后,无任何报错,但是页面中的el表达式的值无法显示

//controller层
package com.emp.controller;

import com.emp.pojo.Staff;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.emp.service.StaffService;

@Controller
public class StaffController {
    @Autowired
    private StaffService staffService;

    @RequestMapping("/test")
    public ModelAndView selectByPrimaryKey(Integer staffId) {
        Staff staff = staffService.selectStaffKey(3);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("staff", staff);
        modelAndView.setViewName("test");
        System.out.println("员工id:" + staff.getStaffId());
        System.out.println("员工name:" + staff.getName());
        System.out.println("员工sex:" + staff.getSex());
        System.out.println("员工dept_id:" + staff.getDeptId());
        return modelAndView;
    }    
}

spring-mvc.xml

 <?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 
    <context:component-scan base-package="com.emp.controller" />
    <mvc:annotation-driven />
    <mvc:default-servlet-handler/>

    <!-- 3.配置jsp 显示ViewResolver -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>

jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" isELIgnored="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>员工管理系统</title>
</head>
<body>
    <table border="1">
        <tr>
            <th>工号</th>
            <th>姓名</th>
            <th>性别</th>
            <th>部门号</th>

        </tr>
        <tr>
            <td>${staff.staff_id}</td>
            <td>${staff.name}</td>
            <td>${staff.sex}</td>
            <td>${staff.dept_id}</td>
        </tr>
    </table>
</body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
    version="4.0">

    <display-name>Archetype Created Web Application</display-name>
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- 配置springMVC需要加载的配置文件 spring-dao.xml,spring-service.xml,spring-mvc.xml 
            Mybatis - > spring -> springmvc -->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-*.xml</param-value>
        </init-param>
    </servlet>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:applicationContext.xml</param-value>
    </context-param>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <!-- 默认匹配所有的请求 -->
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

img

img

Staff staff = staffService.selectStaffKey(3);
这里下断点调试下,返回正确的 staff 了么

你是不是没在页面上去获取传递过来的数据哦

这个值没有取到

 Staff staff = staffService.selectStaffKey(3)

做个判断

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<c:if test="${not empty staff}">
<<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<c:if test="${not empty staff}">
<table border="1">
<tr>
<th>工号</th>
<th>姓名</th>
<th>性别</th>
<th>部门号</th>
</tr>
<tr>
<td><c:out value="${staff.staffId}" /></td>
<td><c:out value="${staff.name}" /></td>
<td><c:out value="${staff.sex}" /></td>
<td><c:out value="${staff.deptId}" /></td>
</tr>
</table>
</c:if>