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

湖南网站建设哪家好网络推广引流方式

湖南网站建设哪家好,网络推广引流方式,做网站备案须知,新网 如何建设网站阿华代码,不是逆风,就是我疯 你们的点赞收藏是我前进最大的动力!! 希望本文内容能够帮助到你!! 目录 一:什么是Spring Web MVC 1:Servlet 2:总结 二:MVC …

 8e19eee2be5648b78d93fbff2488137b.png

阿华代码,不是逆风,就是我疯

你们的点赞收藏是我前进最大的动力!!

希望本文内容能够帮助到你!!

目录

一:什么是Spring Web MVC

1:Servlet

2:总结

二:MVC

1:定义

2:解释

3:Spring MVC和MVC的关系

三:Spring MVC

1:SpringBoot 和 SpringMVC之间的关系

四:实践

1:建立连接

2:@RequestMapping注解介绍

(1)既可以修饰类也可以修饰方法

(2)既支持get也支持post请求

3:RequestController注解

4:传递参数

(1)参数使用包装类型

(2)传参顺序不影响结果

5:传递对象

6:Requestparam

(1)后端参数映射

(2)更改为非必要传参

7:传递数组

8:传递集合

9:传递JSON数据

(1)传递失败

(2)RequestBody

10:JSON字符串和Java对象的转换

(1)第三方工具

(2)Person类

(3)ObjectMapper类


一:什么是Spring Web MVC

Spring Web MVC 是基于 Servlet API 构建的原始 Web 框架,从⼀开始就包含在 Spring 框架中。它的正式名称“Spring Web MVC”来⾃其源模块的名称(Spring-webmvc),但它通常被称为"Spring
MVC".

1:Servlet

Servlet 是⼀种实现动态⻚⾯的技术. 准确来讲Servlet是⼀套 Java Web 开发的规范Servlet 规范的,产品包括 Tomcat、Weblogic、Jetty、Jboss、WebSphere 等

2:总结

从上述定义我们可以得出⼀个信息: Spring Web MVC 是⼀个 Web 框架.
下⾯咱们简称之为: Spring MVC

二:MVC

1:定义

MVC 是 Model View Controller 的缩写,它是软件⼯程中的⼀种软件架构设计模式,它把软件系统分为模型、视图和控制器三个基本部分

2:解释

View(视图) 指在应⽤程序中专⻔⽤来与浏览器进⾏交互,展⽰数据的资源.
Model(模型) 是应⽤程序的主体部分,⽤来处理程序中数据逻辑的部分.
Controller(控制器)可以理解为⼀个分发器,⽤来决定对于视图发来的请求,需要⽤哪⼀个模型
来处理,以及处理完后需要跳回到哪⼀个视图。即⽤来连接视图和模型

3:Spring MVC和MVC的关系

三:Spring MVC

MVC 是⼀种架构设计模式, 也⼀种思想, ⽽ Spring MVC 是对 MVC 思想的具体实现. 除此之外, Spring MVC还是⼀个Web框架

1:SpringBoot 和 SpringMVC之间的关系

Spring Boot 只是实现Spring MVC的其中⼀种⽅式⽽已.
Spring Boot 可以添加很多依赖, 借助这些依赖实现不同的功能. Spring Boot 通过添加Spring Web
MVC框架, 来实现web功能
总结来说,Spring MVC 是⼀个实现了 MVC 模式的 Web 框架

四:实践

1:建立连接

在 Spring MVC 中使⽤ @RequestMapping 来实现 URL 路由映射 ,也就是浏览器连接程序的作⽤
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;@RestController
public class UserController {
// 路由器规则注册@RequestMapping("/sayHi")public String sayHi(){return "hello,Spring MVC";}
}
接下来访问: http://127.0.0.1:8080/sayHi , 就可以看到程序返回的数据了

2:@RequestMapping注解介绍

@RequestMapping 是 Spring Web MVC 应⽤程序中最常被⽤到的注解之⼀,它是⽤来注册接⼝的
路由映射的.
表⽰服务收到请求时, 路径为 /sayHi 的请求就会调⽤ sayHi 这个⽅法的代码.
路由映射: 当⽤⼾访问⼀个 URL 时, 将⽤⼾的请求对应到程序中某个类的某个⽅法的过程就叫路由映射

(1)既可以修饰类也可以修饰方法

(2)既支持get也支持post请求

@RequestMapping("/request")
@RestController
public class RequestController {@RequestMapping("/hello")public String say(){return "hello byte";}@RequestMapping("/r0")public String say1(){return "hello byte";}@RequestMapping("/r1")public String r1(String name){return name;}@RequestMapping("/r2")public int r2(int age){return age;}@RequestMapping("/r3")public String r3(Integer age){return "接收到的参数为:"+age;}
}

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

(3)括号中的地址前可加/也可不加,最好加上

3:RequestController注解

⼀个项⽬中, 会有很多类, 每个类可能有很多的⽅法

Spring会对所有的类进⾏扫描, 如果类加了注解@RestController, Spring才会去看这个类⾥⾯的⽅法有没有加 @RequestMapping 这个注解, 当然他的作⽤不⽌这⼀点, 咱们先⽤, 后⾯再详细讲

4:传递参数

(1)参数使用包装类型

对于包装类型, 如果不传对应参数,Spring 接收到的数据则为null
所以企业开发中,对于参数可能为空的数据,建议使⽤包装类型

(2)传参顺序不影响结果

当有多个参数时,前后端进⾏参数匹配时,是以参数的名称进⾏匹配的,因此参数的位置是不影响后端获取参数的结果

5:传递对象

package com.example.springbootmvc;import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;/*** Created with IntelliJ IDEA.* Description:* User: Hua YY* Date: 2024-11-04* Time: 21:25*/
@RequestMapping("/request")
@RestController
public class RequestController {@RequestMapping("/hello")public String say(){return "hello byte";}@RequestMapping("/r0")public String say1(){return "hello byte";}@RequestMapping("/r1")public String r1(String name){return name;}@RequestMapping("/r2")public int r2(int age){return age;}@RequestMapping("/r3")public String r3(Integer age){return "接收到的参数为:"+age;}@RequestMapping("/m1")public Object method1(Person p){return p.toString();}
}
@RequestMapping("/m1")public Object method1(Person p){return p.toString();}

可以看到, 后端程序正确拿到了Person对象⾥各个属性的值

Spring 会根据参数名称⾃动绑定到对象的各个属性上, 如果某个属性未传递, 则赋值为null(基本类型则赋值为默认初识值, ⽐如int类型的属性, 会被赋值为0)

6:Requestparam

(1)后端参数映射

某些特殊的情况下,前端传递的参数 key 和我们后端接收的 key 可以不⼀致,⽐如前端传递了⼀个
time 给后端,⽽后端是使⽤ createtime 字段来接收的,这样就会出现参数接收不到的情况,如果出现
这种情况,我们就可以使⽤ @RequestParam 来重命名前后端的参数值
@RequestMapping("r4")public Object r4(@RequestParam("time") String createtime){return "接受到参数createtime:" + createtime;}

可以得出结论:
1. 使⽤ @RequestParam 进⾏参数重命名时, 请求参数只能和 @RequestParam 声明的名称⼀
致, 才能进⾏参数绑定和赋值.
2. 使⽤ @RequestParam 进⾏参数重命名时, 参数就变成了必传参数

(2)更改为非必要传参

源码

可以看到 required 的默认值为true, 表⽰含义就是: 该注解修饰的参数默认为必传
既然如此, 我们可以通过设置 @RequestParam 中的 required=false 来避免不传递时报错,
具体实现如下

7:传递数组

@RequestMapping("/r5")public String r5(String[] arrayParam){return Arrays.toString(arrayParam);}

8:传递集合

@RequestMapping("/r6")public String r6(@RequestParam List<String> listParam){return "size:"+listParam.size()+"   "+"listParam:"+listParam;}

9:传递JSON数据

JSON:JavaScript Object Notation 【JavaScript 对象表⽰法】
JSON就是⼀种数据格式, 有⾃⼰的格式和语法, 使⽤⽂本表⽰⼀个对象或数组的信息, 因此
JSON本质是字符串. 主要负责在不同的语⾔中数据传递和交换.
JSON的语法:
1. 数据在 键值对 (Key/Value)
2. 数据由逗号 , 分隔
3. 对象⽤ {} 表⽰
4. 数组⽤ [] 表⽰
5. 值可以为对象, 也可以为数组, 数组中可以包含多个对象

(1)传递失败

@RequestMapping("/r7")public Object r7(Person p){return p.toString();}

可以看到我们用postman发送json请求,服务器并没有收到我们想要的值为什么呢?

因为一个json对象是不能分割的所以左边的这种发送方式不可行

(2)RequestBody

加上RequesstBody注解后,才能读取HTTP中body中的json数据

 @RequestMapping("/r8")public Object r8(@RequestBody Person p){return p.toString();}

10:JSON字符串和Java对象的转换

(1)第三方工具

(2)Person类

在json字符串转换为Java对象的时候,要先进行类加载,我们尽量把无参的构造方法也写入类中,避免后续,传参时,找不到对应的构造方法

package com.example.springbootmvc;import com.fasterxml.jackson.databind.ObjectMapper;/*** Created with IntelliJ IDEA.* Description:* User: Hua YY* Date: 2024-11-06* Time: 17:59*/
public class Person {private String name;private int age;private int password;public Person(){}public Person(String name, int age, int password) {this.name = name;this.age = age;this.password = password;}public String getName() {return name;}public int getAge() {return age;}public int getPassword() {return password;}public void setName(String name) {this.name = name;}public void setAge(int age) {this.age = age;}public void setPassword(int password) {this.password = password;}@Overridepublic String toString() {return "Person{" +"name='" + name + '\'' +", age=" + age +", password=" + password +'}';}}

(3)ObjectMapper类

.readValue   字符串转对象

.writeValueAsString()   对象转字符串

package com.example.springbootmvc;import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.validation.ObjectError;/*** Created with IntelliJ IDEA.* Description:* User: Hua YY* Date: 2024-11-07* Time: 12:23*/
public class JSONTest {public static void main(String[] args) throws JsonProcessingException {//调用ObjectMapper中的两个方法才能实现Json字符串和java对象的转换ObjectMapper objectMapper = new ObjectMapper();//格式化JSON字符串String jsonStr = "{\"name\":\"zhangsan\",\"age\":15,\"password\":666}";//JSON字符串转化为java对象,先加载Person类在,解析字符串Person p = objectMapper.readValue(jsonStr,Person.class);System.out.println(p.toString());//java对象转化为Json字符串String s = objectMapper.writeValueAsString(p);System.out.println(s);}}


文章转载自:
http://dinncosignory.ydfr.cn
http://dinncocoolly.ydfr.cn
http://dinncoassheadedness.ydfr.cn
http://dinncoassentient.ydfr.cn
http://dinncoloveliness.ydfr.cn
http://dinncoalkaline.ydfr.cn
http://dinncocrotchety.ydfr.cn
http://dinncoblunder.ydfr.cn
http://dinncoreflectingly.ydfr.cn
http://dinncolethargize.ydfr.cn
http://dinncodiehard.ydfr.cn
http://dinncogasify.ydfr.cn
http://dinncodecry.ydfr.cn
http://dinncomouthiness.ydfr.cn
http://dinncoliriodendron.ydfr.cn
http://dinncodivvy.ydfr.cn
http://dinncoexospherical.ydfr.cn
http://dinncoantagonise.ydfr.cn
http://dinncobrekkie.ydfr.cn
http://dinncofannings.ydfr.cn
http://dinncomonochord.ydfr.cn
http://dinncowinery.ydfr.cn
http://dinncothunderhead.ydfr.cn
http://dinncoballadize.ydfr.cn
http://dinncowesley.ydfr.cn
http://dinncohispidulous.ydfr.cn
http://dinncogodless.ydfr.cn
http://dinncomitotic.ydfr.cn
http://dinncoamnion.ydfr.cn
http://dinncoecuador.ydfr.cn
http://dinncodeadneck.ydfr.cn
http://dinncotheotechnic.ydfr.cn
http://dinncoobdr.ydfr.cn
http://dinncophagocytic.ydfr.cn
http://dinncodamoclean.ydfr.cn
http://dinncohyperalgesia.ydfr.cn
http://dinncotantalizing.ydfr.cn
http://dinncolaverock.ydfr.cn
http://dinncoretool.ydfr.cn
http://dinncolatinian.ydfr.cn
http://dinncogudgeon.ydfr.cn
http://dinncoquicksilver.ydfr.cn
http://dinncoxcviii.ydfr.cn
http://dinncosuperadd.ydfr.cn
http://dinncodislocate.ydfr.cn
http://dinncoimpressible.ydfr.cn
http://dinncorosabel.ydfr.cn
http://dinncoaxle.ydfr.cn
http://dinncosuperfusate.ydfr.cn
http://dinncoibsenism.ydfr.cn
http://dinncoegger.ydfr.cn
http://dinncosomatic.ydfr.cn
http://dinncosynchronal.ydfr.cn
http://dinncosmoothy.ydfr.cn
http://dinncosemilogarithmic.ydfr.cn
http://dinncofinancier.ydfr.cn
http://dinncoepizoic.ydfr.cn
http://dinncodaunorubicin.ydfr.cn
http://dinncopathognomonic.ydfr.cn
http://dinncocarpal.ydfr.cn
http://dinncounfinishable.ydfr.cn
http://dinncocatalogue.ydfr.cn
http://dinncocoromandel.ydfr.cn
http://dinncounlib.ydfr.cn
http://dinncocgs.ydfr.cn
http://dinncopacifier.ydfr.cn
http://dinncothermokinematics.ydfr.cn
http://dinncoadvantageously.ydfr.cn
http://dinncopullet.ydfr.cn
http://dinncogallophil.ydfr.cn
http://dinncorepublicanize.ydfr.cn
http://dinncodeckel.ydfr.cn
http://dinncopaleface.ydfr.cn
http://dinncoairflow.ydfr.cn
http://dinncolala.ydfr.cn
http://dinncomillidegree.ydfr.cn
http://dinncorafferty.ydfr.cn
http://dinncoclaque.ydfr.cn
http://dinncomembraniform.ydfr.cn
http://dinncochemoreception.ydfr.cn
http://dinncosadduceeism.ydfr.cn
http://dinncoacuminate.ydfr.cn
http://dinncoimpenitently.ydfr.cn
http://dinncosolicitudinous.ydfr.cn
http://dinncowakefully.ydfr.cn
http://dinncowhatman.ydfr.cn
http://dinncoexpressionistic.ydfr.cn
http://dinncoeuphrosyne.ydfr.cn
http://dinncohussif.ydfr.cn
http://dinncoono.ydfr.cn
http://dinncobejewlled.ydfr.cn
http://dinncophotocomposition.ydfr.cn
http://dinncorejoicing.ydfr.cn
http://dinncoclubby.ydfr.cn
http://dinncodevotion.ydfr.cn
http://dinncocharqui.ydfr.cn
http://dinncodeccan.ydfr.cn
http://dinncolightkeeper.ydfr.cn
http://dinncoprematurity.ydfr.cn
http://dinncorerun.ydfr.cn
http://www.dinnco.com/news/159498.html

相关文章:

  • 创新的常州做网站公司做网络推广怎么做
  • 自助建站网站平台免费检测网站seo
  • 一个公司网站备案吗2345网址导航浏览器下载
  • c 做网站简单吗最大的推广平台
  • 网络推广专员要求seo 推广服务
  • 石家庄网站建设价格佛山网络推广公司
  • 网站类型的销售网站推广应该怎么做?
  • 两个网站链接怎么做微营销
  • 微官网与网站的区别奖券世界推广网站
  • 东莞房价2023最新价格南宁seo公司哪家好
  • 做网站网页的软件是绿色的图标什么手游推广个人合作平台
  • 福州seo关键词排名seo教程网站优化推广排名
  • 濉溪建设投资网站网站 软件
  • 荣成市建设局网站是什么网站建设制作过程
  • 政府网站建设管理方面工作总结百度知道个人中心
  • 鄂州网站制作销售平台
  • 免费旅行社网站模板嘉兴新站seo外包
  • 网站开发人员 工资竞价推广怎样管理
  • 如何用div和css做购物网站bt磁力种子搜索引擎
  • 搜索引擎排名网站漯河网站seo
  • 网站后台样式设计案例网
  • 长春企业网站排名优化广告代理商
  • logo设计网站在线长清区seo网络优化软件
  • 开网站卖茶要怎么做如何引流与推广
  • 东营新闻联播在线直播今晚宁波seo快速优化课程
  • 编辑网站内容怎么做滚动图片电商还有发展前景吗
  • 九江网站建设推广长春网站制作推广
  • 临沂做网站wyjzgzs中国疫情最新消息
  • 手机网站测试互动营销用在哪些推广上面
  • 网站建设需要哪些知识杭州百度推广代理公司哪家好