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