La requête envoyée par le client est syntaxiquement incorrect.-Spring MVC + JDBC Modèle
Je suis novice de Spring MVC.
J'ai été bloqué par une erreur lors de l'exécution de mon projet
Erreur de La requête envoyée par le client est syntaxiquement incorrect.
J'ai une classe d'entité PatientInfo.
Ma page jsp est demo1.
Mon contrôleur est Patient Contrôleur.
La fonctionnalité que je veux mettre en œuvre est l'Insertion de valeurs dans la base de données.
Mais je ne suis pas en mesure d'appeler ma fonction(add-update2) dans le contrôleur.
demo1.jsp
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<html>
<head>
<title>Registration Form</title>
</head>
<body>
<h2 align="center">Full Registration Form</h2>
<hr />
<table align="center" cellpadding="5" cellspacing="5">
<form:form modelAttribute="patientInfo" method="POST" action="add-update2">
<tr>
<td> First Name</td>
<td><form:input path="firstName"/></td>
</tr>
<tr>
<td>Middle Name</td>
<td><form:input path="middleName" /></td>
</tr>
<tr>
<td>Last Name</td>
<td><form:input path="lastName"/>
</td>
</tr>
<tr>
<td>Age</td>
<td><form:input path="age" /></td>
</tr>
<tr>
<td>Gender</td>
<td><form:select path="gender">
<form:option value="" label="Select Gender" />
<form:options items="${genderList}" itemLabel="gender" itemValue="gender" />
</form:select></td>
</tr>
<tr>
<td>Marital Status</td>
<td><form:select path="maritalStatus">
<form:option value="" label="Select Marital Status" />
<form:options items="${maritalList}" itemLabel="maritalstatus" itemValue="maritalstatus" />
</form:select></td>
</tr>
<tr>
<td>Nationality</td>
<td><form:select path="nationality">
<form:option value="" label="Select Nationality" />
<form:options items="${nationalityList}" itemLabel="country" itemValue="country" />
</form:select></td>
</tr>
<tr name="tstest">
<td>Date Of Birth</td>
<td><form:input path="dateOfBirth" name="timestamp" value=""/>
<a href="javascript:show_calendar('document.tstest.timestamp', document.tstest.timestamp.value);"><img src="../images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the timestamp"></a>
</td>
</tr>
<tr>
<td>E-mail</td>
<td><form:input path="email"/></td>
</tr>
<tr>
<td>Blood Group</td>
<td><form:select path="bloodGroup">
<form:option value="" label="Select Blood Group" />
<form:options items="${bloodList}" itemLabel="bloodgroupname" itemValue="bloodgroupname" />
</form:select></td>
</tr>
<tr>
<td><input type="submit" value="submit"/></td>
</tr>
</form:form>
</table>
</body>
</html>
Controller-PatientController.java
package com.app.ehr.api;
import com.app.ehr.domain.Bloodgroup;
import com.app.ehr.domain.Gendertype;
import com.app.ehr.entities.Patientinfo;
import com.app.ehr.domain.Maritalstatus;
import com.app.ehr.domain.Nationality;
import com.app.ehr.model.Patient;
import com.app.ehr.service.PatientService;
import org.springframework.stereotype.Controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class PatientController {
public PatientService patientService;
@Autowired
public PatientController(PatientService patientService){
this.patientService = patientService;
}
@RequestMapping(value="/", method= RequestMethod.GET)
public String index(ModelMap map) {
return "index";
}
@RequestMapping(value="/full-reg", method= RequestMethod.GET)
public String fullreg(ModelMap map,Patientinfo patientInfo) {
List<Bloodgroup> bloodList = new ArrayList<Bloodgroup>();
List<Gendertype> genderList = new ArrayList<Gendertype>();
List<Nationality> nationalityList = new ArrayList<Nationality>();
List<Maritalstatus> maritalList = new ArrayList<Maritalstatus>();
bloodList=patientService.getAllBloodgroup();
genderList= patientService.getAllGendertype();
nationalityList=patientService.getAllNationality();
maritalList=patientService.getAllMaritalstatus();
for(int i=0;i<bloodList.size();i++)
{
System.out.println("---------------------Controller"+bloodList.get(i));
}
//map.addAttribute("hello", "Hello Spring from Netbeans!!");
map.addAttribute("patientInfo", patientInfo);
map.addAttribute("bloodList", patientService.getAllBloodgroup());
map.addAttribute("genderList", patientService.getAllGendertype());
map.addAttribute("maritalList", patientService.getAllMaritalstatus());
map.addAttribute("nationalityList", patientService.getAllNationality());
return "demo1";
}
@RequestMapping(value="/add-update2", method= RequestMethod.POST)
public String addUpdate(@ModelAttribute("patientInfo") Patientinfo patientInfo) {
System.out.println("----------------------------------------- From Controller------------------------------------------------");
//patientService.addPatient(patientInfo);
return "redirect:/full-reg";
}
}
Classe D'Entité - PatientInfo.java
package com.app.ehr.entities;
import java.io.Serializable;
import java.math.BigInteger;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
*
* @author HP LAPTOP
*/
@Entity
@Table(name = "patientinfo")
@NamedQueries({
@NamedQuery(name = "Patientinfo.findAll", query = "SELECT p FROM Patientinfo p")})
public class Patientinfo implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "PatientKey")
private Long patientKey;
@Column(name = "PatientMRNumber")
private String patientMRNumber;
@Column(name = "IntPrimaryPhysicianKey")
private BigInteger intPrimaryPhysicianKey;
@Column(name = "FirstName")
private String firstName;
@Column(name = "MiddleName")
private String middleName;
@Column(name = "LastName")
private String lastName;
@Column(name = "Age")
private Short age;
@Column(name = "Gender")
private String gender;
@Column(name = "Nationality")
private String nationality;
@Column(name = "DateOfBirth")
@Temporal(TemporalType.TIMESTAMP)
private Date dateOfBirth;
@Column(name = "MaritalStatus")
private String maritalStatus;
@Column(name = "Occupation")
private String occupation;
@Column(name = "AnnualIncome")
private String annualIncome;
@Column(name = "BloodGroup")
private String bloodGroup;
@Column(name = "Email")
private String email;
@Column(name = "ModeOfPayment")
private String modeOfPayment;
@Column(name = "ModeOfPaymentAlt")
private String modeOfPaymentAlt;
@Column(name = "ExtPrimaryPhysicianName")
private String extPrimaryPhysicianName;
@Column(name = "ExtPrimaryPhysicianPhoneNumber")
private String extPrimaryPhysicianPhoneNumber;
@Column(name = "IsDeleted")
private Boolean isDeleted;
@Column(name = "Meta_CreatedByUser")
private String metaCreatedByUser;
@Column(name = "Meta_UpdatedDT")
@Temporal(TemporalType.TIMESTAMP)
private Date metaUpdatedDT;
@Column(name = "Meta_CreatedDT")
@Temporal(TemporalType.TIMESTAMP)
private Date metaCreatedDT;
public Patientinfo() {
}
public Patientinfo(Long patientKey) {
this.patientKey = patientKey;
}
public Long getPatientKey() {
return patientKey;
}
public void setPatientKey(Long patientKey) {
this.patientKey = patientKey;
}
public String getPatientMRNumber() {
return patientMRNumber;
}
public void setPatientMRNumber(String patientMRNumber) {
this.patientMRNumber = patientMRNumber;
}
public BigInteger getIntPrimaryPhysicianKey() {
return intPrimaryPhysicianKey;
}
public void setIntPrimaryPhysicianKey(BigInteger intPrimaryPhysicianKey) {
this.intPrimaryPhysicianKey = intPrimaryPhysicianKey;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getMiddleName() {
return middleName;
}
public void setMiddleName(String middleName) {
this.middleName = middleName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Short getAge() {
return age;
}
public void setAge(Short age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getNationality() {
return nationality;
}
public void setNationality(String nationality) {
this.nationality = nationality;
}
public Date getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public String getMaritalStatus() {
return maritalStatus;
}
public void setMaritalStatus(String maritalStatus) {
this.maritalStatus = maritalStatus;
}
public String getOccupation() {
return occupation;
}
public void setOccupation(String occupation) {
this.occupation = occupation;
}
public String getAnnualIncome() {
return annualIncome;
}
public void setAnnualIncome(String annualIncome) {
this.annualIncome = annualIncome;
}
public String getBloodGroup() {
return bloodGroup;
}
public void setBloodGroup(String bloodGroup) {
this.bloodGroup = bloodGroup;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getModeOfPayment() {
return modeOfPayment;
}
public void setModeOfPayment(String modeOfPayment) {
this.modeOfPayment = modeOfPayment;
}
public String getModeOfPaymentAlt() {
return modeOfPaymentAlt;
}
public void setModeOfPaymentAlt(String modeOfPaymentAlt) {
this.modeOfPaymentAlt = modeOfPaymentAlt;
}
public String getExtPrimaryPhysicianName() {
return extPrimaryPhysicianName;
}
public void setExtPrimaryPhysicianName(String extPrimaryPhysicianName) {
this.extPrimaryPhysicianName = extPrimaryPhysicianName;
}
public String getExtPrimaryPhysicianPhoneNumber() {
return extPrimaryPhysicianPhoneNumber;
}
public void setExtPrimaryPhysicianPhoneNumber(String extPrimaryPhysicianPhoneNumber) {
this.extPrimaryPhysicianPhoneNumber = extPrimaryPhysicianPhoneNumber;
}
public Boolean getIsDeleted() {
return isDeleted;
}
public void setIsDeleted(Boolean isDeleted) {
this.isDeleted = isDeleted;
}
public String getMetaCreatedByUser() {
return metaCreatedByUser;
}
public void setMetaCreatedByUser(String metaCreatedByUser) {
this.metaCreatedByUser = metaCreatedByUser;
}
public Date getMetaUpdatedDT() {
return metaUpdatedDT;
}
public void setMetaUpdatedDT(Date metaUpdatedDT) {
this.metaUpdatedDT = metaUpdatedDT;
}
public Date getMetaCreatedDT() {
return metaCreatedDT;
}
public void setMetaCreatedDT(Date metaCreatedDT) {
this.metaCreatedDT = metaCreatedDT;
}
@Override
public int hashCode() {
int hash = 0;
hash += (patientKey != null ? patientKey.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
//TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Patientinfo)) {
return false;
}
Patientinfo other = (Patientinfo) object;
if ((this.patientKey == null && other.patientKey != null) || (this.patientKey != null && !this.patientKey.equals(other.patientKey))) {
return false;
}
return true;
}
@Override
public String toString() {
return "com.app.ehr.entities.Patientinfo[ patientKey=" + patientKey + " ]";
}
}
- Voyez-vous la sortie de
System.out.println("----------------------------------------- From Controller------------------------------------------------");
? - Non.. je ne la voyez pas. Je pense que mon erreur est avec le @Attribut du Modèle d'annotation.
Vous devez vous connecter pour publier un commentaire.
Je pense que le problème est que le Printemps ne sais pas comment désérialiser la date de votre navigateur client envoie lors de la présentation du
input
champ dansPrintemps ne sais pas comment prendre la valeur que vous saisissez dans ce champ et de le convertir en un
Date
objet. Vous devez vous inscrire à unPropertyEditor
pour que. Par exemple, ajoutez la ligne suivante à votre@Controller
classeÉvidemment, changer la
SimpleDateFormat
à ce que votre client envoie.Sur une note connexe, vous envoyez une réponse 302 par l'envoi d'une redirection
Rappelez-vous que la demande et les attributs de modèle ne vivent que pour la durée d'une demande. Ainsi, lorsque votre client d'envoyer la demande à
full-reg
, aucun formulaire de saisie des paramètres que vous avez envoyé à l'origine existe plus. Vous devez penser à comment vous faites cela.Je suis tombé sur la même erreur ce matin. Le problème avec mon code est que j'ai déclaré une variable comme un nombre entier dans mon formulaire de liaison de l'objet mais sur la forme, j'ai été la capture de texte. La modification de la variable pour le type correct fonctionné pour moi
Ce qui se passe quand la liaison définies ne correspond pas à ce que l'utilisateur l'envoi. Les problèmes les plus courants sont:
Donc, en général, assurez-vous que:
@PathVariable(value="myVariableName", String myVariable)
où le chemin définit@RequestMapping(value = "/userInfo/myVariableName", method = RequestMethod.GET)
essayez avec cette (avec
/add-update2
au lieu de simplementadd-update2
) et remplacermodelAttribute
parcommandName
commandName
etmodelAttribute
sont le même champ. Voir - stackoverflow.com/questions/21495616/...Dans mon cas, j'essaie de créer un objet qui a l'ID et le NOM en tant qu'attributs.
ID est de type int, NOM de la Chaîne.
Mais mon js ensemble des valeurs de ce type
ID = ", NOM = 'brabrabra...'
Après set ID = 0, le problème est résolu.