我想使用sqlMap从数据库插入和获取对象。插入用户工作正常但是当我调用getUser时它会抛出一个异常"请求处理失败;嵌套异常是java.lang.NullPointerException"。
public void insertUser(User user)
{
try
{
getSqlMapClientTemplate().insert("User.insert", user);
}
catch (Exception e)
{
e.printStackTrace();
}
}
@Override
public User getUser(String email) {
User user=null;
try
{
user = (User) getSqlMapClientTemplate().queryForObject("User.getUser", email);
} catch (Exception e) {
e.printStackTrace();
}
return user;
}
<sqlMap namespace="User">
<select id="getUser" resultClass="MyProject.domain.User">
select userName as name, password as password, email as email from users where email = #value#
</select>
<insert id="insert" parameterClass="MyProject.domain.User">
insert into users (userName,password,email) values
(#name#,#password#,#email#)
</insert>
</sqlMap>
答案 0 :(得分:0)
在你的sqlmap中,你没有为getUser语句指定parameterClass;尝试添加:
parameterClass="string"
你的陈述。