我在Spring的申请中做了联系表格。我有一个问题:
字段名称上的对象接触中的字段错误:拒绝的值[null];代码[NotBlank.contact.name, NotBlank.name, NotBlank.java.lang.String, NotBlank];参数[org.springframework.context.support.DefaultMessageSourceResolable: code[contact.name, name];参数[];默认消息[名称]];默认消息[它不能是空的]字段消息上的对象“联系人”中的字段错误:拒绝的值[空];代码[NotBlank.contact.message,NotBlank.message,NotBlank.java.lang.字符串,NotBlank];参数[org.springframework.context.support.DefaultMessageSourceResolable:代码[contact.message,消息];参数[];默认消息[消息]];默认消息[它不能是空的]字段主题上的对象'接触'中的字段错误:拒绝值[null];代码[NotBlank.contact.subject, NotBlank.subject, NotBlank.java.lang.String, NotBlank];参数[org.springframework.context.support.DefaultMessageSourceResolable: code[contact.subject,主题];参数[];默认消息[主题];默认消息[它不能是空的]字段在对象'联系人'字段'phone'错误:拒绝值[null];代码[NotBlank.contact.phone, NotBlank.phone, NotBlank.java.lang.字符串, NotBlank];参数[org.springframework.context.support.DefaultMessageSourceResolable:代码[contact.phone, phone];参数[];默认消息[phone]];默认消息 [не может быть пусто] 字段'email'上的对象'接触'中的字段错误:拒绝的值[null];代码[NotBlank. contact. email, NotBlank. email, NotBlank. java. lang.String, NotBlank];参数[org. springframework. background. support.默认消息[它不能是空的]
控制器:
@Controller
public class ContactController {
@Autowired
MailComponent mailComponent;
@GetMapping("/contact")
public String contact(@ModelAttribute Contact contact) {
return "contact";
}
@PostMapping("/contact")
public String processContact(@Validated Contact contact, RedirectAttributes model, BindingResult bindingResult) {
if (bindingResult.hasErrors())
return "contact";
if (mailComponent.sendSimpleMail(contact)) {
model.addFlashAttribute("classCss", "alert sukcesu");
model.addFlashAttribute("message", "Twoja wiadomość została wysłana");
} else {
model.addFlashAttribute("classCss", "alert ostrzeżenie");
model.addFlashAttribute("message", "Wystąpił nieoczekiwany błąd, powtórz później");
}
return "redirect:/";
}
}
实体:
public class Contact {
@NotBlank
@Pattern(regexp = "[\\p{L} '-]+", message = "{com.diet4you.LapkoEkaterina.constraint.Name.message}")
private String name;
@NotBlank
@Pattern(regexp = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])",
message = "{com.diet4you.LapkoEkaterina.constraint.Email.message}")
private String email;
@NotBlank
@Pattern(regexp = "\\+(?:[0-9] ?){6,14}[0-9]", message = "{com.diet4you.LapkoEkaterina.constraint.Phone.message}")
private String phone;
@NotBlank
private String subject;
@NotBlank
private String message;
public Contact() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
验证属性:
javax.validation.constraints.AssertFalse.message = must be false
javax.validation.constraints.AssertTrue.message = must be true
javax.validation.constraints.DecimalMax.message = must be less than ${inclusive == true ? 'or equal to ' : ''}{value}
javax.validation.constraints.DecimalMin.message = must be greater than ${inclusive == true ? 'or equal to ' : ''}{value}
javax.validation.constraints.Digits.message = numeric value out of bounds (<{integer} digits>.<{fraction} digits> expected)
javax.validation.constraints.Future.message = must be in the future
javax.validation.constraints.Max.message = must be less than or equal to {value}
javax.validation.constraints.Min.message = must be greater than or equal to {value}
javax.validation.constraints.NotNull.message = may not be null
javax.validation.constraints.Null.message = must be null
javax.validation.constraints.Past.message = must be in the past
javax.validation.constraints.Pattern.message = must match "{regexp}"
javax.validation.constraints.Size.message = size must be between {min} and {max}
org.hibernate.validator.constraints.CreditCardNumber.message = invalid credit card number
org.hibernate.validator.constraints.EAN.message = invalid {type} barcode
org.hibernate.validator.constraints.Email.message = not a well-formed email address
org.hibernate.validator.constraints.Length.message = length must be between {min} and {max}
org.hibernate.validator.constraints.LuhnCheck.message = The check digit for ${validatedValue} is invalid, Luhn Modulo 10 checksum failed
org.hibernate.validator.constraints.Mod10Check.message = The check dihtml" target="_blank">git for ${validatedValue} is invalid, Modulo 10 checksum failed
org.hibernate.validator.constraints.Mod11Check.message = The check digit for ${validatedValue} is invalid, Modulo 11 checksum failed
org.hibernate.validator.constraints.ModCheck.message = The check digit for ${validatedValue} is invalid, ${modType} checksum failed
org.hibernate.validator.constraints.NotBlank.message = This field is required
org.hibernate.validator.constraints.NotEmpty.message = may not be empty
org.hibernate.validator.constraints.ParametersScriptAssert.message = script expression "{script}" didn't evaluate to true
org.hibernate.validator.constraints.Range.message = must be between {min} and {max}
org.hibernate.validator.constraints.SafeHtml.message = may have unsafe html content
org.hibernate.validator.constraints.ScriptAssert.message = script expression "{script}" didn't evaluate to true
org.hibernate.validator.constraints.URL.message = must be a valid URL
org.hibernate.validator.constraints.br.CNPJ.message = invalid Brazilian corporate taxpayer registry number (CNPJ)
org.hibernate.validator.constraints.br.CPF.message = invalid Brazilian individual taxpayer registry number (CPF)
org.hibernate.validator.constraints.br.TituloEleitoral.message = invalid Brazilian Voter ID card number
com.diet4you.LE.Name.message = Tylko litery
com.diet4you.LE.Email.message = Nie format e-mail
com.diet4you.LE.Phone.message = InNie format numeru
BindingResult需要紧跟在bean之后:
试着从
@PostMapping("/contact")
public String processContact(@Validated Contact contact, RedirectAttributes model, BindingResult bindingResult)
到
@PostMapping("/contact")
public String processContact(@Validated Contact contact, BindingResult bindingResult, RedirectAttributes model)
由于您已在实体类“联系人”中设置了字段名称、电子邮件、电话、主题、消息的验证,请检查您是否在表单中传递了所有这些值。如果没有按照实体类传递值,Spring将无法绑定在方法processContact中传递的Contact对象,并引发BeanPropertyBindingResult错误。
通用方法 (以下)管制员工作正常 另一个跟上面一样的控制器,但给出了一个例外 例外是 例外组织。springframework。刀。InvalidDataAccessApiUsageException:对象引用未保存的临时实例-在刷新之前保存临时实例:com。软的企业资源计划赞成的意见。模型ProPurchaseOrderModel;嵌套的异常是org。冬眠TransientObjectExcep
我收到了第三方的回复,如下所示 我们有课。 但是当我们转换时,我们会低于误差 错误com.openbet.commons.sdk.common.util.请求SenderImpl-在HTTP交换过程中意外的异常:org.springframework.http.converter.HttpMessageNotReadableExctive:JSON解析错误:无法反序列化的实例START_ARRAY
我正在将WebLogic Server 11g(10.3.6.0)升级到12c(12.2.1.3.0)。 我在12c服务器上没有问题地安装了war文件。然后,我尝试启动模块。由于缺少特定的类文件,我得到了错误。似乎该类文件属于“spring-aop-2.5.2.jar.” 当我在WebLogic Server 11g环境中部署相同的war文件时,我没有发现任何问题。我确保war文件中存在“spri
我使用hibernate-4.1.2和spring-framework-4.1.6中的所有jar文件来尝试hibernateTemplate问题中指定的项目。我正面临一个组织。springframework。刀。InvalidDataAccessApiUsageException 上面提到的错误堆栈建议将会话的刷新模式设置为COMMIT/AUTO或从事务定义中删除“readOnly”标记。有没有办
我尝试使用ldap-server,它是Microsoft Active Directory。这些“”具有以下结构: (超过1000个条目)和工人以下,有以下条目开始: 等等 我使用的框架是cuba studio。我必须申报以下财产: 但是,当我尝试使用它时,我得到了以下异常: 我还发现,例外应该是“无效凭据”的东西 https://confluence.atlassian.com/stashkb/
我得到以下错误消息,而运行我的项目 组织。springframework。豆。工厂UnsatisfiedPendencyException:创建名为“TipoeStatDoCivilController”的bean时出错:通过字段“TipoeStatDoCivilService”表示的未满足的依赖关系;嵌套的异常是org。springframework。豆。工厂UnsatisfiedPendenc