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 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题