mybatis 注解


一、mybatis.xml
  • <mapper>中使用<package/>
 
二、mapper.java接口
  • public interface StudentMapper2 {
  •       @Select("select * from stu")
  •       List<Student> selAll();
  • }
 
三、Test中调用
  • StudentMapper2 sm = session.getMapper(StudentMapper2.class);
  • List<Student> list = sm.selAll();
 
四、多值传递(用#{param1},#{param2},#{param3}。不能用#{0},#{1},#{2})
package top.woldcn.mapper;
 
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import top.woldcn.entity.Comment;
 
public interface CommentMapper {
    @Insert("insert into comment values(default, #{param1},#{param2},#{param3},default)")
    int insert(int essayId, int visitorId, String content);
}
 
 
 
 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM