1.实体类
##引入宏定义
$
!define
#
set($entityName
= $tableInfo
.name
.substring(1))
##使用宏定义设置回调(保存位置与文件后缀)
#
save("/entity", ".java")
$
!callback
.setFileName($tool
.append($entityName
, ".java"))
##使用宏定义设置包后缀
#
setPackageSuffix("entity")
##使用全局变量实现默认包导入
$
!autoImport
import java
.io
.Serializable
;
import io
.swagger
.annotations
.ApiModel
;
import io
.swagger
.annotations
.ApiModelProperty
;
import lombok
.Data
;
import javax
.persistence
.Column
;
import javax
.persistence
.Table
;
import java
.io
.Serializable
;
import java
.util
.Date
;
##使用宏定义实现类注释信息
#
tableComment("实体类")
@Table(name
= "$tableInfo.obj.name")
@Data
@ApiModel(value
= "$!{entityName})", description
= "$!{tableInfo.comment}")
public class $
!{entityName
} implements Serializable {
private static final long serialVersionUID
= $
!tool
.serial();
#
foreach($column in $tableInfo
.fullColumn
)
#
if($
{column
.comment
})#end
@Column(name
= "$column.obj.name")
@ApiModelProperty(value
= "${column.comment}")
private $
!{tool
.getClsNameByFullName($column
.type
)} $
!{column
.name
};
#end
}
2.mapper
##定义初始变量
#
set($entityName
= $tableInfo
.name
.substring(1))
#
set($tableName
= $tool
.append($entityName
, "Mapper"))
##设置回调
$
!callback
.setFileName($tool
.append($tableName
, ".java"))
$
!callback
.setSavePath($tool
.append($tableInfo
.savePath
, "/mapper"))
#
if($tableInfo
.savePackageName
)package $
!{tableInfo
.savePackageName
}.#
{end
}mapper
;
import tk
.mybatis
.mapper
.common
.BaseMapper
;
import $
!{tableInfo
.savePackageName
}.entity
.$
!{tableInfo
.name
.substring(1)};
import java
.util
.List
;
import org
.apache
.ibatis
.annotations
.Mapper
;
@Mapper
public interface $
!{tableName
} extends BaseMapper<$
!{entityName
}> {
}
3.service
##定义初始变量
#
set($entityName
= $tableInfo
.name
.substring(1))
#
set($tableName
= $tool
.append($entityName
, "Service"))
##设置回调
$
!callback
.setFileName($tool
.append($tableName
, ".java"))
$
!callback
.setSavePath($tool
.append($tableInfo
.savePath
, "/service"))
##拿到主键
#
if(!$tableInfo
.pkColumn
.isEmpty())
#
set($pk
= $tableInfo
.pkColumn
.get(0))
#end
#
if($tableInfo
.savePackageName
)package $
!{tableInfo
.savePackageName
}.#
{end
}service
;
import org
.springframework
.beans
.factory
.annotation
.Autowired
;
import com
.zjf
.fmall
.mapper
.$
!{entityName
}Mapper
import org
.springframework
.stereotype
.Service
;
import $
!{tableInfo
.savePackageName
}.entity
.$
!{entityName
};
import java
.util
.List
;
import java
.time
.LocalDateTime
;
@Service
public class $
!{tableName
} {
@Autowired
private $
!{entityName
}Mapper $
!tool
.firstLowerCase($entityName
)Mapper
;
public JsonResult
insert($
!{entityName
} $
!tool
.firstLowerCase($entityName
)){
$
!{tool
.firstLowerCase($entityName
)}.setId(StringUtil
.getUUID());
$
!{tool
.firstLowerCase($entityName
)}Mapper
.insertSelective($
!tool
.firstLowerCase($entityName
));
return JsonResult
.success();
}
public JsonResult
update($
!{entityName
} $
!tool
.firstLowerCase($entityName
)){
$
!{tool
.firstLowerCase($entityName
)}.setUpdateTime(LocalDateTime
.now());
$
!{tool
.firstLowerCase($entityName
)}Mapper
.updateByPrimaryKeySelective($
!tool
.firstLowerCase($entityName
));
return JsonResult
.success();
}
public JsonResult
remove(String id
){
$
!{tool
.firstLowerCase($entityName
)}Mapper
.deleteByPrimaryKey(id
);
return JsonResult
.success();
}
public JsonResult
findOne($
!{entityName
} $
!tool
.firstLowerCase($entityName
)){
return JsonResult
.success($
!{tool
.firstLowerCase($entityName
)}Mapper
.selectOne($
!tool
.firstLowerCase($entityName
)));
}
}
4.controller
##定义初始变量
#
set($tableName
= $tool
.append($tableInfo
.name
.substring(1), "Controller"))
#
set($entityName
= $tableInfo
.name
.substring(1))
##设置回调
$
!callback
.setFileName($tool
.append($tableName
, ".java"))
$
!callback
.setSavePath($tool
.append($tableInfo
.savePath
, "/controller"))
##拿到主键
#
if(!$tableInfo
.pkColumn
.isEmpty())
#
set($pk
= $tableInfo
.pkColumn
.get(0))
#end
#
if($tableInfo
.savePackageName
)package $
!{tableInfo
.savePackageName
}.#
{end
}controller
;
import $
!{tableInfo
.savePackageName
}.entity
.$
!{tableInfo
.name
};
import $
!{tableInfo
.savePackageName
}.service
.$
!{tableInfo
.name
}Service
;
import org
.springframework
.web
.bind
.annotation
.*
;
import org
.springframework
.beans
.factory
.annotation
.Autowired
;
@RestController
@RequestMapping("$!tool.firstLowerCase($entityName)")
public class $
!{tableName
} {
@Autowired
private $
!{entityName
}Service $
!tool
.firstLowerCase($entityName
)Service
;
}
转载请注明原文地址:https://tech.qufami.com/read-3139.html