博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringMVC处理模型数据
阅读量:6643 次
发布时间:2019-06-25

本文共 3311 字,大约阅读时间需要 11 分钟。

目录结构

web.xml

HiddenHttpMethodFilter
org.springframework.web.filter.HiddenHttpMethodFilter
HiddenHttpMethodFilter
/*
dispatcherServlet
org.springframework.web.servlet.DispatcherServlet
1
dispatcherServlet
/

dispatcherServlet-servlet.xml

test

package com.springmvc;import java.io.IOException;import java.io.Writer;import java.util.Arrays;import java.util.Date;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.CookieValue;import org.springframework.web.bind.annotation.ModelAttribute;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestHeader;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.SessionAttributes;import org.springframework.web.servlet.ModelAndView;import com.springmvc.entities.User;@SessionAttributes(value = { "user" }, types = { String.class }) // user为键 和string类型的放入session中@RequestMapping("/springmvc")  @Controllerpublic class SpringMVCTest {    private static final String SUCCESS = "success";    @RequestMapping("/testSessionAttributes")    public String testSessionAttributes(Map
map) { User user = new User("Tom", "123456", "tom@aaaa.com", 15); map.put("user", user); map.put("school", "yp"); return SUCCESS; } @RequestMapping("/testMap") public String testMap(Map
map) { System.out.println(map.getClass().getName()); map.put("names", Arrays.asList("AA", "BB", "CC")); return SUCCESS; } @RequestMapping("/testModelAndView") public ModelAndView testModelAndView() { String viewName = SUCCESS; ModelAndView modelAndView = new ModelAndView(viewName); modelAndView.addObject("modelAndView", "testModelAndView"); return modelAndView; }}

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>
Insert title here testModelAndView testMap testSessionAttributes

success.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>
Insert title here ModelAndView :${requestScope.modelAndView}
Map: ${requestScope.names}
SessionAttributes: ${sessionScope.user.username}
School:${sessionScope.school}

 

转载于:https://www.cnblogs.com/lusufei/p/7396192.html

你可能感兴趣的文章
第九届ECNU Coder F.蚂蚁(栈)
查看>>
iOS开发-常见宏定义
查看>>
C# 通过反射实现类似MVC路由的机制
查看>>
转:PrintWriter中write与println方法的区别
查看>>
解构赋值,reset参数,扩展运算符,class,import、export
查看>>
HTML中汉字空格占位符
查看>>
下拉加载更多
查看>>
Leetcode | Sort Colors
查看>>
video.js播放rtmp流2
查看>>
类欧几里得算法
查看>>
2013 Multi-University Training Contest 5 部分解题报告
查看>>
IP TCP HTTP Socket的区别
查看>>
js函数
查看>>
压缩图片的算法
查看>>
人生不可能完美因此我们要学会讲究着过
查看>>
正则表达式详解
查看>>
.net RAW(16)与GUID互相转换
查看>>
DE1-soc软件实验”hello_word"
查看>>
第一个vi
查看>>
tidb导入大量数据报错:statement count 5001 exceeds the transaction limitation, autocommit = false...
查看>>