mybatis 接口绑定和多参数传递
一、接口绑定:把mapper.xml的sql语句绑定到mapper.java接口中的方法中
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄
- mybatis.xml:
- <mappers>
- <package name="com.mybatis.mapper"/>
- </mappers>
- StudentMapper.xml:
- <select id="selOne" resultType="Student">
- select * from stu where id=#{0} and name=#{1};
- </select>
- StudentMapper.java:
- public interface StudentMapper {
- Student selOne(int id,String name);
- }
- Test.java:
- StudentMapper sm = session.getMapper(StudentMapper.class);
- Student stu = sm.selOne(2,"lisi");
- 或者在#{}中写@Param("内容") 参数中的内容
- Student selOne(@Param("i") int id,@Param("n") String name);
- select * from stu where id=#{i} and name=#{n};
- 此时,底层使用map实现,"i"作为key,id的值作为value。

更多精彩