笔记
User
package com.chinasofti.domain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.Serializable;
public class User implements Serializable
{
private static final long serialVersionUID = 1L;
private Long id;
private String username;
@JsonIgnore
private String password;
private String phone;
private String email;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setUsername(String username)
{
this.username = username;
}
public String getUsername()
{
return username;
}
public void setPassword(String password)
{
this.password = password;
}
public String getPassword()
{
return password;
}
public void setPhone(String phone)
{
this.phone = phone;
}
public String getPhone()
{
return phone;
}
public void setEmail(String email)
{
this.email = email;
}
public String getEmail()
{
return email;
}
}
UserMapper
<?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.chinasofti.manager.mapper.IUserMapper">
<resultMap id="UserResult" type="com.chinasofti.domain.User">
<result property="id" column="id"/>
<result property="username" column="username"/>
<result property="password" column="password"/>
<result property="phone" column="phone"/>
<result property="email" column="email"/>
</resultMap>
<sql id="selectUserVo">
select id,username,password,phone,email from user
</sql>
<!-- 根据ID进行查询 -->
<select id="selectUserById" parameterType="Long" resultMap="UserResult">
<include refid="selectUserVo"/>
where id = #{id}
</select>
<!-- 根据条件查询 -->
<select id="selectUserList" parameterType="com.chinasofti.domain.User" resultMap="UserResult">
<include refid="selectUserVo"/>
<where>
<if test="id!=null">and id=#{id}</if>
<if test="username!=null and username!=''">and username=#{username}</if>
<if test="password!=null and password!=''">and password=#{password}</if>
<if test="phone!=null and phone!=''">and phone=#{phone}</if>
<if test="email!=null and email!=''">and email=#{email}</if>
</where>
</select>
<!-- 增加 -->
<insert id="insertUser" parameterType="com.chinasofti.domain.User">
insert into user
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id!=null">id,</if>
<if test="username!=null and username!=''">username,</if>
<if test="password!=null and password!=''">password,</if>
<if test="phone!=null and phone!=''">phone,</if>
<if test="email!=null and email!=''">email,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id!=null">#{id},</if>
<if test="username!=null and username!=''">#{username},</if>
<if test="password!=null and password!=''">#{password},</if>
<if test="phone!=null and phone!=''">#{phone},</if>
<if test="email!=null and email!=''">#{email},</if>
</trim>
</insert>
<!-- 根据id值进行删除 -->
<delete id="deleteUserById" parameterType="Long">
delete from user where id=#{id}
</delete>
<!-- 修改用户 -->
<update id="updateUser" parameterType="com.chinasofti.domain.User">
update user
<trim prefix="set" suffixOverrides=",">
<if test="username !=null and username !=''">username =#{username},</if>
<if test="password !=null and password !=''">password =#{password},</if>
<if test="phone !=null and phone !=''">phone =#{phone},</if>
<if test="email !=null and email !=''">email =#{email},</if>
</trim>
where id=#{id}
</update>
<!-- 根据ids 进行批量删除 -->
<delete id="deleteUserByIds" parameterType="java.lang.String">
delete from user where id in
<foreach collection="array" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>
Cart
package com.chinasofti.domain;
import java.io.Serializable;
import java.util.Date;
public class Cart implements Serializable
{
private static final long serialVersionUID = 1L;
private Long id;
private Long userId;
private Long productId;
private String productTitle;
private String productImage;
private Long productPrice;
private Integer num;
private Date created;
private Date updated;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setUserId(Long userId)
{
this.userId = userId;
}
public Long getUserId()
{
return userId;
}
public void setProductId(Long productId)
{
this.productId = productId;
}
public Long getProductId()
{
return productId;
}
public void setProductTitle(String productTitle)
{
this.productTitle = productTitle;
}
public String getProductTitle()
{
return productTitle;
}
public void setProductImage(String productImage)
{
this.productImage = productImage;
}
public String getProductImage()
{
return productImage;
}
public void setProductPrice(Long productPrice)
{
this.productPrice = productPrice;
}
public Long getProductPrice()
{
return productPrice;
}
public void setNum(Integer num)
{
this.num = num;
}
public Integer getNum()
{
return num;
}
public void setCreated(Date created)
{
this.created = created;
}
public Date getCreated()
{
return created;
}
public void setUpdated(Date updated)
{
this.updated = updated;
}
public Date getUpdated()
{
return updated;
}
}
CartMapper
<?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.chinasofti.mapper.CartMapper">
<resultMap type="Cart" id="CartResult">
<result property="id" column="id" />
<result property="userId" column="userId" />
<result property="productId" column="productId" />
<result property="productTitle" column="productTitle" />
<result property="productImage" column="productImage" />
<result property="productPrice" column="productPrice" />
<result property="num" column="num" />
<result property="created" column="created" />
<result property="updated" column="updated" />
</resultMap>
<sql id="selectCartVo">
select id, userId, productId, productTitle, productImage, productPrice, num, created, updated from cart
</sql>
<select id="selectCartList" parameterType="Cart" resultMap="CartResult">
<include refid="selectCartVo"/>
<where>
<if test="id != null "> and id = #{id}</if>
<if test="userId != null "> and userId = #{userId}</if>
<if test="productId != null "> and productId = #{productId}</if>
<if test="productTitle != null and productTitle != '' "> and productTitle = #{productTitle}</if>
<if test="productImage != null and productImage != '' "> and productImage = #{productImage}</if>
<if test="productPrice != null "> and productPrice = #{productPrice}</if>
<if test="num != null "> and num = #{num}</if>
<if test="created != null "> and created = #{created}</if>
<if test="updated != null "> and updated = #{updated}</if>
</where>
</select>
<select id="selectCartById" parameterType="Long" resultMap="CartResult">
<include refid="selectCartVo"/>
where id = #{id}
</select>
<insert id="insertCart" parameterType="Cart" useGeneratedKeys="true" keyProperty="id">
insert into cart
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="userId != null ">userId,</if>
<if test="productId != null ">productId,</if>
<if test="productTitle != null and productTitle != '' ">productTitle,</if>
<if test="productImage != null and productImage != '' ">productImage,</if>
<if test="productPrice != null ">productPrice,</if>
<if test="num != null ">num,</if>
<if test="created != null ">created,</if>
<if test="updated != null ">updated,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="userId != null ">#{userId},</if>
<if test="productId != null ">#{productId},</if>
<if test="productTitle != null and productTitle != '' ">#{productTitle},</if>
<if test="productImage != null and productImage != '' ">#{productImage},</if>
<if test="productPrice != null ">#{productPrice},</if>
<if test="num != null ">#{num},</if>
<if test="created != null ">#{created},</if>
<if test="updated != null ">#{updated},</if>
</trim>
</insert>
<update id="updateCart" parameterType="Cart">
update cart
<trim prefix="SET" suffixOverrides=",">
<if test="userId != null ">userId = #{userId},</if>
<if test="productId != null ">productId = #{productId},</if>
<if test="productTitle != null and productTitle != '' ">productTitle = #{productTitle},</if>
<if test="productImage != null and productImage != '' ">productImage = #{productImage},</if>
<if test="productPrice != null ">productPrice = #{productPrice},</if>
<if test="num != null ">num = #{num},</if>
<if test="created != null ">created = #{created},</if>
<if test="updated != null ">updated = #{updated},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteCartById" parameterType="Long">
delete from cart where id = #{id}
</delete>
<delete id="deleteCartByIds" parameterType="String">
delete from cart where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>