-
Notifications
You must be signed in to change notification settings - Fork 46.1k
Closed
Labels
discussdiscuss a problemdiscuss a problemenhancementNew feature or request or suggestionNew feature or request or suggestionperfectImprove knowledge points or descriptionsImprove knowledge points or descriptions
Description
更正:Dao 接口里的方法可以重载,但是Mybatis的XML里面的ID不允许重复!
此处错误更正:
Dao 接口里的方法可以重载,但是Mybatis的XML里面的ID不允许重复。
Mybatis版本3.3.0,亲测如下:
/**
* Mapper接口里面方法重载
*/
public interface StuMapper {
List<Student> getAllStu();
List<Student> getAllStu(@Param("id") Integer id);
}然后在StuMapper.xml中利用Mybatis的动态sql就可以实现。
<select id="getAllStu" resultType="com.pojo.Student">
select * from student
<where>
<if test="id != null">
id = #{id}
</if>
</where>
</select>能正常运行,并能得到相应的结果,这样就实现了在Dao接口中写重载方法。
总结:
Mybatis的Dao接口可以有多个重载方法,但是方法对应的映射必须只有一个,也就是Mapper的XML中定义的ID名不能重复,否则启动会报错。Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
discussdiscuss a problemdiscuss a problemenhancementNew feature or request or suggestionNew feature or request or suggestionperfectImprove knowledge points or descriptionsImprove knowledge points or descriptions
