一、pom.xml
1 <overwrite>false</overwrite>
二、ItemModel
1 package com.miaoshaProject.service.model; 2 3 import java.io.Serializable; 4 import java.math.BigDecimal; 5 6 /** 7 * @Author wangshuo 8 * @Date 2022/4/18, 8:45 9 * Please add a comment 10 */ 11 public class ItemModel implements Serializable { 12 13 private Integer id; 14 15 private String title; 16 17 private String name; 18 19 private BigDecimal price; 20 21 private Integer stock; 22 23 private String description; 24 25 private Integer sales; 26 27 //商品描述图片的url 28 private String imgUrl; 29 30 public Integer getId() { 31 return id; 32 } 33 34 public void setId(Integer id) { 35 this.id = id; 36 } 37 38 public String getTitle() { 39 return title; 40 } 41 42 public void setTitle(String title) { 43 this.title = title; 44 } 45 46 public String getName() { 47 return name; 48 } 49 50 public void setName(String name) { 51 this.name = name; 52 } 53 54 public BigDecimal getPrice() { 55 return price; 56 } 57 58 public void setPrice(BigDecimal price) { 59 this.price = price; 60 } 61 62 public Integer getStock() { 63 return stock; 64 } 65 66 public void setStock(Integer stock) { 67 this.stock = stock; 68 } 69 70 public String getDescription() { 71 return description; 72 } 73 74 public void setDescription(String description) { 75 this.description = description; 76 } 77 78 public Integer getSales() { 79 return sales; 80 } 81 82 public void setSales(Integer sales) { 83 this.sales = sales; 84 } 85 86 public String getImgUrl() { 87 return imgUrl; 88 } 89 90 public void setImgUrl(String imgUrl) { 91 this.imgUrl = imgUrl; 92 } 93 }
三、item.sql
1 /* 2 Navicat Premium Data Transfer 3 4 Source Server : testOne 5 Source Server Type : MySQL 6 Source Server Version : 80028 7 Source Host : localhost:3306 8 Source Schema : miaosha 9 10 Target Server Type : MySQL 11 Target Server Version : 80028 12 File Encoding : 65001 13 14 Date: 18/04/2022 09:17:13 15 */ 16 17 SET NAMES utf8mb4; 18 SET FOREIGN_KEY_CHECKS = 0; 19 20 -- ---------------------------- 21 -- Table structure for item 22 -- ---------------------------- 23 DROP TABLE IF EXISTS `item`; 24 CREATE TABLE `item` ( 25 `id` int(0) NOT NULL AUTO_INCREMENT, 26 `title` varchar(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '', 27 `price` decimal(10, 2) NOT NULL DEFAULT 0.00, 28 `description` varchar(500) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '', 29 `sales` int(0) NOT NULL DEFAULT 0, 30 `img_url` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '', 31 PRIMARY KEY (`id`) USING BTREE 32 ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = Dynamic; 33 34 -- ---------------------------- 35 -- Table structure for item_stock 36 -- ---------------------------- 37 DROP TABLE IF EXISTS `item_stock`; 38 CREATE TABLE `item_stock` ( 39 `id` int(0) NOT NULL AUTO_INCREMENT, 40 `stock` int(0) NOT NULL DEFAULT 0 COMMENT '库存', 41 `item_id` int(0) NOT NULL DEFAULT 0, 42 PRIMARY KEY (`id`) USING BTREE 43 ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_unicode_ci ROW_FORMAT = Dynamic; 44 45 SET FOREIGN_KEY_CHECKS = 1;
四、mybatis-generator.xml
1 <!-- 商品表 --> 2 <table tableName="item" domainObjectName="ItemDO" enableCountByExample="false" 3 enableUpdateByExample="false" enableDeleteByExample="false" 4 enableSelectByExample="false" selectByExampleQueryId="false" 5 enableInsert="true" enableDeleteByPrimaryKey="false"></table> 6 7 <!-- 商品库存表 --> 8 <table tableName="item_stock" domainObjectName="ItemStockDO" 9 enableCountByExample="false" enableUpdateByExample="false" 10 enableDeleteByExample="false" enableSelectByExample="false" 11 selectByExampleQueryId="false" enableInsert="true" 12 enableDeleteByPrimaryKey="false"></table>
五、插件生成



六、修改insert策略
1 <insert id="insert" parameterType="com.miaoshaProject.dataobject.ItemStockDO" useGeneratedKeys="true" keyProperty="id"> 2 <!-- 3 WARNING - @mbg.generated 4 This element is automatically generated by MyBatis Generator, do not modify. 5 This element was generated on Mon Apr 18 09:20:26 CST 2022. 6 --> 7 insert into item_stock (id, stock, item_id 8 ) 9 values (#{id,jdbcType=INTEGER}, #{stock,jdbcType=INTEGER}, #{itemId,jdbcType=INTEGER} 10 ) 11 </insert> 12 <insert id="insertSelective" parameterType="com.miaoshaProject.dataobject.ItemStockDO" useGeneratedKeys="true" keyProperty="id"> 13 <!-- 14 WARNING - @mbg.generated 15 This element is automatically generated by MyBatis Generator, do not modify. 16 This element was generated on Mon Apr 18 09:20:26 CST 2022. 17 --> 18 insert into item_stock 19 <trim prefix="(" suffix=")" suffixOverrides=","> 20 <if test="id != null"> 21 id, 22 </if> 23 <if test="stock != null"> 24 stock, 25 </if> 26 <if test="itemId != null"> 27 item_id, 28 </if> 29 </trim> 30 <trim prefix="values (" suffix=")" suffixOverrides=","> 31 <if test="id != null"> 32 #{id,jdbcType=INTEGER}, 33 </if> 34 <if test="stock != null"> 35 #{stock,jdbcType=INTEGER}, 36 </if> 37 <if test="itemId != null"> 38 #{itemId,jdbcType=INTEGER}, 39 </if> 40 </trim> 41 </insert>
本文来自博客园,作者:荣慕平,转载请注明原文链接:https://www.cnblogs.com/rongmuping/articles/16164006.html
浙公网安备 33010602011771号