mybatis学习:十

来源:互联网 发布:触宝输入法软件 编辑:程序博客网 时间:2024/06/06 02:13

在mybatis中使用注解
1.定义接口,在接口上加入注解

public interface IStudentDao {    @Insert("insert into student values(default,#{name},#{phone})")    public int addStudent(Student student);    @Delete("delete from student where id = #{id}")    public int deleteStudent(int id);    @Select("select * from student limit #{start},#{size}")    public List<Student> selectPage(Map<String, Object> map);    @Update("update student set name=#{name}, phone=#{phone} where id=#{id}")    public int updateStudent(Student student);}

2.在配置文件中标签中加入,把接口注册

    <mappers>        <!-- <package name="com.han.dao"/> -->        <mapper class="com.han.dao.IStudentDao"/>    </mappers>