mybatis访问数据库时报java.lang.NullPointerException

来源:互联网 发布:python buffer类型使用 编辑:程序博客网 时间:2024/06/06 01:24

(1)问题描述:

严重: Servlet.service() for servlet [springMvc] in context with path [/New_OPC] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root causejava.lang.NullPointerException    at cn.edu.hdu.Controller.System.LoginController.loginPost(LoginController.java:52)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)等等  

(2)本项目说明
LoginController.java类中

System.out.println("正在执行查询方法");        System.out.println("查询用户的结果:"+userservice.getUserById(1));        System.out.println("查询方法执行完毕");

业务接口

public interface UserService {    User getUserById(Integer userId);}

业务接口实现类

@servicepublic class UserServiceImpl implements UserService {    @Resource    private UserMapper userMapper;    @Override    public User getUserById(Integer userId) {        // TODO Auto-generated method stub        return userMapper.getUserById(userId);    }}

mabatis映射接口

public interface UserMapper  {    User getUserById(Integer userId);   }

mabatis映射xml文件

<mapper namespace="cn.edu.hdu.Dao.System.UserMapper">     <select id="getUserById" parameterType="int" resultMap="User">        select * from tb_user u where u.user_id = #{userId}    </select></mapper>

数据库:
这里写图片描述

解决:localhost写错了

jdbc.driver=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://locahost:3306/test?autoReconnect=true&useUnicode=true&characterEncoding=UTF8&characterSetResults=utf8jdbc.username=rootjdbc.password=******
阅读全文
0 0
原创粉丝点击