私は次のクラスを持っています
@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.updateApplication( 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;
}
}
問題は、送信されたフォーム オブジェクトを完全に処理しているため、ModelAttribute を取得したくない、または取得する必要がないアクション フェーズにいるときです。リクエスト パラメータを不要にして null チェックを実行するか、アクションを実行するためだけに新しいコントローラを追加することもできますが、どちらも扱いにくいと感じます。