@Controller
public class MyController {
@RequestMapping(value = "/click", method = RequestMethod.GET)
public String registerForm(Model model) {
User user = new User();
user.setSex("男");
model.addAttribute("user", user);
return "result";
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form:form modelAttribute="user" action="click" method="POST">
<table>
<tr>
<td>性别∶</td>
<td>
<form:radiobutton path="sex" value="男" />男
<form:radiobutton path="sex" value="女" />女 </td>
</tr>
</table>
</form:form>
</body>
</html>
radiobuttons
@Controller
public class MyController {
@RequestMapping(value = "/click", method = RequestMethod.GET)
public String registerForm2(Model model) {
User user = new User();
user.setSex("男");
user.setSex("女");
List<String> sexList = new ArrayList<String>();
sexList.add("男");
sexList.add("女");
model.addAttribute("user", user);
model.addAttribute("sexList", sexList);
return "result";
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form:form modelAttribute="user" action="click" method="POST">
<table>
<tr>
<td>性别∶</td>
<td><form:radiobuttons path="sex" items="${sexList}" /></td>
</tr>
</table>
</form:form>
</body>
</html>