templates1.MvcFile.tmpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of coder-maven-plugin Show documentation
Show all versions of coder-maven-plugin Show documentation
Assist in generating CRUD code, without limitation on the specific language, as long as you can write velocity templates.
package ${packagePrefix}.controller;
import java.util.List;
import java.util.Map;
import com.github.pagehelper.PageInfo;
import com.kbao.core.common.exception.BusinessException;
import com.kbao.core.common.utils.EmptyUtils;
import com.kbao.core.common.utils.json.JsonHelper;
import com.kbao.core.common.utils.json.JsonReturnTemplate;
import com.kbao.core.common.web.controller.BaseController;
import com.kbao.core.common.web.page.RequestPage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import ${packagePrefix}.service.${className}Service;
import ${packagePrefix}.entity.${className};
/**
*
* @ClassName ${className}Controller
* @Description
* @author ${author}
* @version V1.0
* @since V1.0
* @date ${date}
*
*/
@RestController
@RequestMapping("/${module}/${subModule}/${classVar}")
public class ${className}Controller extends BaseController {
private static Logger logger = LoggerFactory.getLogger(${className}Controller.class.getName());
@Resource(name = "${classVar}Service")
private ${className}Service ${classVar}Service ;
/**
*
* @Description: 新增
* @since V1.0
* @param ${classVar}
*/
@RequestMapping(value = "/save" )
@ResponseBody
public Object save (@RequestBody @Valid ${className} ${classVar},BindingResult result){
//校验确认
checkValidator(result);
${classVar}Service.insert(${classVar} );
JsonReturnTemplate json = new JsonReturnTemplate(JsonReturnTemplate.RETURN_STATUS_SUCCESS);
//json.setData(${classVar});
return JsonHelper.obj2Json(json);
}
/**
*
* @Description: 删除
* @since V1.0
* @param ids
*/
@RequestMapping(value = "/delete" )
@ResponseBody
public Object delete (@RequestBody List ids){
//判断批量删除的数组是否为空
if(EmptyUtils.isEmpty(ids)){
throw new BusinessException("biz.sales.common.delete.param.empty");
}
${classVar}Service.batchDelete(ids);
JsonReturnTemplate json = new JsonReturnTemplate(JsonReturnTemplate.RETURN_STATUS_SUCCESS);
return json;
}
/**
*
* @Description: 修改
* @since V1.0
* @param ${classVar}
*/
@RequestMapping(value = "/update" )
@ResponseBody
public Object update(@RequestBody @Valid ${className} ${classVar},BindingResult result ) {
//校验确认
if (EmptyUtils.isEmpty(${classVar}.get${keyVar0} ()))
throw new BusinessException("biz.sales.common.id.notExist");
checkValidator(result);
${classVar}Service.updateByPrimaryKeySelective(${classVar} );
JsonReturnTemplate json = new JsonReturnTemplate(JsonReturnTemplate.RETURN_STATUS_SUCCESS);
//json.setData(${classVar});
return JsonHelper.obj2Json(json);
}
/**
*
* @Description: 查看
* @since V1.0
* @param queryParam
*/
@RequestMapping(value = "/findById" )
@ResponseBody
public Object findById(@RequestBody Map queryParam ) {
Long id = Long.valueOf(queryParam.get("id").toString());
${className} ${classVar} = ${classVar}Service.selectByPrimaryKey(id);
JsonReturnTemplate json = new JsonReturnTemplate(JsonReturnTemplate.RETURN_STATUS_SUCCESS);
json.setData(${classVar});
return JsonHelper.obj2Json(json);
}
/**
*
* @Description: 按某条件查询所有列表
* @since V1.0
* @param queryParam
*/
@RequestMapping(value = "/list" )
@ResponseBody
public Object list(@RequestBody Map queryParam ) {
List<${className}> ${classVar}s = ${classVar}Service.list(queryParam);
JsonReturnTemplate json = new JsonReturnTemplate(JsonReturnTemplate.RETURN_STATUS_SUCCESS);
json.setData( ${classVar}s);
return JsonHelper.obj2Json(json);
}
/**
*
* @Description: 按某条件查询分页查询
* @since V1.0
* @param param
*/
@RequestMapping("/page")
public Object page(@RequestBody RequestPage param) {
PageInfo<${className}> pageInfo = ${classVar}Service.page(param);
JsonReturnTemplate result = new JsonReturnTemplate(JsonReturnTemplate.RETURN_STATUS_SUCCESS);
result.setData(pageInfo);
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy