复写平台基础增删改查方法
根据业务不同需要做后台业务处理,平台默认的方法满足不了需求,我们就需要复写平台相关方法,已达到我们的需求
新增
/**
* 重写保存方法
*
* @param param
*/
@RequestMapping(value = "/doSave", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
@ResponseBody
@Override
public BaseRespResult doSave(MethodArgument param) {
try {
return BaseRespResult.successResult(demoService.doSave(param).getValues());
} catch (PlatformException e) {
throw e;
} catch (Exception e) {
throw new PlatformException("数据保存失败!", PlatformExceptionEnum.UNKOWN_ERROR, e);
}
}
删除
/**
* 重写删除方法(真实删除)
*
* @param param
*/
@RequestMapping(value = "/doRemove", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
@ResponseBody
@Override
public BaseRespResult doRemove(MethodArgument param) {
try {
int i = manager.doRemove(param);
return BaseRespResult.successResult(String.format("%s 条记录被删除", i));
} catch (PlatformException e) {
throw e;
} catch (Exception e) {
throw new PlatformException("数据删除失败!", PlatformExceptionEnum.UNKOWN_ERROR, e);
}
}
修改
/**
* 重写修改方法
*
* @param param 请求参数封装对象
*/
@RequestMapping(value = "/doUpdate", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
@ResponseBody
@Override
public BaseRespResult doUpdate(MethodArgument param) {
try {
return BaseRespResult.successResult(manager.doUpdate(param).getValues());
} catch (PlatformException e) {
throw e;
} catch (Exception e) {
throw new PlatformException("数据修改失败!", PlatformExceptionEnum.UNKOWN_ERROR, e);
}
}
根据主键查询
/**
* 根据主键获取
*
* @param param 请求参数封装对象
*/
@RequestMapping(value = "/getInfoById", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
@ResponseBody
@Override
public Map getInfoById(MethodArgument param) {
try {
DynaBean infoById = manager.getInfoById(param);
if (infoById == null) {
return new HashMap<>();
}
return infoById.getValues();
} catch (PlatformException e) {
throw e;
} catch (Exception e) {
throw new PlatformException("数据加载失败!", PlatformExceptionEnum.UNKOWN_ERROR, e);
}
}
查询
/**
* 默认的列表读取
*
* @param param 请求参数封装对象
*/
@RequestMapping(value = "/load", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
@ResponseBody
@Override
public void load(MethodArgument param) {
try {
Page page = manager.load(param);
toWrite(BaseRespResult.successResultPage(Lists.newArrayList(), 0L), param);
} catch (PlatformException e) {
throw e;
} catch (Exception e) {
throw new PlatformException("数据加载失败!", PlatformExceptionEnum.UNKOWN_ERROR, e);
}
}
注意
1、重写父类 AbstractPlatformController
的增删改查方法,在原来封装的方法上加需要的业务逻辑
@Controller
@RequestMapping(value = "/je/demoDyna")
public class DemoDynaBeanController extends AbstractPlatformController {
@Autowired
private DemoService demoService;
}
2、新建的controller请求路径“/je/demoDyna”要与功能配置里面Action项
对应,增删改查方法页面不做操作,后台只需继承 AbstractPlatformController
重写父类方法即可。
3、基本的五个方法:load,doSave,doUpdate,doRemove,getInfoById
关键字,相关问题
- 复写平台方法
- 二次开发
最后编辑: 呼丽华 文档更新时间: 2024-08-21 10:58 作者:呼丽华