这是一个简单的函数,我需要来自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
和程序包浏览:
我的索引页面
<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>
答案 0 :(得分:0)
在返回maView
对象之前,在代码中添加此行
maView.setViewName("your jsp page name");
或将其添加到ModelAndView
构造函数中
ModelAndView maView = new ModelAndView("your jsp page name");
此后一切都应该正常工作。