SpringMvc控制器类不起作用

时间:2019-05-03 10:56:06

标签: java spring-mvc

这是一个简单的函数,我需要来自ShownMovieController类的数据,但是索引页没有任何内容,这是我的代码。有什么建议吗?

运行Java 8,Spring 5.1。

@Controller
public class ShownMovieController {
    @Autowired
    private ShownMovieService sms;
    @Autowired
    private  ShownMovieService fms;

    @RequestMapping(value="/index")
    public ModelAndView MovieDisplay(HttpRequest request,HttpServletResponse response){
        ModelAndView maView = new ModelAndView();
        List<ShownMovie> sm = sms.findShownMovie();
        List<ShownMovie> fm = fms.findForthcomingMovie();

        maView.addObject("shownMovies", sm);
        maView.addObject("forthcomingMovies", fm);
        return maView;
    }
}

我的web.xml

enter image description here

和程序包浏览:

enter image description here

我的索引页面

<div class="row">
  <c:forEach item="${shownMovies }" var="shownMovie">
      <div class="imgFrame">
          <img src="${shownMovie.imgPath }">
          <button class="btn btn-danger imgBtn">Buy</button>
      </div>
  </c:forEach>
</div>

和springmvc-config.xml

<context:component-scan base-package="com.zyb.core.web.controller"></context:component-scan>

<mvc:annotation-driven />
<mvc:resources mapping="/js/**" location="/js/" />
<mvc:resources mapping="/css/**" location="/css/" />
<mvc:resources mapping="/images/**" location="/images/" />
<mvc:resources mapping="/includes/**" location="/includes/" />

<bean id="jspViewResource" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/"></property>
    <property name="suffix" value=".jsp"></property>
</bean>

1 个答案:

答案 0 :(得分:0)

在返回maView对象之前,在代码中添加此行

maView.setViewName("your jsp page name");

或将其添加到ModelAndView构造函数中

ModelAndView maView = new ModelAndView("your jsp page name");

此后一切都应该正常工作。

相关问题