基于前一篇博客的实例,我们这次来完成mybatis框架下sqlite数据库增、删、改、查的实现。
1、修改StudentMapper接口
首先修改上一次的StudentMapper接口,新增几个方法。
package com.mapper;
import com.pojo.Student;
import java.util.List;
public interface StudentMapper {
public Student getStudentById(int id);
public List<Student> findStudents(String roleName);
public int insertStudent(Student role);
public int deleteStudent(int id);
public int updateStudent(Student role);
}
2、修改StudentMpper.xml文件
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mapper.StudentMapper">
<select id="getStudentById" resultType="student" parameterType="int">
select ID,Name,Sex,Grade from student where id=#{id}
</select>
<insert id="insertStudent" parameterType="student">
insert into student(ID,NAME,SEX,GRADE) values (#{ID},#{Name},#{Sex},#{Grade})
</insert>
<delete id="deleteStudent" parameterType="int">
delete from student where id=#{id}
</delete>
<update id="updateStudent" parameterType="student">
update student set NAME=#{Name},SEX