在dao层通过注解的形式去完成响应的功能
package com.example.demo.dao;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
@Mapper
@Component
public interface OrderDao {
/**
* 新增订单
*
* @param price 订单价格
* @param userId 用户id
* @param status 订单状态
* @return
*/
@Insert("insert into t_order(price,user_id,status) value(#{price},#{userId},#{status})")
int insertOrder(@Param("price") BigDecimal price, @Param("userId") Long userId,
@Param("status") String status);
/**
* 根据id列表查询多个订单
*
* @param orderIds 订单id列表
* @return
*/
@Select({"<script>" +
"select " + " * " +
" from t_order t" +
" where t.order_id in " +
"<foreach collection='orderIds' item='id' open='(' separator=',' close=')'>" + " #{id} " +
"</foreach>" + "</script>"})
List<Map> selectOrderByIds(@Param("orderIds") List<Long> orderIds);
/**
* 批量删除
* @param orderIds
* @return
*/
@Delete({"<script>" +
"delete from t_order where order_id in " +
"<foreach collection='orderIds' item='id' open='(' separator=',' close=')'>" + " #{id} " +
"</foreach>" + "</script>"})
int deleteOrders(@Param("orderIds") List<Long> orderIds);
/**
* 修改
* @param orderId
* @param price
* @param userId
* @param status
* @return
*/
@Update("<script> " + "update t_order" +
"<set>" + "<if test=\"price != null and price !=''\">price=#{price},</if>" +
"<if test=\"userId != null and userId !=''\">user_id=#{userId},</if>" +
"<if test=\"status != null and status !=''\">status=#{status},</if>" +
"</set>" + "where order_id=#{orderId}" +
" </script> ")
int updateOrder(@Param("price") double price, @Param("userId") Long userId, @Param("status") String status,@Param("orderId") Long orderId);
}