wang8831567 2014-10-22 02:52 采纳率: 0%
浏览 3309

mybaitis springmvc整合空指针异常

这是我的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()是空的,请问大神,是哪里错啦?

  • 写回答

1条回答

  • weixin_39324376 2017-07-05 08:51
    关注

    不用问,我和你出现差不多的错误我也不知道,你知道告诉我一下

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘