Wie zum senden von Daten von radio-buttons zur Steuerung mit Thymeleaf

Habe ich eine einfache HTML Seite, wo bin ich Anzeige paar radio buttons:

<form action="#" th:action="@{/processForm}" th:object="${priorities}"
  method="post">
  <fieldset>
    <table style="width: 500px">
      <tr th:each="item : ${chosen}">
        <td>
          <div>
            <div>
              <label th:text="${item}">example</label>
              <input type="radio" th:name="${'priorities[' + item + ']'}" value="a" />A
              <input type="radio" th:name="${'priorities[' + item + ']'}" value="b" />B
              <input type="radio" th:name="${'priorities[' + item + ']'}" value="c" />C
            </div>
          </div>
        </td>
      </tr>
      <tr>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td>
          <button type="submit"
            class="btn btn-xs btn-primary margin10-right paddingNew"
            name="save">Calculate!</button>
        </td>
        <td></td>
      </tr>
    </table>
  </fieldset>
</form>

Hier hast du, was ich sehen kann:

Wie zum senden von Daten von radio-buttons zur Steuerung mit Thymeleaf

Ich würde gerne senden Sie diese Daten auf meinem controller, so habe ich eine erstellt:

@RequestMapping(value = "/processForm", method = RequestMethod.POST)
public String save(@ModelAttribute(value = "foo") ClusterParams foo,
@ModelAttribute(value = "priorities") HashMap<String, String> priorities,
final ModelMap m) throws ClassNotFoundException, IOException,
InterruptedException {

    for (String s : priorities.keySet()) {
        System.out.println(s);
    }
}

Hier kannst du sehen, wie meine Klasse GEWICHTE (entfernt):

public class Weights {

    Map<String, String> priorities = new HashMap<String, String>();

    public Map<String, String> getPriorities() {
        return priorities;
    }

    public void setPriorities(Map<String, String> priorities) {
        this.priorities = priorities;
    }

}

aber ich habe keine Ahnung, wie die Werte mit thymeleaf.

Ich würde gerne eine Abbildung:

camera -> B
video -> C

Könnten Sie mir helfen, das zu tun? Natürlich ist es meine Idee mit der Erstellung einer HashMap, wenn es eine andere Lösung gibt, werde ich es ändern.

Danke im Voraus

InformationsquelleAutor ruhungry | 2014-06-23

Schreibe einen Kommentar