MyBatis增加和修改.XML示例

<update id="updateEntity" parameterType="RyTangdian">
update ry_tangdian
<set>
<if test="tdName != null and tdName != ''">tdName = #{tdName},</if>
<if test="tel != null and tel != ''">tel = #{tel},</if>
<if test="principal != null and principal != ''">principal = #{principal},</if>
<if test="principalphone != null and principalphone != ''">principalphone = #{principalphone},</if>
<if test="address != null and address != ''">address = #{address},</if>
<if test="galleryful != null">galleryful = #{galleryful},</if>
<if test="classify != null and classify != ''">classify = #{classify},</if>




<if test="tdName == null or tdName == ''">tdName = null,</if>
<if test="tel == null or tel == ''">tel = null,</if>
<if test="principal == null or principal == ''">principal = null,</if>
<if test="principalphone == null or principalphone == ''">principalphone = null,</if>
<if test="address == null or address == ''">address = null,</if>
<if test="galleryful == null">galleryful = null,</if>
<if test="classify == null or classify == ''">classify = null,</if>
</set>
where tangdian_Id = #{tangdianID}
</update>


<insert id="insertEntity" parameterType="RyTangdian" useGeneratedKeys="true" keyProperty="tangdianID">
insert into ry_tangdian
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="tangdianID != null and tangdianID != 0">tangdian_Id,</if>
<if test="tdName != null and tdName != ''">tdName,</if>
<if test="tel != null and tel != ''">tel,</if>
<if test="principal != null and principal != ''">principal,</if>
<if test="principalphone != null and principalphone != ''">principalphone,</if>
<if test="address != null and address != ''">address,</if>
<if test="galleryful != null">galleryful,</if>
<if test="classify != null and classify != ''">classify,</if>
</trim>
<trim prefix="values(" suffix=")" suffixOverrides="," >
<if test="tangdianID != null and postId != 0">#{tangdianID},</if>
<if test="tdName != null and tdName != ''">#{tdName},</if>
<if test="tel != null and tel != ''">#{tel},</if>
<if test="principal != null and principal != ''">#{principal},</if>
<if test="principalphone != null and principalphone != ''">#{principalphone},</if>
<if test="address != null and address != ''">#{address},</if>
<if test="galleryful != null">#{galleryful},</if>
<if test="classify != null and classify != ''">#{classify},</if>
</trim>

</insert>


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的 MyBatis Oracle Mapper.xml 示例: ```xml <?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.UserDao"> <select id="getUserById" parameterType="int" resultType="com.example.entity.User"> SELECT * FROM users WHERE id = #{id} </select> <insert id="insertUser" parameterType="com.example.entity.User"> INSERT INTO users (name, age) VALUES (#{name}, #{age}) </insert> <update id="updateUser" parameterType="com.example.entity.User"> UPDATE users SET name = #{name}, age = #{age} WHERE id = #{id} </update> <delete id="deleteUser" parameterType="int"> DELETE FROM users WHERE id = #{id} </delete> </mapper> ``` 这个示例包含了四个 SQL 操作,分别是通过 `id` 获取用户信息、插入用户信息、更新用户信息和删除用户信息。这些操作都是通过 SQL 语句来实现的。 在 MyBatis 中,每个 Mapper.xml 文件都定义了一个 namespace,这个 namespace 用于在应用程序中唯一标识这个 Mapper.xml 文件对应的 DAO 接口。在这个示例中,namespace 是 `com.example.dao.UserDao`。 每个操作都有一个唯一的 `id`,这个 `id` 用于在代码中唯一标识这个操作。`parameterType` 和 `resultType` 分别表示操作的输入参数类型和输出结果类型。在这个示例中,`parameterType` 和 `resultType` 都是 Java 对象类型。 注意,这个示例中的 SQL 语句都是 Oracle 数据库的语法。如果你使用的是其他数据库,你需要根据相应的语法修改这些 SQL 语句。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值