代码生成器
parent
51dc2cb9d7
commit
00f85c8dc9
@ -0,0 +1,85 @@
|
|||||||
|
package ${package.Controller};
|
||||||
|
|
||||||
|
import ${package.Entity}.${entity};
|
||||||
|
import ${package.Service}.${table.serviceName};
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
<#--import org.apache.shiro.authz.annotation.Logical;-->
|
||||||
|
<#--import org.apache.shiro.authz.annotation.RequiresPermissions;-->
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
<#--import com.common.res.DataResult;-->
|
||||||
|
<#if restControllerStyle>
|
||||||
|
<#else>
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
</#if>
|
||||||
|
<#if superControllerClassPackage??>
|
||||||
|
import ${superControllerClassPackage};
|
||||||
|
</#if>
|
||||||
|
/**
|
||||||
|
* @author ${author}
|
||||||
|
* @since ${date}
|
||||||
|
*/
|
||||||
|
<#if restControllerStyle>
|
||||||
|
@RestController
|
||||||
|
<#else>
|
||||||
|
@Controller
|
||||||
|
</#if>
|
||||||
|
@RequestMapping("/<#if controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
|
||||||
|
<#if kotlin>
|
||||||
|
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
|
||||||
|
<#else>
|
||||||
|
<#if superControllerClass??>
|
||||||
|
public class ${table.controllerName} extends ${superControllerClass} {
|
||||||
|
<#else>
|
||||||
|
public class ${table.controllerName} {
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ${table.serviceName} ${table.serviceName?uncap_first};
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/selectOne")
|
||||||
|
<#-- @RequiresPermissions("sys:${table.entityName?uncap_first}:list")-->
|
||||||
|
@ApiOperation("${table.entityName}查询单个")
|
||||||
|
public ${table.entityName} get${table.entityName}(@RequestParam("id") Integer id){
|
||||||
|
${table.entityName} ${table.entityName?uncap_first}One = ${table.entityName?uncap_first}Service.get${table.entityName}( id);
|
||||||
|
return ${table.entityName?uncap_first}One;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/listAll")
|
||||||
|
<#-- @RequiresPermissions("sys:${table.entityName?uncap_first}:list")-->
|
||||||
|
@ApiOperation("${table.entityName}查询全部")
|
||||||
|
public List<${table.entityName}> getAll${table.entityName}(){
|
||||||
|
List<${table.entityName}> ${table.entityName?uncap_first}List = ${table.entityName?uncap_first}Service.getAll${table.entityName}();
|
||||||
|
return ${table.entityName?uncap_first}List;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/add")
|
||||||
|
<#-- @RequiresPermissions("sys:${table.entityName?uncap_first}:add")-->
|
||||||
|
@ApiOperation("${table.entityName}新增")
|
||||||
|
public Object add(@Valid @RequestBody ${table.entityName} ${table.entityName?uncap_first}) {
|
||||||
|
${table.entityName?uncap_first}Service.add( ${table.entityName?uncap_first});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update")
|
||||||
|
<#-- @RequiresPermissions("sys:${table.entityName?uncap_first}:update")-->
|
||||||
|
@ApiOperation("${table.entityName}修改")
|
||||||
|
public int update(@Valid @RequestBody ${table.entityName} ${table.entityName?uncap_first}) {
|
||||||
|
int num = ${table.entityName?uncap_first}Service.modify( ${table.entityName?uncap_first});
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@DeleteMapping(value = "/delete/{ids}")
|
||||||
|
<#-- @RequiresPermissions("sys:${table.entityName?uncap_first}:delete")-->
|
||||||
|
@ApiOperation("${table.entityName}删除(单个条目)")
|
||||||
|
public Object remove(@NotBlank(message = "{required}") @PathVariable String ids) {
|
||||||
|
${table.entityName?uncap_first}Service.remove(ids);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</#if>
|
@ -0,0 +1,53 @@
|
|||||||
|
package ${package.Service};
|
||||||
|
|
||||||
|
import ${package.Entity}.${entity};
|
||||||
|
import ${superServiceClassPackage};
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ${author}
|
||||||
|
* @since ${date}
|
||||||
|
*/
|
||||||
|
<#if kotlin>
|
||||||
|
interface ${table.serviceName} : ${superServiceClass}<${entity}>
|
||||||
|
<#else>
|
||||||
|
public interface ${table.serviceName} extends ${superServiceClass}<${entity}> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${table.entityName!}详情
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
${table.entityName} get${table.entityName}( Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${table.entityName!}详情
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<${table.entityName}> getAll${table.entityName}();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${table.entityName!}新增
|
||||||
|
* @param ${table.entityName?uncap_first} 根据需要进行传值
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void add(${entity} ${table.entityName?uncap_first});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${table.entityName!}修改
|
||||||
|
* @param ${table.entityName?uncap_first} 根据需要进行传值
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int modify(${entity} ${table.entityName?uncap_first});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${table.entityName!}删除
|
||||||
|
* @param ids
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void remove(String ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
</#if>
|
||||||
|
|
@ -0,0 +1,69 @@
|
|||||||
|
package ${package.ServiceImpl};
|
||||||
|
|
||||||
|
import ${package.Entity}.${entity};
|
||||||
|
import ${package.Mapper}.${table.mapperName};
|
||||||
|
import ${package.Service}.${table.serviceName};
|
||||||
|
import ${superServiceImplClassPackage};
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Arrays;
|
||||||
|
/**
|
||||||
|
* ${table.comment!} 服务实现类
|
||||||
|
*
|
||||||
|
* @author ${author}
|
||||||
|
* @since ${date}
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
<#if kotlin>
|
||||||
|
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {
|
||||||
|
|
||||||
|
}
|
||||||
|
<#else>
|
||||||
|
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
${table.entityName}Mapper ${table.entityName?uncap_first}Mapper;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ${table.entityName} get${table.entityName}(Integer id){
|
||||||
|
|
||||||
|
return ${table.entityName?uncap_first}Mapper.selectById(id);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public List<${table.entityName}> getAll${table.entityName}(){
|
||||||
|
return ${table.entityName?uncap_first}Mapper.selectList(null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add( ${table.entityName} ${table.entityName?uncap_first}) {
|
||||||
|
${table.entityName?uncap_first}Mapper.insert(${table.entityName?uncap_first});
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public int modify( ${table.entityName} ${table.entityName?uncap_first}) {
|
||||||
|
//乐观锁更新
|
||||||
|
${table.entityName} current${table.entityName}= ${table.entityName?uncap_first}Mapper.selectById(${table.entityName?uncap_first}.getId());
|
||||||
|
${table.entityName?uncap_first}.setVersion(current${table.entityName}.getVersion());
|
||||||
|
return ${table.entityName?uncap_first}Mapper.updateById(${table.entityName?uncap_first});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove( String ids) {
|
||||||
|
|
||||||
|
if(StringUtils.isNotEmpty(ids)){
|
||||||
|
String[] array = ids.split(",");
|
||||||
|
if (!CollectionUtils.isEmpty(Arrays.asList(array))) {
|
||||||
|
${table.entityName?uncap_first}Mapper.deleteBatchIds(Arrays.asList(array));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
</#if>
|
Loading…
Reference in New Issue