ToB企服应用市场:ToB评测及商务社交产业平台

标题: 补: Rest 风格哀求处理的的内容补充(1) [打印本页]

作者: 前进之路    时间: 2024-9-10 13:38
标题: 补: Rest 风格哀求处理的的内容补充(1)
补: Rest 风格哀求处理的的内容补充(1)

Rest风格哀求:注意事项和细节

  1. spring:
  2.   mvc:
  3.     hiddenmethod:
  4.       filter:
  5.         enabled: true # 开启页面表单的rest功能,启用了HiddenHttpMethodFilter,支持rest
复制代码
Rest的核心过滤器:
Spring Boot 开启视图解析器的 yaml 语法
  1. spring:
  2.   mvc:
  3.     hiddenmethod:
  4.       filter:
  5.         enabled: true # 开启页面表单的rest功能,启用了HiddenHttpMethodFilter,支持rest    view: # 设置视图解析器      prefix: /rainbowsea/** # 这里是需要注意,如果你设置了 static-path-pattern: /rainbowsea/** 需要保持一致#      prefix: /rainbowsea/ 都行 # 这里是需要注意,如果你设置了 static-path-pattern: /rainbowsea/** 需要保持一致      suffix: .html    static-path-pattern: /rainbowsea/**
复制代码
我们这里思考一个问题:为什么这里return "hello",返回的是不是字符串,而是转发到对应的资源文件。
  1. package com.rainbowsea.springboot.controller;
  2. import org.springframework.web.bind.annotation.RequestMapping;
  3. import org.springframework.web.bind.annotation.RestController;
  4. @RestController
  5. public class HiController {
  6.     @RequestMapping("/hello")
  7.     public String hi(){
  8.         return "hi:):)";
  9.     }
  10.     @RequestMapping("/go")
  11.     public String go(){
  12.         return "hello";
  13.         /*
  14.         return 是先看视图解析器当中是否有 hello.html 页面,没有就在找 controller 控制
  15. 是否有处理该请求的,如果两者都没有则报 404错误
  16.          */
  17.     }
  18. }
复制代码

注意:我是设置了视图解析器的。

启动 Spring Boot ,打开浏览器输入:http://localhost:8080/go


当 hello.html 静态资源存在时,并没有走 controller
我们将静态文件资源 hello.html 移除,再次访问:http://localhost:8080/go
问题:

我们将静态文件资源 hello.html 移除,再次访问:http://localhost:8080/go


最后:

“在这个最后的篇章中,我要表达我对每一位读者的感激之情。你们的关注和回复是我创作的动力源泉,我从你们身上吸取了无尽的灵感与勇气。我会将你们的鼓励留在心底,继承在其他的领域奋斗。感谢你们,我们总会在某个时刻再次相遇。”


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4