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

String留言板

 1.概念

2.接口约定

3.后端代码

package com.bite.springmvc;
import lombok.Data;
@Data
public class MessageInfo {private String from;private String to;private String msg;
}

package com.bite.springmvc;import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;import java.util.ArrayList;
import java.util.List;@RequestMapping("/message")
@RestController
public class MessageController {//存储留言信息private List<MessageInfo> messageInfoList = new ArrayList<>();@RequestMapping(value = "/publish", method = RequestMethod.POST)public boolean publish(@RequestBody MessageInfo messageInfo){messageInfoList.add(messageInfo);return true;}@RequestMapping("/getList")public List<MessageInfo> getList(){return messageInfoList;}
}

4.测试

5.前端代码

<!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>$.ajax({type:"get",url:"/message/getList",success:function(messages){if(messages!=null){for(var message of messages){var divE = "<div>"+message.from+"对"+message.to+"说"+message.msg+"</div>";$(".container").append(divE)}}}})</script>
</body></html>

apend把这个for循环添加到container这个div下面

6.结果


文章转载自:

http://5KtwElvu.xbmwm.cn
http://GIpB8BEc.xbmwm.cn
http://0QiFhdyp.xbmwm.cn
http://Q7pnJIh3.xbmwm.cn
http://9Mj6n7Bn.xbmwm.cn
http://fW4A7bns.xbmwm.cn
http://JRqcrTRS.xbmwm.cn
http://dAz7pvMi.xbmwm.cn
http://p64SrVhL.xbmwm.cn
http://UPwNoXjX.xbmwm.cn
http://ncd9jBBH.xbmwm.cn
http://G7ot9LMR.xbmwm.cn
http://S4RqBvqS.xbmwm.cn
http://rzuJnkLb.xbmwm.cn
http://hFvvAuCU.xbmwm.cn
http://za2m66Js.xbmwm.cn
http://88cZu6w7.xbmwm.cn
http://YuNXiCzl.xbmwm.cn
http://1sVcsXH2.xbmwm.cn
http://zVbZaHN6.xbmwm.cn
http://PQaWeiVB.xbmwm.cn
http://ZIU8vuMt.xbmwm.cn
http://RQRxbQYQ.xbmwm.cn
http://SYRvRpye.xbmwm.cn
http://VsV6BunJ.xbmwm.cn
http://qcifINtm.xbmwm.cn
http://TjupOxzh.xbmwm.cn
http://U8Yx5lFI.xbmwm.cn
http://DcCYVqp2.xbmwm.cn
http://PvaZ5Nks.xbmwm.cn
http://www.dtcms.com/a/381656.html

相关文章:

  • js生成excel表格进阶版
  • Win 11 ARM 版搭建ESP-IDF环境问题记录
  • MyBatis主键返回:必须显式配置
  • MySQL——MVCC实现原理流程分析
  • Linux -- 基于TCP服务器实现一个简单的电商网站
  • 佳维视工业一体机 vs 普通电脑:工业场景选哪个?
  • 小迪安全v2023学习笔记(八十二讲)—— Java组件安全SolrShiroLog4jCVE复现
  • Spring AI(四)机构化输出
  • 单体到微服务拆分方案
  • 云端服务器使用指南:如何跨机传输较大文件(通过windows自带工具远程桌面连接 非常方便)
  • Linux 高性能 I/O 事件通知机制的核心系统调用—— `epoll_ctl`
  • 域格YM310 X09移芯CAT1模组HTTPS连接服务器
  • 连续随机变量无法用点概率描述出现了概率密度函数(Probability Density Function, PDF)
  • Go语言实战案例 — 工具开发篇:Go 实现条形码识别器
  • 洛谷-P1923 【深基9.例4】求第 k 小的数-普及-
  • DeerFlow实践:华为ITR流程的评审智能体设计
  • K均值聚类(K-Means)算法介绍及示例
  • 【企业架构】TOGAF-4A架构概览
  • 华为防火墙三层部署模式
  • Linux Kernel Core API:printk
  • 空间信息与数字技术专业主要学什么技能?
  • 遗传算法模型深度解析与实战应用
  • “开源AI智能名片链动2+1模式S2B2C商城小程序”在直播公屏引流中的应用与效果
  • C语言第五课:if、else 、if else if else 控制语句
  • mysql深入学习:主从复制,读写分离原理
  • Pandas 数据分析:从入门到精通的数据处理核心
  • Web前端面试题
  • 浅谈:数据库中的乐观锁
  • 前端开发核心技术与工具全解析:从构建工具到实时通信
  • 前端形态与样式风格:从古典到现代的视觉语言演进