1、前提约束
2、技术选型
- springmvc+spring+mybatis
- pagehelper
3、修改net.wanho.mapper.StudentMapper.java接口
新增query方法申明:
package net.wanho.mapper;
import net.wanho.entity.Student;
import java.util.List;
public interface StudentMapper {
void add(Student student) throws Exception;
void update(Student student) throws Exception;
void delete(int id) throws Exception;
void get(int id) throws Exception;
List<Student> query() throws Exception;
}
4、修改net/wanho/mapper/StudentMapper.xml文件
新增update方法对应的sql:
<?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="net.wanho.mapper.StudentMapper">
<!--id的值与接口中方法名同名,parameterType即方法的参数类型,
useGeneratedKeys即使用自增主键,keyProperty定义了主键-->
<insert id="add" parameterType="net.wanho.entity.Student" useGeneratedKeys="true" keyProperty="id">
insert into t_student(name) values(#{name})
</insert>
<update id="update" parameterType="net.wanho.entity.Student" >
update t_student set name=#{name} where id=#{id}
</update>
<delete id&