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

美橙域名查询网站考研比较厉害的培训机构

美橙域名查询网站,考研比较厉害的培训机构,小程序宣传推广方案,wordpress获取当前tag名称文章目录 1.基本介绍2.PathVariable 路径参数获取信息 1.代码实例 1.index.html2.ParameterController.java3.测试 2.细节说明 3.RequestHeader 请求头获取信息 1.代码实例 1.index.html2.ParameterController.java3.测试 2.细节说明 4.RequestParameter 请求获取参数信息 1.…文章目录 1.基本介绍2.PathVariable 路径参数获取信息 1.代码实例 1.index.html2.ParameterController.java3.测试 2.细节说明 3.RequestHeader 请求头获取信息 1.代码实例 1.index.html2.ParameterController.java3.测试 2.细节说明 4.RequestParameter 请求获取参数信息 1.代码实例 1.index.html2.ParameterController.java3.测试 2.细节说明 5.CookieValue cookie获取值 1.代码实例 1.index.html2.ParameterController.java3.测试 2.细节说明 6.RequestBody 处理json请求post请求体获取信息 1.代码实例 1.index.html2.ParameterController.java3.测试 7.RequestAttribute 请求域获取信息 1.代码实例 1.RequestController.java2.配置视图解析器 application.yml3.测试 8.SessionAttribute session域获取信息 1.代码实例 1.SessionController.java2.配置视图解析器同上3.测试 9.复杂参数 1.代码实例 1.RequestController.java2.测试 2.HttpServletResponse给浏览器设置cookie 1.代码实例2.测试 1.基本介绍 2.PathVariable 路径参数获取信息 1.代码实例 1.index.html !DOCTYPE html html langen headmeta charsetUTF-8titleTitle/title /head body h1基本注解/h1 hr/ a href/monster/100/kingPathVariable-路径变量/monster/100/king/a /body /html2.ParameterController.java package com.sun.springboot.controller;import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController;import java.util.Map;/*** author 孙显圣* version 1.0*/ RestController public class ParameterController {GetMapping(/monster/{id}/{name}) //接受两个路径参数public String pathVariable(PathVariable(id) Integer id, PathVariable(name) String name,PathVariable MapString, String map) { //这里的map指将所有的路径参数都放到map中System.out.println(id id name: name);for (Map.EntryString, String entry : map.entrySet()) {System.out.println(key entry.getKey() value: entry.getValue());}return success; //返回json给浏览器}}3.测试 2.细节说明 PathVariable(“xxx”)必须跟{xxx}相对应可以将所有的路径参数放到map中 PathVariable MapString, String map 3.RequestHeader 请求头获取信息 1.代码实例 1.index.html !DOCTYPE html html langen headmeta charsetUTF-8titleTitle/title /head body h1基本注解/h1 hr/ a href/requestHeaderRequestHeader-获取请求头信息/a /body /html2.ParameterController.java package com.sun.springboot.controller;import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RestController;import java.util.Map;/*** author 孙显圣* version 1.0*/ RestController public class ParameterController {GetMapping(/requestHeader) //获取请求头的信息public String requestHeader(RequestHeader(host) String host, RequestHeader MapString, String header) {System.out.println(host host);System.out.println(header);return success;}}3.测试 2.细节说明 请求头的信息都是以key - value的形式存储的可以通过RequestHeader(“xxx”)来获取xxx对应的value也可以通过RequestHeader MapString, String header将所有的key - value都封装到map中 4.RequestParameter 请求获取参数信息 1.代码实例 1.index.html !DOCTYPE html html langen headmeta charsetUTF-8titleTitle/title /head body h1基本注解/h1 hr/ a href/hi?hobby打篮球hobby踢球RequestParam-请求参数/a /body /html2.ParameterController.java package com.sun.springboot.controller;import org.springframework.web.bind.annotation.*;import java.util.List;/*** author 孙显圣* version 1.0*/ RestController public class ParameterController {GetMapping(/hi)public String hi(RequestParam(value name, defaultValue 孙显圣) String name,RequestParam(hobby) ListString list) {System.out.println(name name);System.out.println(list);return success;}}3.测试 2.细节说明 请求参数是可以设置默认值的使用defaultValue属性即可请求参数还可以将同名的结果封装到List中请求参数也可以使用RequestParameter MapString, String map 将所有参数封装到map中但是如果有同名的结果只会得到第一个因为map的key是唯一的 5.CookieValue cookie获取值 1.代码实例 1.index.html !DOCTYPE html html langen headmeta charsetUTF-8titleTitle/title /head body h1基本注解/h1 hr/ a href/cookieCookieValue-获取cookie的值/a /body /html2.ParameterController.java package com.sun.springboot.controller;import org.springframework.web.bind.annotation.*;import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest;/*** author 孙显圣* version 1.0*/ RestController public class ParameterController {GetMapping(/cookie)//这里可以设置required false意为不是必须存在的如果不存在则得到的值就为null//如果后面的参数类型是Cookie则会获取Cookie对象并封装到变量中public String cookie(CookieValue(value cookie_key, required false) String cookie_value,CookieValue(value username , required false) Cookie cookie, HttpServletRequest request) {//使用原生api获取cookiesCookie[] cookies request.getCookies();for (Cookie cookie1 : cookies) {System.out.println(cookie1);}System.out.println(cookie_value);System.out.println(name: cookie.getName() value: cookie.getValue());return success;}}3.测试 2.细节说明 CookieValue可以根据后面要封装的参数的类型来获取指定的值如果后面的类型是Cookie类型则会获取一个Cookie对象并封装进入如果是String类型则会获取Cookie的value来进行封装还可以通过Servlet原生api的request来获取所有的cookieCookieValue中有属性required默认为true意为必须存在否则报错如果设置为false则如果获取不到则为null 6.RequestBody 处理json请求post请求体获取信息 1.代码实例 1.index.html !DOCTYPE html html langen headmeta charsetUTF-8titleTitle/title /head body h1基本注解/h1 hr/ form action/requestBody methodpostinput typetext nameusernamebrinput typetext namepasswordbrinput typesubmit valuesubmit /form /body /html2.ParameterController.java package com.sun.springboot.controller;import org.springframework.web.bind.annotation.*;/*** author 孙显圣* version 1.0*/ RestController public class ParameterController {PostMapping(requestBody)public String getRequestBody(RequestBody String requestBody) { //获取请求体System.out.println(requestBody);return success;}}3.测试 7.RequestAttribute 请求域获取信息 1.代码实例 1.RequestController.java package com.sun.springboot.controller;import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.ResponseBody;import javax.servlet.http.HttpServletRequest; /*** author 孙显圣* version 1.0*/ Controller public class RequestController {GetMapping(/login)public String login(HttpServletRequest request) {//在Request域中存放一些信息request.setAttribute(name, sun);request.setAttribute(age, 13);//调用视图解析器请求转发到/okreturn forward:/ok;}ResponseBodyGetMapping(/ok)public String ok(RequestAttribute(value name, required false) String name) { //使用注解来获取请求域中的信息并封装到参数中System.out.println(name: name);return success; //返回json给浏览器} }2.配置视图解析器 application.yml spring:mvc:view: #配置了视图解析器suffix: .html #后缀prefix: / #前缀指的是根目录3.测试 8.SessionAttribute session域获取信息 1.代码实例 1.SessionController.java package com.sun.springboot.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.ResponseBody;import org.springframework.web.bind.annotation.SessionAttribute;import javax.servlet.http.HttpServletRequest;/*** author 孙显圣* version 1.0*/Controllerpublic class SessionController {GetMapping(/login)public String login(HttpServletRequest request) {//在session域中设置信息request.getSession().setAttribute(session, session_value);//调用视图解析器请求转发到/okreturn forward:/ok;}ResponseBodyGetMapping(/ok)public String ok(SessionAttribute(value session) String value) { //使用注解来获取session域中的信息并封装到参数中System.out.println(session: value);return success; //返回json给浏览器}}2.配置视图解析器同上 3.测试 9.复杂参数 1.代码实例 1.RequestController.java package com.sun.springboot.controller;import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.ResponseBody;import javax.servlet.http.HttpServletResponse; import java.util.Map;/*** author 孙显圣* version 1.0*/ Controller public class RequestController {GetMapping(/login)public String login(MapString, Object map, Model model, HttpServletResponse response) {//给map封装信息map.put(user, sun);map.put(job, 工程师);//model封装信息model.addAttribute(sal, 1000);//结果最后都会封装到request域中//调用视图解析器请求转发到/okreturn forward:/ok;}ResponseBodyGetMapping(/ok)public String ok(RequestAttribute(user) String user, RequestAttribute(job) String job,RequestAttribute(sal) Integer sal) { //使用注解来获取请求域中的信息并封装到参数中System.out.println(user: user job: job sal: sal);return success; //返回json给浏览器} }2.测试 2.HttpServletResponse给浏览器设置cookie 1.代码实例 package com.sun.springboot.controller;import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody;import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse;/*** author 孙显圣* version 1.0*/ Controller public class RequestController {GetMapping(/login)public String login(HttpServletResponse response) {Cookie cookie new Cookie(cookie_name, cookie_value);response.addCookie(cookie);//调用视图解析器重定向到/ok,不能使用请求转发因为虽然响应给客户端cookie了// 但是由于是请求转发第二个controller得到的是最开始的请求那时候还没有cookiereturn redirect:/ok;}ResponseBodyGetMapping(/ok)public String ok(CookieValue(cookie_name) Cookie cookie) {//获取cookieSystem.out.println(key: cookie.getName() value: cookie.getValue());return success; //返回json给浏览器} }2.测试
http://www.tj-hxxt.cn/news/131684.html

相关文章:

  • 连云港网站开发零基础网站建设教学在哪里
  • 新手做地方门户网站苏州建设工程招标网
  • 低价网站开发携程网站建设的意义
  • 做资源网站违法吗江门cms建站
  • 西安做一个企业网站要多少钱免费代理ip
  • 天津建设工程合同备案网站ftp两个网站子域名的绑定
  • 黄冈市建设信息网站和君设计专业网站建设公司
  • 台州网站搭建线上超市购物平台有哪些
  • 淄博网站建设设计页面设计公司排名
  • 广州自助公司建网站wordpress 虚拟流量
  • 襄阳建设局网站wordpress 资源文件
  • 手机网站生产app东莞vi设计
  • 怎样做网站平台建设银行网站的机构
  • 济南网站制作经验济南建设银行网站
  • 朝阳网站建设多少钱唐山网站建设公司哪家好
  • 公司为什么要建立网站关于网站的ppt怎么做
  • wordpress 使用ip访问不了小时seo百度关键词点击器
  • 群晖ds1817做网站新型干法水泥工艺设计计算及实用技术 久久建筑网
  • 四川网站建设服务步骤流程
  • 潍坊市网站大学 生免费商业网站设计
  • 香奈儿网站建设策划书大连网站建设比较好的公司
  • 网站前端与后台必须同时做吗wordpress内容页插件
  • seo查询爱站南通企业网页制作
  • 家具公司网站模板下载小米网站 用什么做的
  • 西宁做网站的公司力请君博d九歌人工智能诗歌写作网站
  • 三明网站seo长春市住房和城乡建设局网站
  • 网站 常见推广WordPress主题Cute主题
  • 长沙企业网站排名优化wordpress高端企业主题
  • 商业网站首页怎么做wordpress评论换行
  • 大朗做网站的300个免费邮箱地址2022