表单很多数据项录入的时候,提交controller发生异常,数据回显。

1.添加的情况(Model传递Form Data)

request.getSession().setAttribute("car", car);  //抛出异常的时候,数据回显。


2.修改的情况(Model传递Form Data)

Car car2 = carService.detailAll(car.getRegNo());

        try {

            BeanUtils.copyProperties(car2, car);

        } catch (IllegalAccessException e) {

            ec = ErrorCode.SYS_ERROR;

            logger.error("系统错误!", e);

        } catch (InvocationTargetException e) {

            ec = ErrorCode.SYS_ERROR;

            logger.error("系统错误!", e);

        }  //新旧值转换

request.setAttribute("car", car2);

BeanUtils.copyProperties(car2, car);

 

3.修改的情况(Map传递Form Data)

Map<String,Object> map = carService.detail(Integer.valueOf(carNo));

map.putAll(data);  //查询的结果 与 新填写的值data,key值相同的被data替换。

request.setAttribute("car", map);

你可能感兴趣的:(controller)