本文共 1084 字,大约阅读时间需要 3 分钟。
1. 简单的select映射
映射接口:
package com.mybatis3.mappers;public interface StudentMapper{ Student findStudentById(Integer id);}
2. 简单的insert映射
INSERT INTO STUDENTS(STUD_ID,NAME,EMAIL, PHONE) VALUES(#{studId},#{name},#{email},#{phone})
映射接口:
package com.mybatis3.mappers;public interface StudentMapper{ int insertStudent(Student student);}
自增主键:
useGeneratedKeys="true" keyProperty="studId"
INSERT INTO STUDENTS(NAME, EMAIL, PHONE) VALUES(#{name},#{email},#{phone})
3. 简单的update映射
UPDATE STUDENTS SET NAME=#{name}, EMAIL=#{email}, PHONE=#{phone} WHERE STUD_ID=#{studId}
4. 简单的delete映射
DELETE FROM STUDENTS WHERE STUD_ID=#{studId}
映射接口:
package com.mybatis3.mappers;public interface StudentMapper{ int deleteStudent(int studId);}
5. 简单的结果映射
resultMap
转载地址:http://nnfco.baihongyu.com/