1、前提约束
2、修改net.wanho.mapper.StudentMapper.java接口
新增get方法申明:
package net.wanho.mapper;
import net.wanho.entity.Student;
public interface StudentMapper {
void add(Student student) throws Exception;
void get(int id) throws Exception;
}
3、修改net/wanho/mapper/StudentMapper.xml文件
新增get方法对应的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">