私は非常にシンプルな分類をしています。フォームデータを表すBeanで構成されています。私は長い価値のあるフィールドを持っています。 jspで私はこれを書く:<form:hidden path="id"/>
。フォームを送信すると、HTTPステータス400エラーが表示されます。spring mvc form bean文字列から文字列への変換
短い値で提出すると、mvcはフォームオブジェクトを構築するためにlongに変換できません。
フローは単純です:ユーザはe社で編集をクリックします。サービスを介してコントローラが会社を取得し、次にビューがレンダリングされ、最終的にユーザーが変更をサブミットします。しかし、長い値がサブミットされたときにエラーが発生しました。
デバッグ情報は、この私に語った:ここ
DefaultHandlerExceptionResolver [DEBUG] Resolving exception from handler [public java.lang.String ar.com.held.controller.CompanyController.edit(java.lang.Long,org.springframework.ui.Model)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "save"
コードは次のとおりです。
私のフォームBean:
public class CompanyForm {
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@NotBlank
private String name;
@NotBlank
private String addressStreet;
@NotBlank
private String addressCity;
@NotBlank
private String addressState;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddressStreet() {
return addressStreet;
}
public void setAddressStreet(String addressStreet) {
this.addressStreet = addressStreet;
}
public String getAddressCity() {
return addressCity;
}
public void setAddressCity(String addressCity) {
this.addressCity = addressCity;
}
public String getAddressState() {
return addressState;
}
public void setAddressState(String addressState) {
this.addressState = addressState;
}
}
私のコントローラ:
@RequestMapping(value={"edit/{companyId}"})
public String edit(@PathVariable Long companyId, Model model){
CompanyForm form = new CompanyForm();
if(companyId!=null){
Company company = companyService.find(companyId);
if(company!=null)
modelMapper.map(company, form);
}
model.addAttribute("form", form);
return "company/edit";
}
@RequestMapping(value={"new"})
public String edit(Model model){
return this.edit(null, model);
}
@RequestMapping(value="save", method={RequestMethod.POST})
public String save(@ModelAttribute("form") @Valid CompanyForm companyForm, BindingResult result){
if(result.hasErrors())
return "company/edit";
Company company;
if(companyForm.getId()!=null)
company = companyService.find(companyForm.getId());
else
company = new Company();
modelMapper.map(companyForm, company);
companyService.save(company, getLoggedUser());
return "redirect:list";
}
私のjsp :
<form:form method="post" action="save" modelAttribute="form" cssClass="form-horizontal" >
<fieldset>
<form:hidden path="id"/>
++++ others fields +++
<div class="form-actions">
<input type="submit" value="Guardar" class="btn btn-primary btn-large"/>
</div>
</fieldset>
</form:form>
デバッグ情報
2012-02-17 18:17:45 AntPathRequestMatcher [DEBUG] Checking match of request : '/companies/edit/save'; against '/resources/**'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 1 of 10 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
2012-02-17 18:17:45 HttpSessionSecurityContextRepository [DEBUG] Obtained a valid SecurityContext from SPRING_SECURITY_CONTEXT: '[email protected]c22d3c: Authentication: org.springframew[email protected]bcc22d3c: Principal: [email protected]; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]166c8: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 93B19E8B81EBB7F4BFEECF4FFFC46593; Granted Authorities: COMPANY_OWNER'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 2 of 10 in additional filter chain; firing Filter: 'LogoutFilter'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 3 of 10 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 4 of 10 in additional filter chain; firing Filter: 'DefaultLoginPageGeneratingFilter'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 5 of 10 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 6 of 10 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 7 of 10 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
2012-02-17 18:17:45 AnonymousAuthenticationFilter [DEBUG] SecurityContextHolder not populated with anonymous token, as it already contained: 'org.springframew[email protected]bcc22d3c: Principal: [email protected]; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]166c8: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 93B19E8B81EBB7F4BFEECF4FFFC46593; Granted Authorities: COMPANY_OWNER'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 8 of 10 in additional filter chain; firing Filter: 'SessionManagementFilter'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 9 of 10 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save at position 10 of 10 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
2012-02-17 18:17:45 AntPathRequestMatcher [DEBUG] Checking match of request : '/companies/edit/save'; against '/companies/*'
2012-02-17 18:17:45 FilterSecurityInterceptor [DEBUG] Public object - authentication not attempted
2012-02-17 18:17:45 FilterChainProxy [DEBUG] /companies/edit/save reached end of additional filter chain; proceeding with original chain
2012-02-17 18:17:45 DispatcherServlet [DEBUG] DispatcherServlet with name 'spring' processing POST request for [/Held/companies/edit/save]
2012-02-17 18:17:45 RequestMappingHandlerMapping [DEBUG] Looking up handler method for path /companies/edit/save
2012-02-17 18:17:45 RequestMappingHandlerMapping [DEBUG] Returning handler method [public java.lang.String ar.com.held.controller.CompanyController.edit(java.lang.Long,org.springframework.ui.Model)]
2012-02-17 18:17:45 DefaultListableBeanFactory [DEBUG] Returning cached instance of singleton bean 'companyController'
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:17:45 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:17:45 ExceptionHandlerExceptionResolver [DEBUG] Resolving exception from handler [public java.lang.String ar.com.held.controller.CompanyController.edit(java.lang.Long,org.springframework.ui.Model)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "save"
2012-02-17 18:17:45 ResponseStatusExceptionResolver [DEBUG] Resolving exception from handler [public java.lang.String ar.com.held.controller.CompanyController.edit(java.lang.Long,org.springframework.ui.Model)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "save"
2012-02-17 18:17:45 DefaultHandlerExceptionResolver [DEBUG] Resolving exception from handler [public java.lang.String ar.com.held.controller.CompanyController.edit(java.lang.Long,org.springframework.ui.Model)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "save"
2012-02-17 18:17:45 DispatcherServlet [DEBUG] Null ModelAndView returned to DispatcherServlet with name 'spring': assuming HandlerAdapter completed request handling
2012-02-17 18:17:45 DispatcherServlet [DEBUG] Successfully completed request
2012-02-17 18:17:45 ExceptionTranslationFilter [DEBUG] Chain processed normally
2012-02-17 18:17:45 SecurityContextPersistenceFilter [DEBUG] SecurityContextHolder now cleared, as request processing completed
2012-02-17 18:26:56 AntPathRequestMatcher [DEBUG] Checking match of request : '/companies/edit/save'; against '/resources/**'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 1 of 10 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
2012-02-17 18:26:56 HttpSessionSecurityContextRepository [DEBUG] Obtained a valid SecurityContext from SPRING_SECURITY_CONTEXT: '[email protected]c22d3c: Authentication: org.springframew[email protected]bcc22d3c: Principal: [email protected]; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]166c8: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 93B19E8B81EBB7F4BFEECF4FFFC46593; Granted Authorities: COMPANY_OWNER'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 2 of 10 in additional filter chain; firing Filter: 'LogoutFilter'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 3 of 10 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 4 of 10 in additional filter chain; firing Filter: 'DefaultLoginPageGeneratingFilter'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 5 of 10 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 6 of 10 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 7 of 10 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
2012-02-17 18:26:56 AnonymousAuthenticationFilter [DEBUG] SecurityContextHolder not populated with anonymous token, as it already contained: 'org.springframew[email protected]bcc22d3c: Principal: [email protected]; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]166c8: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 93B19E8B81EBB7F4BFEECF4FFFC46593; Granted Authorities: COMPANY_OWNER'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 8 of 10 in additional filter chain; firing Filter: 'SessionManagementFilter'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 9 of 10 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save at position 10 of 10 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
2012-02-17 18:26:56 AntPathRequestMatcher [DEBUG] Checking match of request : '/companies/edit/save'; against '/companies/*'
2012-02-17 18:26:56 FilterSecurityInterceptor [DEBUG] Public object - authentication not attempted
2012-02-17 18:26:56 FilterChainProxy [DEBUG] /companies/edit/save reached end of additional filter chain; proceeding with original chain
2012-02-17 18:26:56 DispatcherServlet [DEBUG] DispatcherServlet with name 'spring' processing POST request for [/Held/companies/edit/save]
2012-02-17 18:26:56 RequestMappingHandlerMapping [DEBUG] Looking up handler method for path /companies/edit/save
2012-02-17 18:26:56 RequestMappingHandlerMapping [DEBUG] Returning handler method [public java.lang.String ar.com.held.controller.CompanyController.edit(java.lang.Long,org.springframework.ui.Model)]
2012-02-17 18:26:56 DefaultListableBeanFactory [DEBUG] Returning cached instance of singleton bean 'companyController'
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initializing new StandardEnvironment
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemProperties] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Adding [systemEnvironment] PropertySource with lowest search precedence
2012-02-17 18:26:56 StandardEnvironment [DEBUG] Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
2012-02-17 18:26:56 ExceptionHandlerExceptionResolver [DEBUG] Resolving exception from handler [public java.lang.String ar.com.held.controller.CompanyController.edit(java.lang.Long,org.springframework.ui.Model)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "save"
2012-02-17 18:26:56 ResponseStatusExceptionResolver [DEBUG] Resolving exception from handler [public java.lang.String ar.com.held.controller.CompanyController.edit(java.lang.Long,org.springframework.ui.Model)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "save"
2012-02-17 18:26:56 DefaultHandlerExceptionResolver [DEBUG] Resolving exception from handler [public java.lang.String ar.com.held.controller.CompanyController.edit(java.lang.Long,org.springframework.ui.Model)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "save"
2012-02-17 18:26:56 DispatcherServlet [DEBUG] Null ModelAndView returned to DispatcherServlet with name 'spring': assuming HandlerAdapter completed request handling
2012-02-17 18:26:56 DispatcherServlet [DEBUG] Successfully completed request
2012-02-17 18:26:56 ExceptionTranslationFilter [DEBUG] Chain processed normally
2012-02-17 18:26:56 SecurityContextPersistenceFilter [DEBUG] SecurityContextHolder now cleared, as request processing completed