1 背景
基于springboot,mybatisplus 的web开发的idea文件模板,包括controller,service,dao,entity等。包含了基本的增删改查操作。
2 Controller
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
/**
*@Description
*@auther ${USER}
*@create ${YEAR}-${MONTH}-${DAY} ${TIME}
*/
@Slf4j
@RequestMapping("/${smallName}")
@RestController
public class ${ClassName}Controller {
@Resource
${ClassName}Service ${smallName}Service;
@CrossOrigin
@RequestMapping(value="/list", method = RequestMethod.POST)
public Object getList(@RequestBody ${ClassName}PageReq ${smallName}PageReq) throws Exception{
if(${smallName}PageReq.getCurrentPage()!=null&&${smallName}PageReq.getPageSize()!=null) {
IPage<${ClassName}VO> ${smallName}VOIPage = ${smallName}Service.select${ClassName}Page(${smallName}PageReq);
return Response.getSuccessResult(${smallName}VOIPage);
}
else{
List<${ClassName}VO> ${smallName}VOList = ${smallName}Service.select${ClassName}List(${smallName}PageReq);
return Response.getSuccessResult(${smallName}VOList);
}
}
@CrossOrigin
@RequestMapping(value="/update", method = RequestMethod.PUT)
public Response<String> update(@RequestBody ${ClassName}VO ${smallName}VO, HttpServletRequest request){
${smallName}VO.setOperator(CommonUtils.getCurrentUserName(request));
boolean result = ${smallName}Service.update(${smallName}VO);
if(result) {
log.info("update ${smallName} successful,${smallName}Id:{} change to {}",${smallName}VO.getId(),${smallName}VO);
return Response.getSuccessResult("update ${smallName} successful");
}
else {
log.warn("update ${smallName} failed,${smallName}Id:{}",${smallName}VO.getId());
return Response.getFailResult(CodeEnum.ERR_SYSTEM, "update ${smallName} failed ");
}
}
@CrossOrigin
@RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
public Response<String> deleteByid(@PathVariable long id, HttpServletRequest request){
if(id<=0){
return Response.getFailResult(CodeEnum.ERR_CLIENT,"参数id异常");
}