使用Anntation完成CRUD
>> 使用XML完成CRUD
相较于XML,通过Anntation完成CRUD只需要做如下改变。
1. mybatis-cfg.xml : 使用StudentMapper.java替换已不存在的xml文件
<mappers><mapper class="com.java1234.mappers.StudentMapper"/></mappers>
2. StudentMapper.java - 将接口类与xml文件结合
package com.java1234.mappers;import java.util.List;import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;import com.java1234.model.Student;public interface StudentMapper {@Insert("Insert into tb_student values(null,#{name},#{age})")public int addStudent(Student student);@