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

网站开发需要资质吗如何防止网站被采集

网站开发需要资质吗,如何防止网站被采集,网站连接怎么做,dwcc怎么做网站目录 1.前言 2.正文 2.1SpringMVC是什么 2.2详解RequestMapping注解 2.3创建Spring项目 2.4建立连接 2.5Postman 3.小结 1.前言 哈喽大家好,今天来给大家带来Spring相关的学习,主要内容有概念的讲解以及如何分别通过Java代码和工具Postman来建立…


目录

1.前言

2.正文

2.1SpringMVC是什么

 2.2详解@RequestMapping注解

2.3创建Spring项目

2.4建立连接

2.5Postman

3.小结


1.前言

哈喽大家好,今天来给大家带来Spring相关的学习,主要内容有概念的讲解以及如何分别通过Java代码和工具Postman来建立连接,那么话不多说让我们开始吧。

2.正文

2.1SpringMVC是什么

Spring MVC 是 Spring 框架的一个模块,专门用于构建 Web 应用程序。它基于经典的 MVC 设计模式(Model-View-Controller),将应用程序分为三层:

  • Model(模型):封装数据(如数据库查询结果)。

  • View(视图):展示数据(如 HTML 页面)。

  • Controller(控制器):处理用户请求,协调 Model 和 View。

官方文档:

Spring Web MVC :: Spring Frameworkhttps://docs.spring.io/spring-framework/reference/web/webmvc.html

使用它有哪些优点呢:

  • 简化开发:通过注解和配置减少代码量。

  • 灵活扩展:支持多种视图技术(JSP、Thymeleaf 等)。

  • 与 Spring 生态无缝集成:如 Spring Security、Spring Data 等。 

那么SpringMVC是如何处理用户发送过来的Http请求呢:

DispatcherServlet(前端控制器)

  • 所有请求的入口,相当于“调度中心”。
  • 负责将请求分发给对应的 Controller。

HandlerMapping(处理器映射器)

  • 根据请求的 URL,找到对应的 Controller 和方法。

Controller(控制器)

  • 处理业务逻辑(如查询数据库),返回 Model 和视图名称。

ViewResolver(视图解析器)

  • 将视图名称(如 "home")解析为具体的视图(如 /WEB-INF/home.jsp)。

View(视图)

  • 渲染页面,将 Model 数据展示给用户。

流程: 

用户请求 → DispatcherServlet → HandlerMapping → Controller → 返回 ModelAndView → ViewResolver → View → 响应给用户

 2.2详解@RequestMapping注解

@RequestMapping 是 Spring MVC 中最核心的注解之一,用于将 HTTP 请求映射到具体的控制器方法。它支持灵活的 URL 匹配、请求方法限制、参数过滤等功能。(学习这一部分时,建议搭配后文使用)


基本用法:在类或方法上使用 @RequestMapping,指定 URL 路径:

@Controller
@RequestMapping("/user")  // 类级别的公共路径,类路径
public class UserController {@RequestMapping("/info")  // 完整路径是 /user/info,方法路径public String getUserInfo() {return "user_info"; }
}

那么该注解到底是GET请求还是POST请求呢?这个时候我们就要来借助以下抓包工具:

测试代码:

package com.example.demo;import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class test1 {@RequestMapping("/hello")public String hello(){return "hello";}}

此时可以看出来是GET请求。那有没有可能是POST请求呢?让我们来测试下:

我们在static创建一个HTML文件:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<form action="/hello" method="post"><input type = "submit" value = "传送">
</form>
</body>
</html>

就会发现此时是POST请求 。

那么我们如何定义该注解是GET请求还是POST请求呢?

@RequestMapping(method=GET)
@RequestMapping(method=POST)

利用method设置一下即可。 


总结下核心属性:

属性作用示例
value 或 path指定 URL 路径@RequestMapping("/user")
method限制请求方法(GET、POST 等)method = RequestMethod.POST
params要求请求必须包含特定参数params = "id=100"(参数 id 必须为 100)
headers要求请求头包含特定字段headers = "Content-Type=text/json"
consumes限制请求的 Content-Type(如接收 JSON)consumes = "application/json"
produces指定响应的 Content-Type(如返回 JSON)produces = "application/json"

2.3创建Spring项目

既然我们学习了该注解,那么就要想办法应用出来,所以我们们需要先创建一个Spring项目


在idea社区版装上Spring插件或者使用Spring专业版,创建项目时勾选:

接着导入SpringWeb相关模块:

这样就完成了Spring项目的创建。

2.4建立连接

下面我们在idea中建立连接:

package com.example.demo;import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class test1 {@RequestMapping("/hello")public String hello(){return "hello";}}

资源路径:类路径+方法路径。 


核心注解说明:

1. @RestController

  • 是 @Controller + @ResponseBody 的组合注解。

  • 作用

    • 标记这个类是一个控制器,能接收 HTTP 请求。

    • 所有方法的返回值会直接写入 HTTP 响应体(Response Body),而不是跳转到视图页面。

  • 适合场景:开发 RESTful API(返回 JSON/XML 数据)。

2. @RequestMapping("/hello")

  • 作用:将 HTTP 请求路径 /hello 映射到 hello() 方法。

  • 默认行为

    • 支持所有 HTTP 方法(GET、POST、PUT 等)。

    • 返回的字符串 "hello" 会直接作为响应内容返回给客户端。

当我们运行项目并在浏览器访问访问 http://localhost:8080/hello时: 

这样就代表连接成功。


如果注解相同,那么就必须保证资源路径(类路径+方法路径)不同: 

package com.example.demo;import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class test1 {@RequestMapping("/hello")public String hello(){return "hello";}@RequestMapping("/hello")public String hello1(String name){ return "hello" + name; }
}

项目直接启动报错并退出:

红线标注部分“error”就是错误日志了。

package com.example.demo;import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class test1 {@RequestMapping("/hello")public String hello(){return "hello";}@RequestMapping("/hello1")public String hello1(String name){ return "hello" + name; }
}

 这样即可正常运行:


2.5Postman

官网:Download Postman | Get Started for Freehttps://www.postman.com/downloads/

Postman是什么呢:

Postman 是一款API 开发与测试工具,被广泛用于设计、调试、测试和文档化 HTTP 接口。无论是后端开发者、测试工程师,还是前端开发者,都可以用它快速验证 API 的功能和可靠性。

  • 发送 HTTP 请求(GET/POST/PUT/DELETE 等)。

  • 自动化测试 API 接口。

  • 管理 API 集合(分类、分组、共享)。

  • 生成 API 文档。

  • 模拟服务器(Mock Server)。

  • 团队协作(共享工作区)。

页面看起来还是很清新的。


就还拿上一段代码来测试,第二个方法还有一个参数name,我们在Postman里可以快捷在请求中添加参数,注意参数名一定要相同。

发送成功。

3.小结

今天的分享到这里就结束了,喜欢的小伙伴点点赞点点关注,你的支持就是对我最大的鼓励,大家加油!


文章转载自:

http://FZB3iefD.rxxdk.cn
http://5pYe3ot9.rxxdk.cn
http://IdYCWOFB.rxxdk.cn
http://jSYAhHVb.rxxdk.cn
http://jNWrRO2q.rxxdk.cn
http://skZ8OpvB.rxxdk.cn
http://MzcIb3GU.rxxdk.cn
http://YSg4GxR3.rxxdk.cn
http://1IscPe6z.rxxdk.cn
http://xZ5OSkTY.rxxdk.cn
http://ipTasqr4.rxxdk.cn
http://12hbm4bQ.rxxdk.cn
http://lq8jRC8H.rxxdk.cn
http://4yPaOBPn.rxxdk.cn
http://LtahxFjz.rxxdk.cn
http://IHx9kFdj.rxxdk.cn
http://5Uaa1m9y.rxxdk.cn
http://5GQnNF7F.rxxdk.cn
http://EDpsZqof.rxxdk.cn
http://t7TUSrd0.rxxdk.cn
http://ALtO927P.rxxdk.cn
http://hTtwAECW.rxxdk.cn
http://3zJX4Ex1.rxxdk.cn
http://yjdMxR45.rxxdk.cn
http://v4VfnIqd.rxxdk.cn
http://UuQ6Iwxl.rxxdk.cn
http://UCwQ287q.rxxdk.cn
http://LTzwmwq9.rxxdk.cn
http://irmKs4cV.rxxdk.cn
http://elWGxhdi.rxxdk.cn
http://www.dtcms.com/wzjs/769467.html

相关文章:

  • 常熟有做网站的网络公司吗建设部网站白蚁文件
  • 网站建设】vs2015 做网站
  • 网站开发数据库郑州前端培训机构
  • 制作网站需要wordpress个人智慧团建网站
  • 网站竞价词怎么做网络营销实务技能训练题答案
  • 做网站的公司搞什么活动h5的制作步骤
  • 肇庆网站seo沾化网站建设
  • world做网站百度收录不到我的网站
  • 开源企业建站系统php网络设计包括
  • 北京冬奥会网站制作素材基因数据库网站建设
  • 网上购物有哪些网站?哈尔滨建设公示
  • 网站管理制度建设的必要性公司画册
  • 如何在微信公众号里建设微网站小精灵网站在线做语文
  • 关于域名用于非网站用途设计师 推荐 网站
  • 专业国外建设网站网站页面html静态化
  • 衡阳建设公司网站wordpress人体时钟
  • dremwear做网站电商网站业务流程图
  • 阿甘网站建设保定网站建设报价
  • 阿里云做网站要几天设计公司品牌介绍
  • 哪个建站软件比较好带论坛北京网站备案号查询
  • 免费学习资源网站设计投稿的网站有什么
  • dw做网站 怎么做背景图片张家口城乡建设局网站
  • 怎么做网站导航edunews wordpress
  • 金山区做网站吗企业展厅装修
  • 有服务器域名源码怎么做网站平台wordpress 安装主题
  • 网站目录结构 权限沈阳做网站费用
  • 海外建站平台成立公司需要多少费用
  • 电信开放81端口怎样做网站找建筑官网
  • 天津网站优化怎么样高端网站制作费用
  • 资讯网站手机网站模板今天热点新闻事件