当前位置: 首页 > news >正文

Mysql mybatis 语法示例

 service

package com.ruoyi.goods.service;import java.util.List;
import com.ruoyi.goods.domain.GoodsProducts;/*** 商品Service接口* * @author ruoyi* @date 2023-08-27*/
public interface IGoodsProductsService 
{/*** 查询商品* * @param ProductID 商品主键* @return 商品*/public GoodsProducts selectGoodsProductsByProductID(Long ProductID);/*** 查询商品列表* * @param goodsProducts 商品* @return 商品集合*/public List<GoodsProducts> selectGoodsProductsList(GoodsProducts goodsProducts);/*** 新增商品* * @param goodsProducts 商品* @return 结果*/public int insertGoodsProducts(GoodsProducts goodsProducts);/*** 修改商品* * @param goodsProducts 商品* @return 结果*/public int updateGoodsProducts(GoodsProducts goodsProducts);/*** 批量删除商品* * @param ProductIDs 需要删除的商品主键集合* @return 结果*/public int deleteGoodsProductsByProductIDs(Long[] ProductIDs);/*** 删除商品信息* * @param ProductID 商品主键* @return 结果*/public int deleteGoodsProductsByProductID(Long ProductID);
}

 xml

<?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.ruoyi.goods.mapper.GoodsProductsMapper"><resultMap type="GoodsProducts" id="GoodsProductsResult"><result property="ProductID"    column="ProductID"    /><result property="Name"    column="Name"    /><result property="Price"    column="Price"    /><result property="Description"    column="Description"    /><result property="Category"    column="Category"    /><result property="StockQuantity"    column="StockQuantity"    /></resultMap><sql id="selectGoodsProductsVo">select ProductID, Name, Price, Description, Category, StockQuantity from goods_products</sql><select id="selectGoodsProductsList" parameterType="GoodsProducts" resultMap="GoodsProductsResult"><include refid="selectGoodsProductsVo"/><where><if test="Name != null  and Name != ''"> and Name like concat('%', #{Name}, '%')</if><if test="Price != null "> and Price = #{Price}</if><if test="Description != null  and Description != ''"> and Description = #{Description}</if><if test="Category != null  and Category != ''"> and Category = #{Category}</if><if test="StockQuantity != null "> and StockQuantity = #{StockQuantity}</if></where></select><select id="selectGoodsProductsByProductID" parameterType="Long" resultMap="GoodsProductsResult"><include refid="selectGoodsProductsVo"/>where ProductID = #{ProductID}</select><insert id="insertGoodsProducts" parameterType="GoodsProducts" useGeneratedKeys="true" keyProperty="ProductID">insert into goods_products<trim prefix="(" suffix=")" suffixOverrides=","><if test="Name != null and Name != ''">Name,</if><if test="Price != null">Price,</if><if test="Description != null">Description,</if><if test="Category != null">Category,</if><if test="StockQuantity != null">StockQuantity,</if></trim><trim prefix="values (" suffix=")" suffixOverrides=","><if test="Name != null and Name != ''">#{Name},</if><if test="Price != null">#{Price},</if><if test="Description != null">#{Description},</if><if test="Category != null">#{Category},</if><if test="StockQuantity != null">#{StockQuantity},</if></trim></insert><update id="updateGoodsProducts" parameterType="GoodsProducts">update goods_products<trim prefix="SET" suffixOverrides=","><if test="Name != null and Name != ''">Name = #{Name},</if><if test="Price != null">Price = #{Price},</if><if test="Description != null">Description = #{Description},</if><if test="Category != null">Category = #{Category},</if><if test="StockQuantity != null">StockQuantity = #{StockQuantity},</if></trim>where ProductID = #{ProductID}</update><delete id="deleteGoodsProductsByProductID" parameterType="Long">delete from goods_products where ProductID = #{ProductID}</delete><delete id="deleteGoodsProductsByProductIDs" parameterType="String">delete from goods_products where ProductID in <foreach item="ProductID" collection="array" open="(" separator="," close=")">#{ProductID}</foreach></delete>
</mapper>

http://www.lryc.cn/news/260485.html

相关文章:

  • 第77讲:二进制方式搭建MySQL数据库5.7版本以及错误日志管理
  • R语言,table()函数实现统计每个元素出现的频数+并将最终统计频数结果转换成dataframe数据框形式
  • 微信小程序uniapp记住密码
  • 喜报!Coremail荣获2023信创“大比武”优秀生态融合奖
  • 知识库SEO:提升网站内容质量与搜索引擎排名的策略
  • GPIO复用时5个调试接口引脚要注意
  • 华为云CodeArts Check常见问答汇总
  • linux 应用开发笔记---【信号:基础】
  • 区块链:改变世界的技术
  • 防御升级!SMC2助力企业高效应对邮箱安全挑战
  • 19.(vue3.x+vite)v-if和v-for哪个优先级更高
  • 12. IO
  • 【稳定检索|投稿优惠】2024年艺术鉴赏与社会科学教育国际会议(ICAASSE 2024)
  • leetCode算法—3.无重复字符的最长子串
  • STM32 寄存器配置笔记——USART DMA接收
  • (基础篇)通过node增删改查连接mysql数据库
  • 做为一个产品经理带你详细了解--动态面板的使用
  • 严世芸龟法养生经
  • 基于OHTPPS实现网站HTTPS访问
  • python|获取接口请求耗时
  • [PyTorch][chapter 7][李宏毅深度学习][深度学习简介]
  • 【go语言实践一】go语言基础篇一
  • 深度学习 Day12——P1实现mnist手写数字识别
  • 【Docker实战】基于Dockerfile搭建LNMP+wordpress
  • 【桌面应用开发】Tauri是什么?基于Rust的桌面应用
  • PHP的协程是什么?
  • three.js 入门三:buffergeometry贴图属性(position、index和uvs)
  • Initial用法-FPGA入门3
  • perl脚本中使用eval函数执行可能有异常的操作
  • 『Redis』在Docker中快速部署Redis并进行数据持久化挂载