求助学习mybatis的时候,sqlsessionfactory报NullpointerException 20

userMapping.xml<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEmapperPUBLIC"-//mybatis.o... userMapping.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">

<mapper namespace="mapper.UserMapper">
<insert id ="save" parameterType="domain.User" useGeneratedKeys="true">
INSERT INTO USERS(name,male,age) VALUES(#{name_stu},#{male},#{age})
</insert>

</mapper>

--------------------------------------
MyBatisTest.java
package spittr.test;
import org.apache.ibatis.session.*;
import spittr.domain.User;
import org.apache.ibatis.io.Resources;
import java.io.InputStream;
public class MyBatisTest {
public static void main(String[] args) throws Exception {
InputStream inputStream= Resources.class.getResourceAsStream("mybatis-config.xml");
SqlSessionFactory sessionFactory =new SqlSessionFactoryBuilder().build(inputStream);
SqlSession session =sessionFactory.openSession();
User user = new User("admin",true,26);
session.insert("mapper.UserMapper.save",user);
session.commit();session.close();

}
}

---------------------------------------
mybatis-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="logImpl" value="LOG4J"/>
</settings>
<environments default="PostgreSQL">
<environment id="PostgreSQL">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://127.0.0.1:5432/postgres"/>
<property name="username" value="pstgres"/>
<property name="password" value="password"/>
</dataSource>
</environment>
</environments>

<mappers>
<mapper resource="mapper/UserMapper.xml"/>
</mappers>
</configuration>
展开
 我来答
匿名用户
2019-03-10
展开全部
空指针 在java 很常见
你有判断吗?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式