我有以下课程
@Controller
@RequestMapping( "VIEW" )
@SessionAttributes( "application" )
public class EditApplicationController {
private static final Logger logger = LoggerFactory.getLogger( EditApplicationController.class );
private final ApplicationService applicationService;
@Autowired
public EditApplicationController( ApplicationService appServ ) {
this.applicationService = appServ;
}
@RenderMapping( params = "action=editApplicationForm" )
public String showEditApplication() {
return "editApplicationForm";
}
@ActionMapping( params = "action=editApplication" )
public void editApplication( @Valid ApplicationDTO application ) {
try {
this.applicationService.updateCmmiApplication( application );
} catch ( final ApplicationNotFound e ) {
logger.error( "No application exists with the given application id." );
}
}
@ModelAttribute( "application" )
public Application getApplication( @RequestParam long appId ) throws ApplicationNotFoundException {
final Application app = this.applicationService.findApplicationById( appId );
if ( app == null ) {
throw new ApplicationNotFoundException();
}
return app;
}
}
问题是当我处于Action阶段时,我不想要或需要检索ModelAttribute,因为我完全处理提交的表单对象。我可以使请求参数不是必需的并执行空检查,或者我可以添加一个新的控制器仅用于执行操作,但这些都感觉很笨拙。