mabatis-mapper.xml模板
时间: 2024-02-06 20:59:34 浏览: 68
mybatis中的mapper配置文件样例
5星 · 资源好评率100%
<?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.example.dao.UserMapper">
<!-- 查询所有用户 -->
<select id="findAllUsers" resultType="com.example.model.User">
SELECT * FROM user
</select>
<!-- 通过id查询用户 -->
<select id="findUserById" parameterType="int" resultType="com.example.model.User">
SELECT * FROM user WHERE id = #{id}
</select>
<!-- 添加用户 -->
<insert id="addUser" parameterType="com.example.model.User">
INSERT INTO user(username, password, email) VALUES(#{username}, #{password}, #{email})
</insert>
<!-- 更新用户 -->
<update id="updateUser" parameterType="com.example.model.User">
UPDATE user SET username=#{username}, password=#{password}, email=#{email} WHERE id=#{id}
</update>
<!-- 删除用户 -->
<delete id="deleteUser" parameterType="int">
DELETE FROM user WHERE id=#{id}
</delete>
</mapper>
阅读全文