码迷,mamicode.com
首页 > 编程语言 > 详细

spring mvc数据绑定与表单标签库

时间:2018-04-06 21:15:35      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:request   command   .sh   work   pac   man   val   doctype   com   

Book类为

package org.shaoxiu;

public class Book {
	private String id;
	private String name;
	
	public Book() {
		super();
	}

	public Book(String id, String name) {
		super();
		this.id = id;
		this.name = name;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return "Book [id=" + id + ", name=" + name + "]";
	}
	
	
	
}

  控制器为

package org.shaoxiu01;


import java.util.ArrayList;

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

@Controller
public class TestController01 {

	@RequestMapping("test01")
	public String test(Model model){
		ArrayList<Book> list=new ArrayList<>();
		list.add(new Book("001","c"));
		list.add(new Book("002","c++"));
		list.add(new Book("003","java"));
		model.addAttribute("list", list);
		model.addAttribute("book", new Book("004","c#"));
		return "test01";
	}
}

  jsp页面代码为

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form:form commandName="book">
		<form:input path="id"/>
		<form:input path="name"/>
		<form:checkboxes path="id" id="ckid" name="id" items="${list}" itemLabel="name" itemValue="id"/>
	</form:form>
</body>
</html>

  解析后表单的html代码为

技术分享图片

 

 

  

spring mvc数据绑定与表单标签库

标签:request   command   .sh   work   pac   man   val   doctype   com   

原文地址:https://www.cnblogs.com/xiu68/p/8728754.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!