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>
spring0625mybatise
最新推荐文章于 2022-06-06 14:54:52 发布