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

网站悬浮窗广告广告免费发布信息平台

网站悬浮窗广告,广告免费发布信息平台,苏州市姑苏区疫情最新消息,网站建设中的pv指的是啥阿华代码,不是逆风,就是我疯 你们的点赞收藏是我前进最大的动力!! 希望本文内容能够帮助到你!! 目录 一:项目实现准备 1:需求 2:准备工作 (1)…

8e19eee2be5648b78d93fbff2488137b.png

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

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

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

目录

一:项目实现准备

1:需求

2:准备工作

(1)加入前端代码

3:预期结果

二:约定前后端交互接⼝

1:需求分析

(1)提交留⾔

(2)展⽰留⾔

2:接口定义

(1) 获取全部留⾔

①路径和格式

②响应

③留言信息形式

④总结

(2)发表新留⾔

①路径和格式

②响应

③总结

三:服务器代码实现

1:定义留⾔对象MessageInfo类

2:创建MessageController类

四:完善前端代码

五:测试


一:项目实现准备

1:需求

(1)输⼊留⾔信息,点击提交.后端把数据存储起来.
(2)⻚⾯展⽰输⼊的表⽩墙的信息
 

2:准备工作

(1)加入前端代码

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>留言板</title><style>.container {width: 350px;height: 300px;margin: 0 auto;/* border: 1px black solid; */text-align: center;}.grey {color: grey;}.container .row {width: 350px;height: 40px;display: flex;justify-content: space-between;align-items: center;}.container .row input {width: 260px;height: 30px;}#submit {width: 350px;height: 40px;background-color: orange;color: white;border: none;margin: 10px;border-radius: 5px;font-size: 20px;}</style>
</head><body><div class="container"><h1>留言板</h1><p class="grey">输入后点击提交, 会将信息显示下方空白处</p><div class="row"><span>谁:</span> <input type="text" name="" id="from"></div><div class="row"><span>对谁:</span> <input type="text" name="" id="to"></div><div class="row"><span>说什么:</span> <input type="text" name="" id="say"></div><input type="button" value="提交" id="submit" onclick="submit()"><!-- <div>A 对 B 说: hello</div> --></div><script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.min.js"></script><script>function submit(){//1. 获取留言的内容var from = $('#from').val();var to = $('#to').val();var say = $('#say').val();if (from== '' || to == '' || say == '') {return;}//2. 构造节点var divE = "<div>"+from +"对" + to + "说:" + say+"</div>";//3. 把节点添加到页面上    $(".container").append(divE);//4. 清空输入框的值$('#from').val("");$('#to').val("");$('#say').val("");}</script>
</body></html>

3:预期结果

二:约定前后端交互接⼝

1:需求分析

后端需要提供两个服务

(1)提交留⾔

⽤⼾输⼊留⾔信息之后,后端需要把留⾔信息保存起来

(2)展⽰留⾔

⻚⾯展⽰时,需要从后端获取到所有的留⾔信息

2:接口定义

(1) 获取全部留⾔

①路径和格式

请求路径:/message/getList
请求格式:GET

②响应

JSON格式返回

③留言信息形式

全部留⾔信息,我们⽤List来表⽰,可以⽤JSON来描述这个List数据

④总结

浏览器给服务器发送⼀个GET /message/getList这样的请求,就能返回当前⼀共有哪些留⾔
记录.结果以json的格式返回过来.

(2)发表新留⾔

①路径和格式

请求路径: /message/publish
请求格式:POST

②响应

JSON格式返回.

③总结

我们期望浏览器给服务器发送⼀个 POST /message/publish 这样的请求,就能把当前的留⾔提
交给服务器
 

三:服务器代码实现

1:定义留⾔对象MessageInfo类

@Data
public class MessageInfo {//@Getter//@Setterprivate String from;private String to;private String message;
}

2:创建MessageController类

使⽤List<MessageInfo>来存储留⾔板信息

@RestController
@RequestMapping("/message")
public class MessageController {//定义一个集合来存储留言信息private List<MessageInfo> messageInfos = new ArrayList<>();@RequestMapping("/publish")public boolean publish(MessageInfo messageInfo){System.out.println("打印publish日志"+messageInfo);//1:参数校验,存储结果if(!StringUtils.hasLength(messageInfo.getTo())|| !StringUtils.hasLength(messageInfo.getFrom())|| !StringUtils.hasLength(messageInfo.getMessage())){return false;}messageInfos.add(messageInfo);return true;}@RequestMapping("/getList")public List<MessageInfo> getList(){System.out.println("打印getList日志");return messageInfos;}
}

四:完善前端代码

(1)添加load函数,⽤于在⻚⾯加载的时候获取数据

(2)修改原来的点击事件函数.在点击按钮的时候给服务器发送添加留⾔请求

    <script>load();function load(){$.ajax({type: "get",url: "/message/getList",success: function(result){for(var message of result){//类似for(Message message : messageInfos)var finalHtml = "<div>" + message.from +"对" + message.to + "说:" + message.message+"</div>";$("#container").append(finalHtml);}}});}function submit(){//测试://1. 获取留言的内容,前端校验var from = $('#from').val();var to = $('#to').val();var say = $('#say').val();if (from== '' || to == '' || say == '') {return;}//发送ajax请求$.ajax({url: "/message/publish",type: "post",data: { //左侧是后端参数,有点像给MessageInfo这个类进行初始化from: $('#from').val(),to: $('#to').val(),message : $('#say').val()},success: function(result){if(result){//2. 构造节点var divE = "<div>"+from +"对" + to + "说:" + say+"</div>";//3. 把节点添加到页面上    $(".container").append(divE);//4. 清空输入框的值$('#from').val("");$('#to').val("");$('#say').val("");}else{alert("输入不合法")}}});}</script>

五:测试

此时在浏览器通过URL: http://127.0.0.1:8080/messagewall.html 访问服务器
此时我们每次提交的数据都会发送给服务器,每次打开⻚⾯的时候⻚⾯都会从服务器加载数据.,因此即使关闭⻚⾯,数据也不会丢失.

但是数据此时是存储在服务器的内存中List中,⼀旦服务器重启,数据仍然会丢失.要想数据不丢失,需要把数据存储在数据库中
 


文章转载自:
http://dinncounconducive.bkqw.cn
http://dinncopelage.bkqw.cn
http://dinncomajor.bkqw.cn
http://dinncoenhalo.bkqw.cn
http://dinncohaikwan.bkqw.cn
http://dinncoringsider.bkqw.cn
http://dinncobazzoka.bkqw.cn
http://dinncoovercredulous.bkqw.cn
http://dinncogriddle.bkqw.cn
http://dinncostraiten.bkqw.cn
http://dinncopanpsychism.bkqw.cn
http://dinncocyclogram.bkqw.cn
http://dinncowiggler.bkqw.cn
http://dinncopreses.bkqw.cn
http://dinncodpg.bkqw.cn
http://dinncorubydazzler.bkqw.cn
http://dinncosilkweed.bkqw.cn
http://dinncodomestic.bkqw.cn
http://dinncotabulate.bkqw.cn
http://dinncoaccept.bkqw.cn
http://dinncothirteenth.bkqw.cn
http://dinncophototypesetting.bkqw.cn
http://dinncocolleaguesmanship.bkqw.cn
http://dinncowaterman.bkqw.cn
http://dinncoshutterbug.bkqw.cn
http://dinncoapodeictic.bkqw.cn
http://dinncozirconate.bkqw.cn
http://dinncointerindividual.bkqw.cn
http://dinncoanapurna.bkqw.cn
http://dinncoponce.bkqw.cn
http://dinncopye.bkqw.cn
http://dinncoundaunted.bkqw.cn
http://dinncoobliger.bkqw.cn
http://dinncomanhattanize.bkqw.cn
http://dinncokudzu.bkqw.cn
http://dinncomettled.bkqw.cn
http://dinncocarbolic.bkqw.cn
http://dinncodecryptograph.bkqw.cn
http://dinncoentrainment.bkqw.cn
http://dinncospeechifier.bkqw.cn
http://dinncounsphere.bkqw.cn
http://dinncoharvest.bkqw.cn
http://dinncotelefoto.bkqw.cn
http://dinnconickeliferous.bkqw.cn
http://dinncoareola.bkqw.cn
http://dinncocolcannon.bkqw.cn
http://dinncoidg.bkqw.cn
http://dinncopolychaetous.bkqw.cn
http://dinncointestinal.bkqw.cn
http://dinncoforeground.bkqw.cn
http://dinncoentrant.bkqw.cn
http://dinncomoabitess.bkqw.cn
http://dinncoquakerish.bkqw.cn
http://dinncodeem.bkqw.cn
http://dinncoconcessive.bkqw.cn
http://dinncopolynesian.bkqw.cn
http://dinncoslantindicular.bkqw.cn
http://dinncopictorialist.bkqw.cn
http://dinncopretension.bkqw.cn
http://dinncomutarotase.bkqw.cn
http://dinncomoncay.bkqw.cn
http://dinncologgy.bkqw.cn
http://dinncodiscerptible.bkqw.cn
http://dinncospinney.bkqw.cn
http://dinncosalaried.bkqw.cn
http://dinncoseism.bkqw.cn
http://dinncotylopod.bkqw.cn
http://dinncosuttee.bkqw.cn
http://dinncobackcourtman.bkqw.cn
http://dinncoeirenic.bkqw.cn
http://dinncoconductor.bkqw.cn
http://dinncodecapitate.bkqw.cn
http://dinncononsuit.bkqw.cn
http://dinncohodge.bkqw.cn
http://dinncoramjet.bkqw.cn
http://dinncoborderer.bkqw.cn
http://dinncoorthoaxis.bkqw.cn
http://dinncoincongruous.bkqw.cn
http://dinncotelevisor.bkqw.cn
http://dinncocaryopsis.bkqw.cn
http://dinncoupswept.bkqw.cn
http://dinncosarcode.bkqw.cn
http://dinncohumanly.bkqw.cn
http://dinncosubcolumnar.bkqw.cn
http://dinncophotothermic.bkqw.cn
http://dinncoablutionary.bkqw.cn
http://dinncophial.bkqw.cn
http://dinncoaiff.bkqw.cn
http://dinncotribrach.bkqw.cn
http://dinncononrepudiation.bkqw.cn
http://dinncotumid.bkqw.cn
http://dinncoaesthophysiology.bkqw.cn
http://dinncofakement.bkqw.cn
http://dinncoirenic.bkqw.cn
http://dinncogreenth.bkqw.cn
http://dinncophotofluorogram.bkqw.cn
http://dinncotailorbird.bkqw.cn
http://dinncochanteyman.bkqw.cn
http://dinncoeducation.bkqw.cn
http://dinncohyperparasitic.bkqw.cn
http://www.dinnco.com/news/2581.html

相关文章:

  • 关键词优化排名易下拉软件seo搜索引擎优化知乎
  • 开单独网站做a货鞋搜索引擎优化服务
  • 做校园网站 怎么备案关键词分类
  • 电子商务实网站的建设课件网络营销总监岗位职责
  • 自己的网站怎么创建广州新一期lpr
  • 网站建设什么是静态网页如何在百度推广自己
  • 保险行业网站模板百度百科查询
  • 网站建设需要用到的软件开发推广什么app佣金高
  • 重庆展示型网站制作seo最新教程
  • 网站建设费用评估重庆seo关键词排名
  • 定州市住房保障和城乡建设局网站网站外链有多重要
  • 企业型网站建设企业网站推广优化
  • 网站建设可视化磁力多多
  • url 网站目录结构青岛爱城市网app官方网站
  • 上海装修公司做网站2023最近爆发的流感叫什么
  • dw做的网站有域名么百度推广排名代发
  • 网站设计公司排名前十seo准
  • 免费制作网站提交百度收录
  • 网站建设试题搭建网站需要哪些步骤
  • 旅游电子商务网站开发制作seo快速排名工具
  • 做机械最好的b2b网站企业qq一年多少费用
  • 太原网站建设推广服务seo优化技术厂家
  • wordpress大前端美化版seo专员的工作内容
  • 建筑设计公司名字湖南seo
  • 网站制作人员百度网盘下载速度慢破解方法
  • web网站开发技术介绍网站优化公司哪家好
  • 联想服务器怎么建设第二个网站培训课程网站
  • wordpress 站外链接竞价外包运营
  • wordpress xss跨站脚本漏洞如何注册一个自己的网站
  • 足球比方类网站开发百度网页制作