网站建设中出现的错误代码,广东建数网络科技有限公司,wordpress首行不缩进,史家小学网站建设1、报文入参尽量避免使用实体类#xff08;如果用实体类接受参数#xff0c;一定要写好注解#xff0c;具体用到了实体类的哪一个属性#xff09;
/*** * Description: 新增玉米观测记录主表信息* param param params* param return 参数* return Result 返回类型* author…1、报文入参尽量避免使用实体类如果用实体类接受参数一定要写好注解具体用到了实体类的哪一个属性
/*** * Description: 新增玉米观测记录主表信息* param param params* param return 参数* return Result 返回类型* author 魏振申* throws*/ApiOperation(value 玉米选定测产信息新增, notes 玉米选定测产信息新增接口)ApiResponses(value { ApiResponse(code 200, message 查询成功, responseContainer com.rhxt.util.Result),ApiResponse(code 650, message 参数缺失)})RequestMapping(value /insertMaizeRInfo, method RequestMethod.POST)public Result insertMaizeRInfo(ApiJsonObject(name insertMaizeRInfo, value {ApiJsonProperty(key userId, example 1, description 当前登录用户id , type string, required true),})RequestBody JSONObject params) {Result result new Result();MapString, Object dataMap new HashMap();if (JSONUtils.checkParams(params, userId, testCode, cropKind)) {String rowNum params.containsKey(rowNum)?params.getString(rowNum):null;String rowLength params.containsKey(rowLength)?params.getString(rowLength):null;String spikeNum params.containsKey(spikeNum)?params.getString(spikeNum):null;String plantNum params.containsKey(plantNum)?params.getString(plantNum):null;String doubleSpikeNum params.containsKey(doubleSpikeNum)?params.getString(doubleSpikeNum):null;String emptyRodNum params.containsKey(emptyRodNum)?params.getString(emptyRodNum):null;String downNum params.containsKey(downNum)?params.getString(downNum):null;String theoryYield params.containsKey(theoryYield)?params.getString(theoryYield):null;String actualYield params.containsKey(actualYield)?params.getString(actualYield):null;String quadratArea params.containsKey(quadratArea)?params.getString(quadratArea):null;String maizeRId params.containsKey(maizeRId)?params.getString(maizeRId):null;String userId params.getString(userId);String testCode params.getString(testCode);String cropKind params.getString(cropKind);int count iMaizeTestService.insertMaizeRInfo(rowNum, rowLength, spikeNum, plantNum, doubleSpikeNum, emptyRodNum, downNum, theoryYield, actualYield, quadratArea, userId, testCode, cropKind, maizeRId);switch (count) {case 0: case 2: case 3:result.setCode(ResponseEnum.OPERATION_ERROR.getCode());result.setMsg(ResponseEnum.OPERATION_ERROR.getMsg());break;case 1:result.setCode(ResponseEnum.OPERATION_SUCCESS.getCode());result.setMsg(ResponseEnum.OPERATION_SUCCESS.getMsg());dataMap iMaizeTestService.selectMaizeYieldInfo(testCode);break;default:break;}} else {result.setCode(ResponseEnum.PARAM_LOSE_EXCEPTION.getCode());result.setMsg(ResponseEnum.PARAM_LOSE_EXCEPTION.getMsg());}result.setObj(dataMap);return result;} 2、入参必填校验务必要做入参类型为map、JSONObject类型的我们均配置的有统一校验方法
JSONUtils.checkParams(params, userId, testCode, cropKind) 3、响应数据务必使用封装好的枚举类及对应的结果类
响应枚举类尽量放在controller层处理 4、修改数据配合前端失焦及延时保存传值应做到哪个发生变化修改哪个而不是每次全行修改 5、swagger注解务必添加并配备真实入参及描述信息 6、如使用RequestMapping注解需指定method类型 7、关键点增加日志记录及异常信息捕捉输出 8、service层方法入参应以具体的参数为主而非对象传参
所有的参数在controller层中接受成具体的属性之后传到service中 9、mybatis中sql关键字必须大写 10、删除无用引入包、无用变量、无用mapper方法
11、为了避免obj为null的现象应该这样写
查询 新增 修改删除这样写在setObj的时候把查询的列表数据放进去因为前端还要做列表刷新
/*** * Description: 新增玉米叶绿素含量记录* param param params* param return 参数* return Result 返回类型* author 魏振申* throws*/ApiOperation(value 新增玉米叶绿素含量记录, notes 新增玉米叶绿素含量记录)ApiResponses(value { ApiResponse(code 200, message 查询成功, responseContainer com.rhxt.util.Result),ApiResponse(code 650, message 参数缺失)})RequestMapping(value /insertChlorophyllInfo, method RequestMethod.POST)public Result insertChlorophyllInfo(ApiJsonObject(name insertChlorophyllInfo, value {ApiJsonProperty(key userId, example 1, description 当前登录用户id , type string, required true),})RequestBody JSONObject params) {Result result new Result();ListChlorophyllRPojo listData new ArrayList();if (JSONUtils.checkParams(params, userId, testCode, cropKind)) {String cropPhase params.containsKey(cropPhase)?params.getString(cropPhase):null;String chlorophyll params.containsKey(chlorophyll)?params.getString(chlorophyll):null;String chlId params.containsKey(chlId)?params.getString(chlId):null;String userId params.getString(userId);String testCode params.getString(testCode);String cropKind params.getString(cropKind);int count iMaizeTestService.insertChlorophyllInfo(cropPhase, chlorophyll, userId, testCode, cropKind, chlId);switch (count) {case 0:result.setCode(ResponseEnum.OPERATION_ERROR.getCode());result.setMsg(ResponseEnum.OPERATION_ERROR.getMsg());break;case 1:result.setCode(ResponseEnum.OPERATION_SUCCESS.getCode());result.setMsg(ResponseEnum.OPERATION_SUCCESS.getMsg());listData iMaizeTestService.selectChlorophyllInfo(testCode, cropKind);break;case 2:result.setCode(ResponseEnum.OPERATION_ERROR.getCode());result.setMsg(数据存储入库异常);break;case 3:result.setCode(ResponseEnum.OPERATION_ERROR.getCode());result.setMsg(数据转换异常);break;}} else {result.setCode(ResponseEnum.PARAM_LOSE_EXCEPTION.getCode());result.setMsg(ResponseEnum.PARAM_LOSE_EXCEPTION.getMsg());}result.setObj(listData);return result;} 12、批量的新增需要批量新增
这种需要处理成批量插入错误写法 正确示范
service
/*** description: 主阀关联批量添加分阀新增* author: 赵书正* date: 2023/3/27 17:28* param: [fCodes, zCode]* return: int**/Overridepublic int insertValveZF(String fCodes, String zCode) {int count 0;//先删除掉所有跟zCode关联的分阀门try {count valveZFMapper.deleteByZCode(zCode);} catch (Exception e) {log.info(删除掉所有跟zCode关联的分阀门出现异常异常位置ValveZFServiceImpl.deleteByZCode异常原因, e);}ListValveZFPojo list new ArrayList();if (G4Utils.isNotEmpty(fCodes)) {String[] fCodeArr fCodes.split(,);for (String fCode : fCodeArr) {ValveZFPojo valveZFPojo new ValveZFPojo();valveZFPojo.setId(G4Utils.getUUID());valveZFPojo.setzCode(zCode);valveZFPojo.setfCode(fCode);valveZFPojo.setCreateTime(G4Utils.getLocalDateTime(yyyy-MM-dd HH:mm:ss));list.add(valveZFPojo);}try {count valveZFMapper.insertValveZF(list);} catch (Exception e) {log.info(主阀关联批量添加分阀出现异常异常位置ValveZFServiceImpl.insertValveZF异常原因, e);}} else {count 1;}return count;}
xml
insert idinsertValveZF parameterTypecom.rhxt.platform.basic.pojo.ValveZFPojoinsert into VALVE_Z_F (ID, Z_CODE, F_CODE, CREATE_USE, CREATE_TIME)valuesforeach collectionlist indexindex itemitem separator,(#{item.id,jdbcTypeVARCHAR},#{item.zCode,jdbcTypeVARCHAR},#{item.fCode,jdbcTypeVARCHAR},#{item.createUse,jdbcTypeVARCHAR},#{item.createTime,jdbcTypeTIMESTAMP})/foreach/insert
13.批量删除也要做成批量的
错误写法改成批量的 正确写法
/*** description: 主阀关联批量添加分阀移除* author: 赵书正* date: 2023/3/27 17:29* param: [fCodeArr, zCode]* return: int**/Overridepublic int deleteValveZF(String[] fCodeArr, String zCode) {int count 0;try {count valveZFMapper.deleteValveZF(fCodeArr, zCode);} catch (Exception e) {log.info(主阀关联批量添加分阀出现异常异常位置ValveZFServiceImpl.deleteValveZF异常原因, e);}return count;}
xml
delete iddeleteValveZF parameterTypejava.lang.Stringdelete from VALVE_Z_Fwhere Z_CODE #{zCode,jdbcTypeVARCHAR} AND F_CODE in #{fCodeArr}/delete
14、无用的定义要去掉无用的定义浪费系统资源