java学习知识积累-初练Mybatis
Mybatis在xml文件处理简单的增删改查操作。、
对应的数据库表结构是这样的:
xml代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<insert id="insertUser" parameterType="User" useGeneratedKeys="true" keyColumn="id"> insert into t_user(name, age) values(#{name}, #{age}) </insert> <update id="updateUser" parameterType="User"> update t_user set name=#{name}, age=#{age} where id=#{id} </update> <select id="findById" parameterType="int" resultType="User"> select * from t_user where id=#{id} </select> <delete id="deleteUser" parameterType="int"> delete from t_user where id=#{id} </delete> |
UserMapper代码如下(另一个方法)
1 2 3 4 5 6 7 8 9 10 11 |
@Insert("insert into t_user(name, age) values(#{name}, #{age})") public void insertUser(User user); @Update("update t_user set name=#{name}, age=#{age} where id=#{id}") public void updateUser(User user); @Select("select * from t_user where id=#{id}") public User findById(int id); @Delete("delete from t_user where id=#{id}") public void deleteUser(int id); |
- java学习知识积累-初识spring框架的”依赖注入”
- java学习知识积累-spring常用注解