1.Mybatis 中如果参数只有一个,且是String类型的,在mapper中需要加入 @param 注解标出或使用mybatis 内置参数 _parameter,否则mybatis 无法找到该参数,会抛出 there is no getter for property named "xxx" in java.lang.String;
//mapper
Student xxx getStudents(@param("name") String name);
//xml --使用注解
<select id="xxxx" paramterType="java.lang.String" resultMap="baseMap">
select * from xxTable where 1=1
<if test="name !=null">
and name=#{name}
</if>
</select>
// xml --使用内置参数
<select id="xxxx" paramterType="java.lang.String" resultMap="baseMap">
select * from xxTable where 1=1
<if test="_parameter!=null">
and name=#{_parameter}
</if>
</select>
2.mybati 关联查询是,查出来的字段即使和某个类的字段一一对应,也无法很好的完成映射,可以使用resultMap进行手动映射
3.mybatis 中 xml 的东西可以相互调用,如xml1调用xml2里的东西,调用方式如下
// xml1 查询出来的字段映射为一个map
<select id="xxx" resultMap="com.xx.xxMapper.BaseMap">
select name from table1
</select>
// xml2
<mapper namespace="com.xx.xxMapper">
<resultMap id="BaseMap" type="com.xx.entry.Student">
<result column="NAME" property="name">
</resultMap>
</mapper>