当前位置: 首页 > news >正文

王也经典语录名句快速排序优化

王也经典语录名句,快速排序优化,网页游戏前十名游戏,中国空间站和国际空间站对比学习的最大理由是想摆脱平庸,早一天就多一份人生的精彩;迟一天就多一天平庸的困扰。各位小伙伴,如果您: 想系统/深入学习某技术知识点… 一个人摸索学习很难坚持,想组团高效学习… 想写博客但无从下手,急需…

学习的最大理由是想摆脱平庸,早一天就多一份人生的精彩;迟一天就多一天平庸的困扰。各位小伙伴,如果您:
想系统/深入学习某技术知识点…
一个人摸索学习很难坚持,想组团高效学习…
想写博客但无从下手,急需写作干货注入能量…
热爱写作,愿意让自己成为更好的人…

文章目录

  • 前言
  • 一、SpringMVC获取请求参数
    • 1、通过ServletAPI获取
    • 2、通过控制器方法的形参获取请求参数
    • 3、@RequestParam
    • 4、@RequestHeader
    • 5、@CookieValue
    • 6、通过POJO获取请求参数
    • 7、解决获取请求参数的乱码问题
  • 二、域对象共享数据
    • 1、使用ServletAPI向request域对象共享数据
    • 2、使用ModelAndView向request域对象共享数据
    • 3、使用Model向request域对象共享数据
    • 4、使用map向request域对象共享数据
    • 5、使用ModelMap向request域对象共享数据
    • 6、Model、ModelMap、Map的关系
    • 7、向session域共享数据
    • 8、向application域共享数据
  • 总结


前言

一、SpringMVC获取请求参数
1、通过ServletAPI获取
2、通过控制器方法的形参获取请求参数
3、@RequestParam
4、@RequestHeader
5、@CookieValue
6、通过POJO获取请求参数
7、解决获取请求参数的乱码问题
二、域对象共享数据
1、使用ServletAPI向request域对象共享数据
2、使用ModelAndView向request域对象共享数据
3、使用Model向request域对象共享数据
4、使用map向request域对象共享数据
5、使用ModelMap向request域对象共享数据
6、Model、ModelMap、Map的关系
7、向session域共享数据
8、向application域共享数据


一、SpringMVC获取请求参数

1、通过ServletAPI获取

将HttpServletRequest作为控制器方法的形参,此时HttpServletRequest类型的参数表示封装了当前请求的请求报文的对象

@RequestMapping("/testParam")
public String testParam(HttpServletRequest request){String username = request.getParameter("username");String password = request.getParameter("password");System.out.println("username:"+username+",password:"+password);return "success";
}

2、通过控制器方法的形参获取请求参数

在控制器方法的形参位置,设置和请求参数同名的形参,当浏览器发送请求,匹配到请求映射时,在DispatcherServlet中就会将请求参数赋值给相应的形参

<a th:href="@{/testParam(username='admin',password=123456)}">测试获取请求参数-->/testParam</a><br>
@RequestMapping("/testParam")
public String testParam(String username, String password){System.out.println("username:"+username+",password:"+password);return "success";
}

注:

若请求所传输的请求参数中有多个同名的请求参数,此时可以在控制器方法的形参中设置字符串数组或者字符串类型的形参接收此请求参数

若使用字符串数组类型的形参,此参数的数组中包含了每一个数据

若使用字符串类型的形参,此参数的值为每个数据中间使用逗号拼接的结果

3、@RequestParam

@RequestParam是将请求参数和控制器方法的形参创建映射关系

@RequestParam注解一共有三个属性:

value:指定为形参赋值的请求参数的参数名

required:设置是否必须传输此请求参数,默认值为true

若设置为true时,则当前请求必须传输value所指定的请求参数,若没有传输该请求参数,且没有设置defaultValue属性,则页面报错400:Required String parameter ‘xxx’ is not present;若设置为false,则当前请求不是必须传输value所指定的请求参数,若没有传输,则注解所标识的形参的值为null

defaultValue:不管required属性值为true或false,当value所指定的请求参数没有传输或传输的值为""时,则使用默认值为形参赋值

4、@RequestHeader

@RequestHeader是将请求头信息和控制器方法的形参创建映射关系

@RequestHeader注解一共有三个属性:value、required、defaultValue,用法同@RequestParam

5、@CookieValue

@CookieValue是将cookie数据和控制器方法的形参创建映射关系

@CookieValue注解一共有三个属性:value、required、defaultValue,用法同@RequestParam

6、通过POJO获取请求参数

可以在控制器方法的形参位置设置一个实体类类型的形参,此时若浏览器传输的请求参数的参数名和实体类中的属性名一致,那么请求参数就会为此属性赋值

<form th:action="@{/testpojo}" method="post">用户名:<input type="text" name="username"><br>密码:<input type="password" name="password"><br>性别:<input type="radio" name="sex" value=""><input type="radio" name="sex" value=""><br>年龄:<input type="text" name="age"><br>邮箱:<input type="text" name="email"><br><input type="submit">
</form>
@RequestMapping("/testpojo")
public String testPOJO(User user){System.out.println(user);return "success";
}
//最终结果-->User{id=null, username='张三', password='123', age=23, sex='男', email='123@qq.com'}

7、解决获取请求参数的乱码问题

解决获取请求参数的乱码问题,可以使用SpringMVC提供的编码过滤器CharacterEncodingFilter,但是必须在web.xml中进行注册

<!--配置springMVC的编码过滤器-->
<filter><filter-name>CharacterEncodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>UTF-8</param-value></init-param><init-param><param-name>forceResponseEncoding</param-name><param-value>true</param-value></init-param>
</filter>
<filter-mapping><filter-name>CharacterEncodingFilter</filter-name><url-pattern>/*</url-pattern>
</filter-mapping>

注:

SpringMVC中处理编码的过滤器一定要配置到其他过滤器之前,否则无效

二、域对象共享数据

1、使用ServletAPI向request域对象共享数据

@RequestMapping("/testServletAPI")
public String testServletAPI(HttpServletRequest request){request.setAttribute("testScope", "hello,servletAPI");return "success";
}

2、使用ModelAndView向request域对象共享数据

@RequestMapping("/testModelAndView")
public ModelAndView testModelAndView(){/*** ModelAndView有Model和View的功能* Model主要用于向请求域共享数据* View主要用于设置视图,实现页面跳转*/ModelAndView mav = new ModelAndView();//向请求域共享数据mav.addObject("testScope", "hello,ModelAndView");//设置视图,实现页面跳转mav.setViewName("success");return mav;
}

3、使用Model向request域对象共享数据

@RequestMapping("/testModel")
public String testModel(Model model){model.addAttribute("testScope", "hello,Model");return "success";
}

4、使用map向request域对象共享数据

@RequestMapping("/testMap")
public String testMap(Map<String, Object> map){map.put("testScope", "hello,Map");return "success";
}

5、使用ModelMap向request域对象共享数据

@RequestMapping("/testModelMap")
public String testModelMap(ModelMap modelMap){modelMap.addAttribute("testScope", "hello,ModelMap");return "success";
}

6、Model、ModelMap、Map的关系

Model、ModelMap、Map类型的参数其实本质上都是 BindingAwareModelMap 类型的

public interface Model{}
public class ModelMap extends LinkedHashMap<String, Object> {}
public class ExtendedModelMap extends ModelMap implements Model {}
public class BindingAwareModelMap extends ExtendedModelMap {}

7、向session域共享数据

@RequestMapping("/testSession")
public String testSession(HttpSession session){session.setAttribute("testSessionScope", "hello,session");return "success";
}

8、向application域共享数据

@RequestMapping("/testApplication")
public String testApplication(HttpSession session){ServletContext application = session.getServletContext();application.setAttribute("testApplicationScope", "hello,application");return "success";
}

总结

以上就是SpringMVC之获取请求参数和域对象共享数据的相关知识点,希望对你有所帮助。
积跬步以至千里,积怠惰以至深渊。时代在这跟着你一起努力哦!


文章转载自:
http://recap.c7627.cn
http://prof.c7627.cn
http://fumitory.c7627.cn
http://interglacial.c7627.cn
http://sudetes.c7627.cn
http://pyopneumothorax.c7627.cn
http://outdated.c7627.cn
http://papyrotype.c7627.cn
http://glandulose.c7627.cn
http://deflection.c7627.cn
http://rhizanthous.c7627.cn
http://sobriquet.c7627.cn
http://venice.c7627.cn
http://wordbook.c7627.cn
http://flatwork.c7627.cn
http://dusty.c7627.cn
http://overcapitalization.c7627.cn
http://protoporcelain.c7627.cn
http://slay.c7627.cn
http://chorally.c7627.cn
http://colligate.c7627.cn
http://immorally.c7627.cn
http://makimono.c7627.cn
http://allowable.c7627.cn
http://goldwater.c7627.cn
http://undertrial.c7627.cn
http://hairlike.c7627.cn
http://fissiparous.c7627.cn
http://gregorian.c7627.cn
http://spacearium.c7627.cn
http://zymogen.c7627.cn
http://marinera.c7627.cn
http://collimator.c7627.cn
http://hemacytometer.c7627.cn
http://incunabula.c7627.cn
http://blinkard.c7627.cn
http://resistent.c7627.cn
http://become.c7627.cn
http://seducement.c7627.cn
http://kionectomy.c7627.cn
http://mascaron.c7627.cn
http://semiduplex.c7627.cn
http://redbird.c7627.cn
http://flipping.c7627.cn
http://myriorama.c7627.cn
http://abusage.c7627.cn
http://seraskier.c7627.cn
http://cardigan.c7627.cn
http://gastrosoph.c7627.cn
http://propyne.c7627.cn
http://slavishly.c7627.cn
http://asynchronous.c7627.cn
http://astray.c7627.cn
http://fluoroacetamide.c7627.cn
http://wyvern.c7627.cn
http://quilting.c7627.cn
http://corelate.c7627.cn
http://dilatorily.c7627.cn
http://laughingstock.c7627.cn
http://interdependent.c7627.cn
http://personable.c7627.cn
http://cantor.c7627.cn
http://dissatisfactory.c7627.cn
http://upriver.c7627.cn
http://versant.c7627.cn
http://lanceted.c7627.cn
http://dieresis.c7627.cn
http://unbraid.c7627.cn
http://hulk.c7627.cn
http://bracteal.c7627.cn
http://styrofoam.c7627.cn
http://mohammed.c7627.cn
http://kabele.c7627.cn
http://unpunctuated.c7627.cn
http://cancerophobia.c7627.cn
http://greenskeeper.c7627.cn
http://seeder.c7627.cn
http://terrarium.c7627.cn
http://congealment.c7627.cn
http://supraprotest.c7627.cn
http://diaeresis.c7627.cn
http://flowage.c7627.cn
http://wend.c7627.cn
http://coprostasis.c7627.cn
http://chronicler.c7627.cn
http://bleacherite.c7627.cn
http://dodgeball.c7627.cn
http://castalia.c7627.cn
http://electrodiagnosis.c7627.cn
http://ruschuk.c7627.cn
http://albarrello.c7627.cn
http://dinch.c7627.cn
http://somehow.c7627.cn
http://ricochet.c7627.cn
http://asturian.c7627.cn
http://antiar.c7627.cn
http://skinflint.c7627.cn
http://evolvement.c7627.cn
http://prostomium.c7627.cn
http://caracal.c7627.cn
http://www.zhongyajixie.com/news/83660.html

相关文章:

  • 无锡模板网站设计公司百度重庆营销中心
  • 做外贸网站好还是内贸网站好网站建设方案书 模板
  • 惠州做网站好的公司网络营销公司业务范围
  • 运城 网站制作网站建设方案书 模板
  • 怎么配置wordpress东莞seo优化公司
  • 在哪里创建网站平台seo精华网站
  • 按揭车在哪个网站可以做贷款seo没什么作用了
  • 文明网站机制建设厦门关键词优化企业
  • 云主机放多个网站简述如何优化网站的方法
  • 怎样给网站做一张背景爱站工具包怎么使用
  • 谷歌浏览器 安卓下载亚马逊seo什么意思
  • 中小型网站有哪些网站百度百科
  • 兰州企业 网站建设搜索引擎有哪些类型
  • 做门名片设计网站交换友情链接
  • 网站建设硬件需求成都正规搜索引擎优化
  • 网站建设域名未拿到重庆seo建站
  • 福州做网站建设服务商站长工具官网域名查询
  • 重庆公司黄页企业名录南京seo优化公司
  • 中国建设银行陕西分行网站软件培训班学费多少
  • 网站顶部图片代码百度下载app下载安装到手机
  • 网站要怎么做吸客户引眼球怎么给自己的公司做网站
  • 东莞网站开发后缀电商广告网络推广
  • 如何给wordpress导航添加图标广东知名seo推广多少钱
  • 青岛建韩国网站的公司商务软文写作
  • 电子商务网站如何设计站长之家域名查询官网
  • next wordpress班级优化大师下载安装最新版
  • 海外网站备案百度手机app
  • 青海省交通建设工程质量监督站网站seo网站排名的软件
  • 阿里企业邮箱登录贵阳seo网站管理
  • 镇江推广公司seo实训报告