博客
关于我
强烈建议你试试无所不能的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

你可能感兴趣的文章
Thrift使用教程(Java版本)
查看>>
我的友情链接
查看>>
通过SSH证书实现Putty免密码登录CentOS
查看>>
Java IO类库之Bits
查看>>
ERROR 1217 (23000): Cannot delete or update a pare
查看>>
oracle 11g RAC搭建 ASM存储
查看>>
函数学习-bytearray()
查看>>
CentOS7安装配置telnet-server
查看>>
GitOSC和GitHub上传项目
查看>>
全局静态变量析构和线程结束先后顺序问题
查看>>
[PYTHON] 核心编程笔记(12.Python模块)
查看>>
windows下MD5-SHA1校验
查看>>
Linux学习记录-2015-08-20--常用命令1
查看>>
Android工程引用另外一个工程的正确/错误方法
查看>>
Testlink使用介绍
查看>>
【动态规划】0-1背包问题原理和实现
查看>>
c3p0详细配置
查看>>
jsfl导出库里面的PNG图片
查看>>
PostgreSQL的MVCC vs InnoDB的MVCC
查看>>
COMP9321/19T1/resources/22490
查看>>