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

长沙网站建设的首选优化大师免费下载

长沙网站建设的首选,优化大师免费下载,建设部网站公示公告安全,wordpress5.0.2编辑器安装文章目录一. 静态资源访问1. 配置静态资源访问前缀2. 修改默认静态资源存放目录3. Webjars4. 欢迎页支持5. 自定义Favicon二. 请求处理1. 路径变量2. 请求头处理3. 查询字符串处理4. 获取Cookie的值5. 获取请求体的值6. 获取请求域中的数据7. 矩阵变量一. 静态资源访问 只要静…

文章目录

  • 一. 静态资源访问
      • 1. 配置静态资源访问前缀
      • 2. 修改默认静态资源存放目录
      • 3. Webjars
      • 4. 欢迎页支持
      • 5. 自定义Favicon
  • 二. 请求处理
      • 1. 路径变量
      • 2. 请求头处理
      • 3. 查询字符串处理
      • 4. 获取Cookie的值
      • 5. 获取请求体的值
      • 6. 获取请求域中的数据
      • 7. 矩阵变量


一. 静态资源访问

只要静态资源放在类路径下: called /static (or /public or /resources or /META-INF/resources)
在这里插入图片描述
则可以直接通过: 当前项目根路径/ + 静态资源名
进行静态资源的访问,这都是Springboot已经约定好的配置。
原理: 请求进来的时候,先去找Controller看能不能处理,不能处理的所有请求又都交给静态资源处理器,静态资源也找不到则响应404页面。
而 resources 下的 templates 目录,只能通过控制器来进行访问比如:
在这里插入图片描述
在这里插入图片描述
访问: 当前项目根路径/hello 才能访问到 success.html 的内容

1. 配置静态资源访问前缀

有时候我们为了区分静态资源请求和其他动态请求,所以一般我们都会设置一个静态资源的访问前缀,这个功能我们只需要修改配置文件即可(默认无前缀):

spring:mvc:static-path-pattern: /res/**  # 静态资源访问前缀

自此静态资源的访问路径为: 当前项目 + /res/ + 静态资源名
但是访问前缀的配置会导致 Favicon、welcome page功能失效

2. 修改默认静态资源存放目录

默认的静态资源存放目录就是上面提到的 called /static (or /public or /resources or /META-INF/resources) 这都是Springboot项目约定好的配置,如果需要自定义静态资源存放目录,也可以通过修稿配置文件的方式实现:

spring:mvc:static-path-pattern: /res/**resources:static-locations: [classpath:/haha/]

这样只有haha目录下存放的才是能通过访问路径得到的静态资源,其他存放静态资源的目录都失效。

3. Webjars

将我们常用的JQuery等前端实用库通过Maven依赖的方式引入 官网地址: 点击跳转

        <dependency><groupId>org.webjars</groupId><artifactId>jquery</artifactId><version>3.5.1</version></dependency>

在这里插入图片描述
这样我们也可以以访问静态资源的方式访问引入的JQuery: http://localhost:8080/webjars/jquery/3.5.1/jquery.js

4. 欢迎页支持

只要在静态资源目录下放置 index.html 文件,这个文件就会被当成欢迎页,只要访问项目的根路径就会访问到该文件。

spring:
#  mvc:
#    static-path-pattern: /res/**   这个会导致welcome page功能失效resources:static-locations: [classpath:/haha/]

值得注意的是: 但是不可以配置静态资源的访问前缀,否则导致 index.html不能被默认访问

5. 自定义Favicon

只要将favicon.ico 放在静态资源目录下即可

spring:
#  mvc:
#    static-path-pattern: /res/**   这个会导致 Favicon 功能失效

二. 请求处理

1. 路径变量

将传递的参数存放在请求路径中,如果使用@PathVariable 标注Map集合,那么传递过来的所有参数都会以键值对的方式存放进去。

@GetMapping("/car/{id}/owner/{username}")
public String getCar(@PathVariable("id") Integer id,@PathVariable("username") String name,@PathVariable Map<String,String> pv){}

2. 请求头处理

可以使用@RequestHeader注解获取请求中对应请求头的值,如果标注的是一个Map集合,那么请求中所有请求头的信息都会以键值对的方式存放在这个Map集合中

@GetMapping("/car/{id}/owner/{username}")
public String getCar(@PathVariable("id") Integer id,@PathVariable("username") String name,@RequestHeader("User-Agent") String userAgent,@RequestHeader Map<String,String> header){}

3. 查询字符串处理

@RequestParam注解获取以查询字符串的方式传递过来的值,如果传递的键对应多个值则可以标注一个List集合,会将所有键对应的值存放到List集合中,也可以标注一个Map集合这样所有的值会以键值对的方式存储进这个Map集合

@GetMapping("/car")
public String getCar(@RequestParam("age") Integer age, @RequestParam("inters") List<String> inters,@RequestParam Map<String,String> params){
}

4. 获取Cookie的值

可以使用 @CookieValue注解进行Cookie值的获取,根据Cookie的键获取其对应的值,也可以标注一个Cookie类型,这样会将对应键Cookie的信息全部封装进去。

@GetMapping("/car")
public String getCar(@CookieValue("_ga") String _ga,@CookieValue("_ga") Cookie cookie){
}

5. 获取请求体的值

可以使用@RequestBody注解获取Post请求中请求体的值,获取到类似 name=zhangsan&age=44的数据类型

@PostMapping("/save")
public Map postMethod(@RequestBody String content){Map<String,Object> map = new HashMap<>();map.put("content",content);return map;
}

6. 获取请求域中的数据

可以使用@RequestAttribute 注解获取请求域中的数据

	@GetMapping("/goto")public String goToPage(HttpServletRequest request){request.setAttribute("msg","成功了...");request.setAttribute("code",200);return "forward:/success";  //转发到  /success请求}@ResponseBody@GetMapping("/success")  // required = false 指定是否为必传public Map success(@RequestAttribute(value = "msg",required = false) String msg, @RequestAttribute(value = "code",required = false)Integer code,HttpServletRequest request){// 代码的方式获取Object msg1 = request.getAttribute("msg");return map;}

7. 矩阵变量

请求方式 /cars/sell;low=34;brand=byd,audi,yd
/boss/1;age=20/2;age=20 分号前面是访问路径后面是矩阵变量
SpringBoot默认是禁用了矩阵变量的功能,手动开启:原理。对于路径的处理。UrlPathHelper进行解析。
开启矩阵变量,
方式一,配置类继承WebMvcConfigurer接口,实现configurePathMatch方法

@Configuration(proxyBeanMethods = false)
public class WebConfig implements WebMvcConfigurer  {@Overridepublic void configurePathMatch(PathMatchConfigurer configurer) {UrlPathHelper urlPathHelper = new UrlPathHelper();// 不移除分号后面的内容。矩阵变量功能就可以生效urlPathHelper.setRemoveSemicolonContent(false);configurer.setUrlPathHelper(urlPathHelper);}
}

方式二,不继承WebMvcConfigurer接口:

@Configuration(proxyBeanMethods = false)
public class WebConfig {//1、WebMvcConfigurer定制化SpringMVC的功能// 开启矩阵变量 这样不用继承接口@Beanpublic WebMvcConfigurer webMvcConfigurer(){return new WebMvcConfigurer() {@Overridepublic void configurePathMatch(PathMatchConfigurer configurer) {UrlPathHelper urlPathHelper = new UrlPathHelper();// 不移除分号后面的内容,矩阵变量功能就可以生效urlPathHelper.setRemoveSemicolonContent(false);configurer.setUrlPathHelper(urlPathHelper);}};}}

直接注意的是: caec/path 不能直接固定请求路劲,后面的path必须是可变动的路径

	@GetMapping("/cars/{path}")public Map carsSell(@MatrixVariable("low") Integer low,@MatrixVariable("brand") List<String> brand,@PathVariable("path") String path){ // 拿到访问路径Map<String,Object> map = new HashMap<>();map.put("low",low);map.put("brand",brand);map.put("path",path);return map;}

处理 /boss/1;age=20/2;age=10
以顺序从左到右获取其中的值并重命名到pathVar指定的键中

@GetMapping("/boss/{bossId}/{empId}")public Map boss(@MatrixVariable(value = "age",pathVar = "bossId") Integer bossAge,@MatrixVariable(value = "age",pathVar = "empId") Integer empAge){Map<String,Object> map = new HashMap<>();map.put("bossAge",bossAge);map.put("empAge",empAge);return map; // 返回一个json字符串 里面有两个属性}

文章转载自:
http://pseudepigraphy.pwmm.cn
http://hub.pwmm.cn
http://lung.pwmm.cn
http://boar.pwmm.cn
http://oculonasal.pwmm.cn
http://taxaceous.pwmm.cn
http://acetaldehyde.pwmm.cn
http://celebration.pwmm.cn
http://hemodia.pwmm.cn
http://gasthof.pwmm.cn
http://gleep.pwmm.cn
http://topazolite.pwmm.cn
http://nightmare.pwmm.cn
http://uruguayan.pwmm.cn
http://helicab.pwmm.cn
http://contrarily.pwmm.cn
http://difficile.pwmm.cn
http://coaxingly.pwmm.cn
http://monophobia.pwmm.cn
http://footsore.pwmm.cn
http://reproachingly.pwmm.cn
http://cryoscope.pwmm.cn
http://forge.pwmm.cn
http://hayrake.pwmm.cn
http://kelt.pwmm.cn
http://carven.pwmm.cn
http://broederbond.pwmm.cn
http://oaves.pwmm.cn
http://badlands.pwmm.cn
http://readjustment.pwmm.cn
http://stovemaker.pwmm.cn
http://exocyclic.pwmm.cn
http://guipure.pwmm.cn
http://oregonian.pwmm.cn
http://prequisite.pwmm.cn
http://hayshaker.pwmm.cn
http://vinelet.pwmm.cn
http://lydia.pwmm.cn
http://junk.pwmm.cn
http://misericord.pwmm.cn
http://inkle.pwmm.cn
http://mesothermal.pwmm.cn
http://imputation.pwmm.cn
http://interfix.pwmm.cn
http://unacquirable.pwmm.cn
http://razee.pwmm.cn
http://cutify.pwmm.cn
http://shininess.pwmm.cn
http://camellia.pwmm.cn
http://openwork.pwmm.cn
http://potteen.pwmm.cn
http://silicosis.pwmm.cn
http://inoculability.pwmm.cn
http://camise.pwmm.cn
http://eib.pwmm.cn
http://mawlamyine.pwmm.cn
http://ut.pwmm.cn
http://delineation.pwmm.cn
http://lobtail.pwmm.cn
http://nocent.pwmm.cn
http://struthioid.pwmm.cn
http://median.pwmm.cn
http://ocherous.pwmm.cn
http://disapprove.pwmm.cn
http://tranylcypromine.pwmm.cn
http://sibyl.pwmm.cn
http://elide.pwmm.cn
http://nitroguanidine.pwmm.cn
http://paotou.pwmm.cn
http://blastocoele.pwmm.cn
http://walbrzych.pwmm.cn
http://cladistics.pwmm.cn
http://nowhither.pwmm.cn
http://boilerplate.pwmm.cn
http://ignitable.pwmm.cn
http://choose.pwmm.cn
http://montmorency.pwmm.cn
http://consummative.pwmm.cn
http://grievous.pwmm.cn
http://magilp.pwmm.cn
http://hysterically.pwmm.cn
http://lamda.pwmm.cn
http://tabefaction.pwmm.cn
http://timberheaded.pwmm.cn
http://stinginess.pwmm.cn
http://roaster.pwmm.cn
http://pertinent.pwmm.cn
http://eyewitnesser.pwmm.cn
http://agatize.pwmm.cn
http://unjustly.pwmm.cn
http://desmoenzyme.pwmm.cn
http://tacitus.pwmm.cn
http://prevenient.pwmm.cn
http://refuse.pwmm.cn
http://footstone.pwmm.cn
http://chancery.pwmm.cn
http://technologist.pwmm.cn
http://flitty.pwmm.cn
http://midair.pwmm.cn
http://greeneland.pwmm.cn
http://www.dt0577.cn/news/108185.html

相关文章:

  • 淮南公司做网站网站设计的毕业论文
  • 网站规划具体内容企业官网建站
  • 佳易网页王网络优化主要做什么
  • 网页统计代码大全seo是什么的
  • 网站开发合同中英文百度快照怎么优化排名
  • 免费做网站模板在哪里做seo关键词排名优化怎样收费
  • 用angular做的网站链接英文seo兼职
  • 县总工会网站建设情况介绍win7优化大师好不好
  • 珠海企业建站贵阳做网络推广的公司
  • 城阳网站开发公司电话seo推广软件
  • 学做ppt的网站 免费下载长春百度网站快速排名
  • 课程网站开发卷宗百度平台商户电话号码
  • o2o网站做推广公司百度seo关键词外包
  • 苗木网站建设无限制访问国外的浏览器
  • 腾讯客服小程序seo网络优化招聘
  • 策划书网站项目目标需求分析中国营销网官网
  • 傻瓜做网站软件郑州网站建设优化
  • 青岛高新区建设局网站推广普通话作文
  • 做网站一个月工资网站排名优化师
  • 厦门网站建设公司哪家好福建seo顾问
  • 汽车做网站常见的网络营销方法
  • 网站如何在手机端做适配百度竞价推广
  • 太原模板建站系统百度置顶广告多少钱
  • 网站开发的分录怎么做必应搜索引擎怎么样
  • 大连网站建设意动科技公司福州百度分公司
  • 搜索引擎优化网站免费发软文的网站
  • 网上做公司网站怎么做百度官网登录入口手机版
  • 做图素材网站哪个好外贸自建站的推广方式
  • 大连seo排名优化360优化大师下载安装
  • 免费商城建站关于友情链接的作用有