这是我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<servlet>
<servlet-name>mvcdemo</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvcdemo</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 指定spring bean配置文件所在位置 -->
<context-param>
<!-- 这个是固定写法contextConfigLocation -->
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/applicationContext.xml</param-value>
</context-param>
applicationContex.xml文件
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close"
p:driverClassName="${driver}"
p:url="${url}"
p:username="${username}" p:password="${password}" p:maxActive="10" p:maxIdle="10">
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- dataSource属性指定要用到的连接池 -->
<property name="dataSource" ref="dataSource" />
<!-- configLocation属性指定mybatis的核心配置文件 -->
<property name="configLocation" value="classpath:config/Configuration.xml" />
<!-- 所有配置的mapper文件 -->
<property name="mapperLocations" value="classpath:mapper/*.xml"></property>
</bean>
<bean id="propertyMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="wang.dao.IPropertyDao"></property>
<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
</bean>
这里是mvcdemo-servlet.xml文件
context:annotation-config/
<!-- spring扫描器,用于实现bean自动载入UserController中 -->
<context:component-scan base-package="wang.controller"/>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/property/"/>
<property name="suffix" value=".jsp"/>
</bean>
IPropertyDao层
package wang.dao;
import java.util.List;
import wang.model.Property;
public interface IPropertyDao {
public List selectProperty();
}
property.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
select * from property
最后是controller层
package wang.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import wang.dao.IPropertyDao;
import wang.model.Property;
@Controller
@RequestMapping("/property")
public class PropertyController {
private IPropertyDao propertyDao;
private Property property;
@RequestMapping("/show")
public String show(Model model){
System.out.println(propertyDao.selectProperty());
// property = propertyDao.selectProperty();
// model.addAttribute("property", property);
return "/list";
}
public IPropertyDao getPropertyDao() {
return propertyDao;
}
public void setPropertyDao(IPropertyDao propertyDao) {
this.propertyDao = propertyDao;
}
public Property getProperty() {
return property;
}
public void setProperty(Property property) {
this.property = property;
}
}
运行后错误500,
debug发现propertyDao.selectProperty()是空的,请问大神,是哪里错啦?