在AccountMapper.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="com.zte.myproject1.mapper.AccountMapper">
<resultMap id="gainAccount" type="com.zte.myproject1.entity.Account">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="name" column="name" jdbcType="VARCHAR" />
<result property="money" column="money" jdbcType="DOUBLE" />
</resultMap>
<select id="getAccount" parameterType="Integer" resultType="com.zte.myproject1.entity.Account">
select * from account
where
<if test="id != null">
id = #{id}
</if>
</select>
</mapper>
在Account.java中漏掉参数注解:
错误:
@Mapper
public interface AccountMapper {
Account getAccount( int id);
}
正确:
@Mapper
public interface AccountMapper {
Account getAccount(@Param("id") int id);
}