测试里
public void select01() throws IOException {
start();
PersonMapper mapper = sqlSession.getMapper(PersonMapper.class);
Person person = mapper.getPersonById(1);
System.out.println(person);
sqlSession.close();
log.debug("test");
}
如果是【#】
等于占位符
<select id="getPersonById"
resultType="com.yiki.Entity.Person">
select pid,p_name pname,email from Person where pid = #{id}
</select>
控制台为
【javaType】
【jdbcType】数据库类型
通常在某种特定情况下使用,在数据为null的时候,有些数据库可能不能识别mybatis对null的默认处理
一般用于oracle环境下
一般格式为#{name,jdbcType=NULL}
如果你name为空,用的jdbcType的空值
【mode】
如果为【$】
不安全!不要乱用,多用于原生sql不支持占位符的地方才用
<select id="getPersonById"
resultType="com.yiki.Entity.Person">
select pid,p_name pname,email from Person where pid = ${id}
</select>
控制台为
错误解决
There is no getter for property named 'id' in class 'java.lang.Integer',由于我实体类的pId为Integer包装类
解决办法为在Dao接口层加上@parm
public Person getPersonById(@Param("id") Integer id);