mybatis修改

修改全部字段

定义Mapper接口

public interface StudentMapper{

        void updata(Student data);


}

Student的结构

package top.wogong.pojo;



public class Student {
    private Integer ID;
    private String name;
    private String classID;
    private String gender;
    private String cardID;
    private String address;
    private String phone;

    public Student() {
    }

    public Student(Integer ID, String name, String classID, String gender, String cardID, String address, String phone) {
        this.ID = ID;
        this.name = name;
        this.classID = classID;
        this.gender = gender;
        this.cardID = cardID;
        this.address = address;
        this.phone = phone;
    }

    public Integer getID() {
        return ID;
    }

    public void setID(Integer ID) {
        this.ID = ID;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getClassID() {
        return classID;
    }

    public void setClassID(String classID) {
        this.classID = classID;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getCardID() {
        return cardID;
    }

    public void setCardID(String cardID) {
        this.cardID = cardID;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Override
    public String toString() {
        return "User{" +
                "ID=" + ID +
                ", name='" + name + '\'' +
                ", classID='" + classID + '\'' +
                ", gender='" + gender + '\'' +
                ", cardID='" + cardID + '\'' +
                ", address='" + address + '\'' +
                ", phone='" + phone + '\'' +
                '}';
    }
}

配置xml

<update id="updata">

       update studentinformation
       set
           student_name=#{name},
           student_classID=#{classID},
           student_gender=#{gender},
           student_cardID=#{cardID},
           student_address=#{address},
           student_phone=#{phone}
       where ID=#{ID}

</update>

修改动态字段

<set>可以解决',' 和set后为空的问题 

   <update id="updata">
        update studentinformation
        <set>
          <if test="name !=null and name=''">
                <!--要加,-->
              student_name=#{name},
          </if>
           <if test="classId !=null">
               student_classID=#{classID},
           </if>
            <if test="gender !=null ">
                student_gender=#{gender},
            </if>
            <if test="cardId !=null">
                student_cardID=#{cardID},
            </if>
            <if test="address !=null">
                student_address=#{address},
            </if>
            <if test="phone !=null  ">
                student_phone=#{phone},
            </if>
        </set>
        where ID=#{ID}

    </update>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_53558470

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值