より多くの要素をマークする可能性のあるselectを組み込みたいです。だからmultiple="true"。私はmysqlと春のDaoテクノロジーを使用しています。selectfromdatabaseの値を正常に取得しました。しかし、選択した値をデータベースに挿入するときに問題が発生しました。
そのための重要なテーブルは次のとおりです。

テーブルdemo.instrumenteには、、などのデータとguitar。が含まれます。これらの値(つまり、)は複数選択で表示されます。pianoidguitarpiano
ユーザーはおそらく2つまたは3つの楽器を選択することができます。そこで、生徒に次の楽器を追加する必要があります。私はテーブルでこれを行いますschueler_instrumente。すべてstudentとinstrumentがありidます。だから私はこのようなデータを作成する必要があります:
student_id 1 and instrument_id 2
student_id 1 and instrument_id 5
楽器モデルクラスのコードは次のとおりです。
public class Instrumente {
private Integer instrumentid;
private String instrumentname;
//...getters and setters
}
このコードは私のコントローラーの一部です:
@RequestMapping(method = RequestMethod.GET)
public String showUserForm(ModelMap model) {
model.put("instrumentListe", schuelerManager.getinstrumente());
return "usercenter";
}
そして、これが私のschuelerManagerの関連部分です
public Map<String, String> getinstrumente() {
Map<String,String> result = new LinkedHashMap<String,String>();
for (Instrumente instrument : instrumentDao.getInstrumente()) {
result.put(instrument.getInstrumentid().toString(),
instrument.getInstrumentname());
}
return result;
}
そして、これが私のデータベースからデータを取得する方法です:
public List<Instrumente> getInstrumente() {
return getJdbcTemplate().query("SELECT * FROM instrumente",
new RowMapper<Instrumente>() {
public Instrumente mapRow(ResultSet rs,
int rowNum)
throws SQLException {
Instrumente instrument = new Instrumente();
instrument.setInstrumentid
(rs.getInt("Instrument_ID"));
instrument.setInstrumentname
(rs.getString("Instrumentenbezeichnung"));
return instrument;
}
});
}
選択リストから選択した値を取得するために何をする必要があるかがわかりました。path="?"jspで何に書き込む必要がありますか。
値のリストを取り戻すことができると思いますが、このリストをテーブルに挿入するにはどうすればよいですかschueler_instrument。しばらくの間、または繰り返して、毎回挿入する必要がありましたか?インターネット上で良い例を見つけることができません。誰かがコードスニペットを使ってこれを行う方法を教えてくれることを願っています。