spring0625mybatise

package com.zypcy.expend.dao;

import com.zypcy.expend.entity.Customer;

import java.util.List;

public interface CustomerMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Customer record);

    int insertSelective(Customer record);

    Customer selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Customer record);

    int updateByPrimaryKey(Customer record);

    List<Customer> listByAll();

    List<Customer> listPages();
}

package com.zypcy.expend.entity;

public class Customer {
    private Integer id;

    private String name;

    private Integer age;

    private Boolean isUse;

    public Customer(){}

    public Customer(Integer id, String name, Integer age, Boolean isUse) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.isUse = isUse;
    }

    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 == null ? null : name.trim();
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Boolean getIsUse() {
        return isUse;
    }

    public void setIsUse(Boolean isUse) {
        this.isUse = isUse;
    }
}



<?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.zypcy.expend.dao.CustomerMapper">
  <resultMap id="BaseResultMap" type="com.zypcy.expend.entity.Customer">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="age" jdbcType="INTEGER" property="age" />
    <result column="is_use" jdbcType="BIT" property="isUse" />
  </resultMap>
  <sql id="Base_Column_List">
    id, name, age, is_use
  </sql>

  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from customers
    where id = #{id,jdbcType=INTEGER}
  </select>

  <select id="listByAll" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from customers
  </select>

  <!-- 翻页 -->
  <select id="listPages" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from customers
    order by id desc
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from customers
    where id = #{id,jdbcType=INTEGER}
  </delete>

  <insert id="insert" parameterType="com.zypcy.expend.entity.Customer">
    insert into customers (name, age, is_use)
    values (#{name,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER}, #{isUse,jdbcType=BIT})
  </insert>

  <insert id="insertSelective" parameterType="com.zypcy.expend.entity.Customer">
    insert into customers
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="age != null">
        age,
      </if>
      <if test="isUse != null">
        is_use,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="age != null">
        #{age,jdbcType=INTEGER},
      </if>
      <if test="isUse != null">
        #{isUse,jdbcType=BIT},
      </if>
    </trim>
  </insert>

  <update id="updateByPrimaryKeySelective" parameterType="com.zypcy.expend.entity.Customer">
    update customers
    <set>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="age != null">
        age = #{age,jdbcType=INTEGER},
      </if>
      <if test="isUse != null">
        is_use = #{isUse,jdbcType=BIT},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>

  <update id="updateByPrimaryKey" parameterType="com.zypcy.expend.entity.Customer">
    update customers
    set name = #{name,jdbcType=VARCHAR},
      age = #{age,jdbcType=INTEGER},
      is_use = #{isUse,jdbcType=BIT}
    where id = #{id,jdbcType=INTEGER}
  </update>

</mapper>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值