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);
}
 
 
 
 
posted @ 2019-05-12 14:10  woldcn  阅读(1012)  评论(0)    收藏  举报