创建insert_user存储过程 CREATE PROCEDURE insert_user(OUT u_id INTEGER,IN u_name VARCHAR(20),IN u_sex VARCHAR(20),IN u_age INTEGER) BEGIN INSERT INTO t_user (name,sex,age) VALUES (u_name,u_sex,u_age); SET u_id=LAST_INSERT_ID(); END 在UserMapper.xml中调用insert_user存储过程 <!-- 添加用户 --> <insert id="addUser" parameterType="com.po.User" statementType="CALLABLE"> {call insert_user( #{id,mode=OUT,jdbcType=INTEGER},#{name,mode=IN},#{sex,mode=IN},#{age,mode=IN})} </insert> 创建deleteUser存储过程 CREATE PROCEDURE deleteUser(IN u_id INTEGER) BEGIN DELETE FROM t_user WHERE id=u_id; END 在UserMapper.xml中调用deleteUser存储过程 <!-- 删除用户 --> <delete id="deleteUser" parameterType="Integer" statementType="CALLABLE"> {call deleteUser(#{id,mode=IN})} </delete> 创建updateUser存储过程 CREATE PROCEDURE updateUser(IN u_id INTEGER,IN u_name VARCHAR(20),IN u_sex VARCHAR(20),IN u_age INTEGER) BEGIN UPDATE t_user SET name=u_name,sex=u_sex,age=u_age WHERE id=u_id; END 在UserMapper.xml中调用updateUser存储过程 <!-- 更新用户 --> <update id="updateUser" parameterType="user" statementType="CALLABLE"> {call updateUser(#{id,mode=IN},#{name,mode=IN},#{sex,mode=IN},#{age,mode=IN})} </update> 创建getUserById存储过程 CREATE PROCEDURE getUserById(IN u_id INTEGER) BEGIN SELECT id,name,sex,age FROM t_user WHERE id=u_id; END 在UserMapper.xml中调用getUserById存储过程 <!-- 根据id查询用户 --> <select id="getUserById" parameterType="Integer" resultType="user" statementType="CALLABLE"> {call getUserById(#{id,mode=IN})} </select> 创建UserDao