controller.java.ftl 2.8 KB
package ${package.Controller};


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.hotent.base.model.CommonResult;
import com.hotent.base.util.StringUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};

/**
 * ${table.comment!} 前端控制器
 *
 <#if cfg.companyName??>
 * @company ${cfg.companyName}
 </#if>
 * @author ${author}
 <#if cfg.authorEmail??>
 * @email ${cfg.authorEmail}
 </#if>
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>/v1/")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass}<${table.serviceName}, ${entity}> {
<#else>
public class ${table.controllerName} {
</#if>

<#if cfg.type != "querySqldef">
	/**
	 * 根据id获取${table.comment!}数据详情
	 * @param id
	 * @return
	 * @throws Exception 
	 * ModelAndView
	 */
	@GetMapping(value="/getDetail")
	@ApiOperation(value="根据id获取${table.comment!}数据详情",httpMethod = "GET",notes = "根据id获取${table.comment!}数据详情")
	public CommonResult<${entity}> getDetail(@ApiParam(name="id",value="业务对象主键", required = true)@RequestParam(required=true) String id) throws Exception{
		return CommonResult.<${entity}>ok().value(baseService.getDetail(id));
	}
    /**
	 * 新增,更新${table.comment!}
	 * @param ${entity?uncap_first}
	 * @throws Exception 
	 * @return
	 * @exception 
	 */
	@PostMapping(value="/save")
	@ApiOperation(value = "新增,更新${table.comment!}数据", httpMethod = "POST", notes = "新增,更新${table.comment!}数据")
	public CommonResult<String> save(@ApiParam(name="${entity}",value="${table.comment!}对象", required = true)@RequestBody ${entity} ${entity?uncap_first}) throws Exception{
		String msg = StringUtil.isEmpty(${entity?uncap_first}.getId()) ? "添加${table.comment!}成功" : "更新${table.comment!}成功";
		baseService.createOrUpdate(${entity?uncap_first});
		return CommonResult.<String>ok().message(msg);
	}
</#if>
}
</#if>