バネデータJPAリポジトリメソッドを使用して、4つのフォームフィールドの名前、年齢、場所、およびアドレスをデータベースに挿入しようとしています。フォームをアクションに送信するとき、コントローラは送信された値を受け取ることができませんでした。コントローラーアクションでnullを取得します。ここで私は春の春のブートと春のデータJPAを使用してみてください。以下は、私のコントローラであるフォームを送信するときにフォームの値が取得されない
@RequestMapping(value="/driverSubmit", method=RequestMethod.POST)
public ModelAndView driverSubmit(@ModelAttribute Driver driver, Model model)
{
model.addAttribute("driver", driver);
driverRepo.save(driver);
return new ModelAndView("redirect:/dHome"); //to home page insertoin
}
そして、私のフォームは、
<form action="driverSubmit" method="post" >
<table width="300px" height="200px" align="center">
<tr>
<td>
<b> Name </b>
</td>
<td>
<input type="text" name="name" />
</td>
</tr>
<tr>
<td>
<b> Age</b>
</td>
<td>
<input type="text" name="age"/>
</td>
</tr>
<tr>
<td>
<b> Address</b>
</td>
<td>
<input type="text" name="address"/>
</td>
</tr>
<tr>
<td>
<b> Location</b>
</td>
<td>
<input type="text" name="location" />
</td>
</tr>
</table>
<div>
<input type="submit" value="Submit"/>
</div>
</form>
とコントローラでは、私は次のように@ModelAttributeを使用して送信されたフォームの値を受け付けており、
@ModelAttribute Driver driver
私はあります印刷によるトラブルシューティング
driver.name;
driver.age;
driver.address;
driver.location;
しかし、この方法ではアクセスしません。この受信方法は正しくないですか?私はこの方法で何ができますか?それ以外の場合は、受信したオブジェクトタイプを使用してフォーム値を達成するための二次的方法がありますか?
マイドライバクラスは、
パッケージcom.central.modelです。
import java.io.Serializable;
import javax.persistence。*;
@Entity
@Table(name = "drivers")
public class Driver implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Integer id;
@Column(name = "name")
public String name;
@Column(name = "age")
public Integer age;
@Column(name = "address")
public String address;
@Column(name = "location")
public String location;
public Driver() {
}
public Driver(String name, Integer age, String address , String location) {
this.name = name;
this.age = age;
this.address = address;
this.location = location;
}
}
。 – mrtasln
ドライバが私のオブジェクトです、私はアクション定義で作成しました。そして、関数の始めに受け取った値をデバッグしたとき、null値を取得しました。 "@ModelAttributeドライバードライバー"コードを使用しているときに受信しません。 – Jacob
Driverクラスを表示できますか? – mrtasln