ssm框架-controller层的model数据传不到jsp

springmvc.xml 

<!-- 配置扫描器 -->
		<context:component-scan base-package="cn.edu.xit.controller"></context:component-scan>


		<!-- 配置视图解释器ViewResolver -->
		<bean id="viewResolver"
			class="org.springframework.web.servlet.view.InternalResourceViewResolver">
			<property name="prefix" value="/jsp/"></property>
			<property name="suffix" value=".jsp"></property>
		</bean>

		<!-- 注解驱动:配置处理器映射器和适配器 -->
		<mvc:annotation-driven />

 main.jsp

	<c:if test="${customers!=null }">

						<table border=1>
								<tr>
									<td>订单号</td>
									<td>订单价格</td>
									<td>订单状态</td>
									
								</tr>
									<c:forEach items="${customers}" var="row">
										<tr>
										<td>${row.o_id }</td>
										<td>${row.price}</td>
										<td>${row.o_state}</td>
										
										</tr>
									</c:forEach>
							</table>
			
			</c:if>

 controller层

@Controller
public class CustomerController {
	@Autowired
	private  CustomerService customerService;
	
	
	
	@RequestMapping("findCustomer")
	public String findCustomer(Model model){
		List<Customer> customers= customerService.findCustomer();
		
		
			System.out.println("-------------------"+model);
	   
		model.addAttribute("customers",customers);

		return "main";
	}
	}

mapper.xml

<select id="findCustomer" resultType="cn.edu.xit.po.Customer" parameterType="Integer">
select o_id,price,o_state from oder
</select>

 上面是文件的一些代码,从数据库表得到的数组没有返回到main.jsp。

 

失败输出结果截图:

使用<c:if>:

 不使用<c:if> :

所以从controller层的customers是空的?

求解!!!!!可以私信下谢谢!! 

你要看看你从数据库查出来,有没有数据;没有数据那肯定就 没办法展示了啊

补充说明:

写在mapperxml文件里的sql语句在数据库中是可以正常查出来的。

你要看你的controller代码里面 能拿到数据不;这个跟你sql在数据库直接查询是两码事

1、 controller打个断点调试,看执行到model.addAttribute("customers",customers);  有没有数据

2、如果已经取到值了,再看下jsp支不支持EL表达式,在默认情况下,Servlet2.3/jsp1.2是不支持EL表达式的,而Servlet2.4/jsp 2.0支持。可以参考

https://blog.csdn.net/weixin_43338519/article/details/89524498

 

我也遇到了 同意问题 楼主解决了没有啊