当前位置:编程学堂 > EasyJava 一个java代码生成工具

EasyJava 一个java代码生成工具

  • 发布:2023-09-09 17:38

前言

经过半个月的时间,终于把我自己写的java代码生成工具,录制成了视频教程。

视频地址

https://www.sychzs.cn/video/BV1EN4y1c7sL/

接下来我们简单介绍下生成的项目结构

表结构

CREATE TABLE `tb_product_info` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增ID',`company_id` varchar(30) DEFAULT NULL COMMENT '公司ID',`code` varchar(11) DEFAULT NULL COMMENT '商品编号',`product_name` varchar(200) DEFAULT NULL COMMENT '商品名称',`price` decimal(15,2) DEFAULT NULL COMMENT '价格',`sku_type` tinyint(4) DEFAULT NULL COMMENT 'sku类型',`color_type` tinyint(4) DEFAULT NULL COMMENT '颜色类型',`create_time` datetime DEFAULT NULL COMMENT '创建时间',`create_date` date DEFAULT NULL COMMENT '创建日期',`stock` bigint(20) DEFAULT NULL COMMENT '库存',`status` tinyint(4) DEFAULT NULL COMMENT '状态:0 未上架  1:已上架',`is_del` tinyint(4) DEFAULT NULL COMMENT '0:删除 1:正常',PRIMARY KEY (`id`),UNIQUE KEY `idx_code` (`code`) USING BTREE,UNIQUE KEY `idx_sku_color` (`sku_type`,`color_type`),KEY `idx_name` (`product_name`)
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8 COMMENT='商品信息';

这个表有 一个自增ID,一个唯一索引 code,还有一个 联合唯一索引,我们会根据这些关键的表信息生成相关的方法

生成Java代码

项目结构


生成的controller

@RestController
@RequestMapping("/productInfo")
public class ProductInfoController extends ABaseController {@Resourceprivate ProductInfoService productInfoService;@RequestMapping("loadDataList")public ResponseVO loadDataList(ProductInfoQuery query) {return getSuccessResponseVO(productInfoService.findListByPage(query));}/*** 新增*/@RequestMapping("add")public ResponseVO add(ProductInfo bean) {this.productInfoService.add(bean);return getSuccessResponseVO(null);}/*** 批量新增*/@RequestMapping("addBatch")public ResponseVO addBatch(@RequestBody List<ProductInfo> listBean) {this.productInfoService.addBatch(listBean);return getSuccessResponseVO(null);}/*** 批量新增或修改*/@RequestMapping("addOrUpdateBatch")public ResponseVO addOrUpdateBatch(@RequestBody List<ProductInfo> listBean) {this.productInfoService.addOrUpdateBatch(listBean);return getSuccessResponseVO(null);}/*** 根据Id查询*/@RequestMapping("getProductInfoById")public ResponseVO getProductInfoById(Integer id) {return getSuccessResponseVO(this.productInfoService.getProductInfoById(id));}/*** 根据Id更新*/@RequestMapping("updateProductInfoById")public ResponseVO updateProductInfoById(ProductInfo bean, Integer id) {this.productInfoService.updateProductInfoById(bean,id);return getSuccessResponseVO(null);}/*** 根据Id删除*/@RequestMapping("deleteProductInfoById")public ResponseVO deleteProductInfoById(Integer id) {this.productInfoService.deleteProductInfoById(id);return getSuccessResponseVO(null);}/*** 根据Code查询*/@RequestMapping("getProductInfoByCode")public ResponseVO getProductInfoByCode(String code) {return getSuccessResponseVO(this.productInfoService.getProductInfoByCode(code));}/*** 根据Code更新*/@RequestMapping("updateProductInfoByCode")public ResponseVO updateProductInfoByCode(ProductInfo bean, String code) {this.productInfoService.updateProductInfoByCode(bean,code);return getSuccessResponseVO(null);}/*** 根据Code删除*/@RequestMapping("deleteProductInfoByCode")public ResponseVO deleteProductInfoByCode(String code) {this.productInfoService.deleteProductInfoByCode(code);return getSuccessResponseVO(null);}/*** 根据SkuTypeAndColorType查询*/@RequestMapping("getProductInfoBySkuTypeAndColorType")public ResponseVO getProductInfoBySkuTypeAndColorType(Integer skuType, Integer colorType) {return getSuccessResponseVO(this.productInfoService.getProductInfoBySkuTypeAndColorType(skuType, colorType));}/*** 根据SkuTypeAndColorType更新*/@RequestMapping("updateProductInfoBySkuTypeAndColorType")public ResponseVO updateProductInfoBySkuTypeAndColorType(ProductInfo bean, Integer skuType, Integer colorType) {this.productInfoService.updateProductInfoBySkuTypeAndColorType(bean,skuType, colorType);return getSuccessResponseVO(null);}/*** 根据SkuTypeAndColorType删除*/@RequestMapping("deleteProductInfoBySkuTypeAndColorType")public ResponseVO deleteProductInfoBySkuTypeAndColorType(Integer skuType, Integer colorType) {this.productInfoService.deleteProductInfoBySkuTypeAndColorType(skuType, colorType);return getSuccessResponseVO(null);}}

我就不把所有类都列举出来了,重点看下mapper.xml

Mapper.xml


DOCTYPE mapper PUBLIC "-//www.sychzs.cn//DTD Mapper 3.0//EN""http://www.sychzs.cn/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.easyjava.mappers.ProductInfoMapper"><resultMap id="base_result_map" type="com.easyjava.entity.po.ProductInfo">    <id column="id" property="id"/><result column="company_id" property="companyId"/><result column="code" property="code"/><result column="product_name" property="productName"/><result column="price" property="price"/><result column="sku_type" property="skuType"/><result column="color_type" property="colorType"/><result column="create_time" property="createTime"/><result column="create_date" property="createDate"/><result column="stock" property="stock"/><result column="status" property="status"/><result column="is_del" property="isDel"/>resultMap><sql id="base_column_list">id,company_id,code,product_name,price,sku_type,color_type,create_time,create_date,stock,status,is_delsql><sql id="base_query_condition"><if test="www.sychzs.cn != null">and id = #{www.sychzs.cn}if><if test="query.companyId != null and query.companyId!=''">and id = #{query.companyId}if><if test="query.code != null and query.code!=''">and id = #{query.code}if><if test="query.productName != null and query.productName!=''">and id = #{query.productName}if><if test="query.price != null">and id = #{query.price}if><if test="query.skuType != null">and id = #{query.skuType}if><if test="query.colorType != null">and id = #{query.colorType}if><if test="query.createTime != null">and id = #{query.createTime}if><if test="query.createDate != null">and id = #{query.createDate}if><if test="query.stock != null">and id = #{query.stock}if><if test="query.status != null">and id = #{query.status}if><if test="query.isDel != null">and id = #{query.isDel}if>sql><sql id="base_query_condition_extend"><if test="query.companyIdFuzzy != null and query.companyIdFuzzy !=''">and company_id like concat('%', #{query.companyIdFuzzy}, '%')if><if test="query.codeFuzzy != null and query.codeFuzzy !=''">and code like concat('%', #{query.codeFuzzy}, '%')if><if test="query.productNameFuzzy != null and query.productNameFuzzy !=''">and product_name like concat('%', #{query.productNameFuzzy}, '%')if><if test="query.createTimeStart != null and query.createTimeStart !=''">= str_to_date(#{query.createTimeStart}, '%Y-%m-%d') ]]>if><if test="query.createTimeEnd != null and query.createTimeEnd !=''">if><if test="query.createDateStart != null and query.createDateStart !=''">= str_to_date(#{query.createDateStart}, '%Y-%m-%d') ]]>if><if test="query.createDateEnd != null and query.createDateEnd !=''">if>sql><sql id="query_condition"><where><include refid="base_query_condition"/><include refid="base_query_condition_extend"/>where>sql><select id="selectList" resultMap="base_result_map">SELECT <include refid="base_column_list"/> FROM tb_product_info <include refid="query_condition"/><if test="query.orderBy!=null">order by ${query.orderBy}if><if test="query.simplePage!=null">limit #{query.simplePage.start},#{query.simplePage.end}if>select><select id="selectCount" resultType="java.lang.Integer">SELECT count(1) FROM tb_product_info <include refid="query_condition"/>select><insert id="insert" parameterType="com.easyjava.entity.po.ProductInfo"><selectKey keyProperty="www.sychzs.cn" resultType="Integer" order="AFTER">SELECT LAST_INSERT_ID()selectKey>INSERT INTO tb_product_info<trim prefix="(" suffix=")" suffixOverrides=","><if test="www.sychzs.cn != null">id,if><if test="bean.companyId != null">company_id,if><if test="bean.code != null">code,if><if test="bean.productName != null">product_name,if><if test="bean.price != null">price,if><if test="bean.skuType != null">sku_type,if><if test="bean.colorType != null">color_type,if><if test="bean.createTime != null">create_time,if><if test="bean.createDate != null">create_date,if><if test="bean.stock != null">stock,if><if test="bean.status != null">status,if><if test="bean.isDel != null">is_del,if>trim><trim prefix="values (" suffix=")" suffixOverrides=","><if test="www.sychzs.cn!=null">#{www.sychzs.cn},if><if test="bean.companyId!=null">#{bean.companyId},if><if test="bean.code!=null">#{bean.code},if><if test="bean.productName!=null">#{bean.productName},if><if test="bean.price!=null">#{bean.price},if><if test="bean.skuType!=null">#{bean.skuType},if><if test="bean.colorType!=null">#{bean.colorType},if><if test="bean.createTime!=null">#{bean.createTime},if><if test="bean.createDate!=null">#{bean.createDate},if><if test="bean.stock!=null">#{bean.stock},if><if test="bean.status!=null">#{bean.status},if><if test="bean.isDel!=null">#{bean.isDel},if>trim>insert><insert id="insertOrUpdate" parameterType="com.easyjava.entity.po.ProductInfo">INSERT INTO tb_product_info<trim prefix="(" suffix=")" suffixOverrides=","><if test="www.sychzs.cn != null">id,if><if test="bean.companyId != null">company_id,if><if test="bean.code != null">code,if><if test="bean.productName != null">product_name,if><if test="bean.price != null">price,if><if test="bean.skuType != null">sku_type,if><if test="bean.colorType != null">color_type,if><if test="bean.createTime != null">create_time,if><if test="bean.createDate != null">create_date,if><if test="bean.stock != null">stock,if><if test="bean.status != null">status,if><if test="bean.isDel != null">is_del,if>trim><trim prefix="values (" suffix=")" suffixOverrides=","><if test="www.sychzs.cn!=null">#{www.sychzs.cn},if><if test="bean.companyId!=null">#{bean.companyId},if><if test="bean.code!=null">#{bean.code},if><if test="bean.productName!=null">#{bean.productName},if><if test="bean.price!=null">#{bean.price},if><if test="bean.skuType!=null">#{bean.skuType},if><if test="bean.colorType!=null">#{bean.colorType},if><if test="bean.createTime!=null">#{bean.createTime},if><if test="bean.createDate!=null">#{bean.createDate},if><if test="bean.stock!=null">#{bean.stock},if><if test="bean.status!=null">#{bean.status},if><if test="bean.isDel!=null">#{bean.isDel},if>trim>on DUPLICATE key update<trim prefix="" suffix="" suffixOverrides=","><if test="bean.companyId!=null">company_id = VALUES(company_id),if><if test="bean.productName!=null">product_name = VALUES(product_name),if><if test="bean.price!=null">price = VALUES(price),if><if test="bean.createTime!=null">create_time = VALUES(create_time),if><if test="bean.createDate!=null">create_date = VALUES(create_date),if><if test="bean.stock!=null">stock = VALUES(stock),if><if test="bean.status!=null">status = VALUES(status),if><if test="bean.isDel!=null">is_del = VALUES(is_del),if>trim>insert><insert id="insertBatch" parameterType="com.easyjava.entity.po.ProductInfo">INSERT INTO tb_product_info(company_id,code,product_name,price,sku_type,color_type,create_time,create_date,stock,status,is_del)values<foreach collection="list" item="item" separator="," >(#{item.companyId},#{item.code},#{item.productName},#{item.price},#{item.skuType},#{item.colorType},#{item.createTime},#{item.createDate},#{item.stock},#{item.status},#{item.isDel})foreach>insert><insert id="insertOrUpdateBatch" parameterType="com.easyjava.entity.po.ProductInfo">INSERT INTO tb_product_info(company_id,code,product_name,price,sku_type,color_type,create_time,create_date,stock,status,is_del)values<foreach collection="list" item="item" separator=",">(#{item.companyId},#{item.code},#{item.productName},#{item.price},#{item.skuType},#{item.colorType},#{item.createTime},#{item.createDate},#{item.stock},#{item.status},#{item.isDel})foreach>on DUPLICATE key update id = VALUES(id),company_id = VALUES(company_id),code = VALUES(code),product_name = VALUES(product_name),price = VALUES(price),sku_type = VALUES(sku_type),color_type = VALUES(color_type),create_time = VALUES(create_time),create_date = VALUES(create_date),stock = VALUES(stock),status = VALUES(status),is_del = VALUES(is_del)insert><select id="selectById" resultMap="base_result_map">select <include refid="base_column_list"/>  from tb_product_info where id=#{id}select><update id="updateById" parameterType="com.easyjava.entity.po.ProductInfo">update tb_product_info<set><if test="www.sychzs.cn!= null">id = #{www.sychzs.cn},if><if test="bean.companyId!= null">company_id = #{bean.companyId},if><if test="bean.code!= null">code = #{bean.code},if><if test="bean.productName!= null">product_name = #{bean.productName},if><if test="bean.price!= null">price = #{bean.price},if><if test="bean.skuType!= null">sku_type = #{bean.skuType},if><if test="bean.colorType!= null">color_type = #{bean.colorType},if><if test="bean.createTime!= null">create_time = #{bean.createTime},if><if test="bean.createDate!= null">create_date = #{bean.createDate},if><if test="bean.stock!= null">stock = #{bean.stock},if><if test="bean.status!= null">status = #{bean.status},if><if test="bean.isDel!= null">is_del = #{bean.isDel},if>set>where id=#{id}update><delete id="deleteById">delete from tb_product_info where id=#{id}delete><select id="selectByCode" resultMap="base_result_map">select <include refid="base_column_list"/>  from tb_product_info where code=#{code}select><update id="updateByCode" parameterType="com.easyjava.entity.po.ProductInfo">update tb_product_info<set><if test="www.sychzs.cn!= null">id = #{www.sychzs.cn},if><if test="bean.companyId!= null">company_id = #{bean.companyId},if><if test="bean.code!= null">code = #{bean.code},if><if test="bean.productName!= null">product_name = #{bean.productName},if><if test="bean.price!= null">price = #{bean.price},if><if test="bean.skuType!= null">sku_type = #{bean.skuType},if><if test="bean.colorType!= null">color_type = #{bean.colorType},if><if test="bean.createTime!= null">create_time = #{bean.createTime},if><if test="bean.createDate!= null">create_date = #{bean.createDate},if><if test="bean.stock!= null">stock = #{bean.stock},if><if test="bean.status!= null">status = #{bean.status},if><if test="bean.isDel!= null">is_del = #{bean.isDel},if>set>where code=#{code}update><delete id="deleteByCode">delete from tb_product_info where code=#{code}delete><select id="selectBySkuTypeAndColorType" resultMap="base_result_map">select <include refid="base_column_list"/>  from tb_product_info where sku_type=#{skuType} and color_type=#{colorType}select><update id="updateBySkuTypeAndColorType" parameterType="com.easyjava.entity.po.ProductInfo">update tb_product_info<set><if test="www.sychzs.cn!= null">id = #{www.sychzs.cn},if><if test="bean.companyId!= null">company_id = #{bean.companyId},if><if test="bean.code!= null">code = #{bean.code},if><if test="bean.productName!= null">product_name = #{bean.productName},if><if test="bean.price!= null">price = #{bean.price},if><if test="bean.skuType!= null">sku_type = #{bean.skuType},if><if test="bean.colorType!= null">color_type = #{bean.colorType},if><if test="bean.createTime!= null">create_time = #{bean.createTime},if><if test="bean.createDate!= null">create_date = #{bean.createDate},if><if test="bean.stock!= null">stock = #{bean.stock},if><if test="bean.status!= null">status = #{bean.status},if><if test="bean.isDel!= null">is_del = #{bean.isDel},if>set>where sku_type=#{skuType} and color_type=#{colorType}update><delete id="deleteBySkuTypeAndColorType">delete from tb_product_info where sku_type=#{skuType} and color_type=#{colorType}delete>mapper>

可以生成 基本的 分页查询、单条插入、单条插入或者更新、批量插入、批量插入或者更新、根据主键、唯一索引 单挑查询、修改、删除

具体有哪些功能,大家看视频吧,视频第一张有演示项目功能,如果你厌倦了CRUD,那就快学起来吧

相关文章

热门推荐