1.Controller

package com.tz.controller;

import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping; import com.tz.domain.Course; @Controller
@RequestMapping("/ModelAttribute")
public class ModelAttributeController { @RequestMapping("/handle")
public String handle(Course c){
System.out.println("handle......"); System.out.println(c);
return "success";
} // //有返回值类型
// @ModelAttribute//优先执行
// public Course show(String cname){
// /**
// * 当form表单中提交的数据不是完整的实体类型的数据时,需要保证,
// * 没有提交数据的字段还是使用
// * 数据库对象原来的数据
// *
// */
// System.out.println("show.....");
// //通过课程名称去数据库查询数据
// Course c = new Course();
// //模拟数据库中的值
// c.setCname(cname);
// c.setNumber(123);
// c.setPrice(11);
// c.setStock(123);
// c.setTeacher("coco");
// return c;
// } //无返回值类型
@ModelAttribute//优先执行
public void show(String cname,Map<String,Course> map){
/**
* 当form表单中提交的数据不是完整的实体类型的数据时,需要保证,
* 没有提交数据的字段还是使用
* 数据库对象原来的数据
*/
System.out.println("show.....");
//通过课程名称去数据库查询数据
Course c = new Course();
//模拟数据库中的值
c.setCname(cname);
c.setNumber(123);
c.setPrice(11);
c.setStock(123);
c.setTeacher("coco"); map.put("c",c);
// return c;
} }

  2.request.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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>
<a href="handle?user=coco">访问</a><br/> <form action="ModelAttribute/handle" method="post">
课程名称:
<input type="text" name="cname"><br/>
主讲老师:
<input type="text" name="teacher"><br/>
<hr/>
<input type="submit" value="提交">
</form> </body> </html>

  

最新文章

  1. Java - NIO
  2. think in java学习笔记
  3. Bandpass Signals(带通信号,或称窄带信号)
  4. @SpringBootApplication
  5. Travis-CI与Latex构建开源中文PDF
  6. 常用的PHP数据库操作方法(MYSQL版)
  7. (转)web网站架构演变
  8. 如何同时启动多个Tomcat服务
  9. 深入浅出 JavaScript 数组 v0.5
  10. 360开源的类Redis存储系统:Pika
  11. 打印object对象
  12. 打包程序时的证书问题(上传APP就出现Missing iOS Distribution signing indetity for)
  13. T4 代码生成 Demo (抽奖程序)
  14. master_pos_wait函数与MySQL主从切换
  15. Kettle根据时间戳同步数据实现
  16. [HNOI 2004]树的计数
  17. Spring Boot + Jersey发生FileNotFoundException (No such file or directory)
  18. ping -c 3 localhost
  19. Mybatis系列(三):Mybatis实现关联表查询
  20. vim的简单配置

热门文章

  1. Oracle连接Navicat Premium遇到的问题
  2. python 拆解包
  3. [原]调试实战——使用windbg调试崩溃在ole32!CStdMarshal::DisconnectSrvIPIDs
  4. tensorflow(三)
  5. Opencv笔记(十七)——轮廓性质
  6. centos mysql无法删除数据库
  7. topological space
  8. Windows_Management_Instrumentation
  9. 如何查看Linux系统下程序运行时使用的库?
  10. Spring Boot集成全局唯一ID生成器