这是一个简单的函数,我需要来自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

java - SpringMvc Controller 类不起作用-LMLPHP

和套件探索:

java - SpringMvc Controller 类不起作用-LMLPHP

我的索引页

<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>

最佳答案

返回maView对象之前,请将此行添加到代码中

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


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

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


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

关于java - SpringMvc Controller 类不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55968393/

10-12 00:13