entity
代码语言:javascript
复制##引入宏定义
$!{define.vm}
##使用宏定义设置回调(保存位置与文件后缀)
#save("/entity", ".java")
##使用宏定义设置包后缀
#setPackageSuffix("entity")
##使用全局变量实现默认包导入
$!{autoImport.vm}
##自动导入包(全局变量)
$!autoImport
import com.baomidou.mybatisplus.extension.activerecord.Model;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
##表注释(宏定义)
@EqualsAndHashCode(callSuper = true)
@Data
public class $!{tableInfo.name} extends Model<$!{tableInfo.name}> {
#foreach($column in $tableInfo.fullColumn)
#if(${column.comment})@ApiModelProperty(value = "${column.comment}")#end
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
#foreach($column in $tableInfo.pkColumn)
/**
* 获取主键值
*
* @return 主键值
*/
@Override
protected Serializable pkVal() {
return this.$!column.name;
}
#break
#end
}
controller
代码语言:javascript
复制##引入宏定义
$!{define.vm}
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Controller"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/controller"))
##使用宏定义设置包后缀
#setPackageSuffix("controller")
##定义服务名
#set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service"))
##定义实体对象名
#set($entityName = $!tool.firstLowerCase($!tableInfo.name))
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import $!{tableInfo.savePackageName}.entity.$!tableInfo.name;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
##表注释(宏定义)
#tableComment("表控制层")
@Api(tags = "$!tableInfo.name")
@RestController
@RequestMapping("$!tool.firstLowerCase($!tableInfo.name)")
public class $!{tableName} extends ApiController {
/**
* 服务对象
*/
@Resource
private $!{tableInfo.name}Service $!{serviceName};
/**
* 分页查询所有数据
*
* @param page 分页对象
* @param $!entityName 查询实体
* @return 所有数据
*/
@GetMapping
public R<Page<$!tableInfo.name>> selectAll(Page<$!tableInfo.name> page, $!tableInfo.name $!entityName) {
return success(this.$!{serviceName}.page(page, new QueryWrapper<>($!entityName)));
}
/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping("{id}")
public R<$!tableInfo.name> selectOne(@PathVariable Serializable id) {
return success(this.$!{serviceName}.getById(id));
}
/**
* 新增数据
*
* @param $!entityName 实体对象
* @return 新增结果
*/
@PostMapping
public R<Boolean> insert(@RequestBody $!tableInfo.name $!entityName) {
return success(this.$!{serviceName}.save($!entityName));
}
/**
* 修改数据
*
* @param $!entityName 实体对象
* @return 修改结果
*/
@PutMapping
public R<Boolean> update(@RequestBody $!tableInfo.name $!entityName) {
return success(this.$!{serviceName}.updateById($!entityName));
}
/**
* 删除数据
*
* @param idList 主键结合
* @return 删除结果
*/
@DeleteMapping
public R<Boolean> delete(@RequestParam("idList") List<Long> idList) {
return success(this.$!{serviceName}.removeByIds(idList));
}
}
service
代码语言:javascript
复制##引入宏定义
$!{define.vm}
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Service"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/service"))
##使用宏定义设置包后缀
#setPackageSuffix("service")
import com.baomidou.mybatisplus.extension.service.IService;
import $!{tableInfo.savePackageName}.entity.$!tableInfo.name;
##表注释(宏定义)
#tableComment("表服务接口")
public interface $!{tableName} extends IService<$!tableInfo.name> {
}
serviceImpl
代码语言:javascript
复制##引入宏定义
$!{define.vm}
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "ServiceImpl"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/service/impl"))
##使用宏定义设置包后缀
#setPackageSuffix("service.impl")
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.stereotype.Service;
##表注释(宏定义)
#tableComment("表服务实现类")
@Service("$!tool.firstLowerCase($tableInfo.name)Service")
public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Mapper, $!{tableInfo.name}> implements $!{tableInfo.name}Service {
}
Mapper
代码语言:javascript
复制##引入宏定义
$!{define.vm}
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Mapper"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/mapper"))
##使用宏定义设置包后缀
#setPackageSuffix("mapper")
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import $!{tableInfo.savePackageName}.entity.$!tableInfo.name;
##表注释(宏定义)
#tableComment("表数据库访问层")
public interface $!{tableName} extends BaseMapper<$!tableInfo.name> {
}