「Spring 入門」form:radiobuttonタグを実装するサンプル(Bean、Controller)

2017年10月13日

1.User.java
package com.changfatun.bean;
import java.io.Serializable;
public class User implements Serializable {
private String sex;
public String getSex() {
return sex;
}

public void setSex(String sex) {
this.sex = sex;
}

}

2.UserController.java
package com.changfatun.control;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.changfatun.bean.User;
@Controller
public class UserController {
@RequestMapping(value="/radiobuttonForm",method=RequestMethod.GET)
public String registerForm(Model model) {
User user=new User();
// 値の設定
user.setSex(“女");
model.addAttribute(“user", user);
return “radiobuttonForm";
}

}

3.radiobuttonForm.jsp

<form:form modelAttribute="user" method="post" action="radiobuttonForm" >

<table>

<tr> <td>性別:</td> <td>

<form:radiobutton path="sex" value="男"/>男

<form:radiobutton path="sex" value="女"/>女

</td> </tr>

</table>

</form:form>

Java

Posted by arkgame