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

ps做分享类网站效果图海南网站设计

ps做分享类网站效果图,海南网站设计,关于门户网站建设工作情况汇报,有后台管理系统网站管理基础项目:留言板 截止到目前为止,我们已经学习了 Spring(只学习了DI)、Spring MVC、SpringBoot、Mybatis 这些知识了,已经满足了做简单项目的基本要求了,所以接下来我们就从0到1实现表白墙项目。 需求分析…

基础项目:留言板

截止到目前为止,我们已经学习了 Spring(只学习了DI)、Spring MVC、SpringBoot、Mybatis 这些知识了,已经满足了做简单项目的基本要求了,所以接下来我们就从0到1实现表白墙项目。

需求分析:实现一个简单的表白墙,用户访问表白墙页面时,可以在输入框中输出 from、to、message的基本信息,然后点击发送按钮就可以将信息提交到表白墙上。

数据库设计:需要一个存放留言信息的数据表,基本字段:id、from、to、message、delete_flag、create_time、update_time。

后端接口:只需要提供两个接口给前端,一个是提交留言的接口,另一个是获取留言信息的接口。
效果预览

不了解的可以去我之前文章观看基础版本的留言板

[SpringBoot]Spring MVC(5.0)----留言板_springboot留言功能-CSDN博客

思路

我们需要在数据库中保存一条一条的消息,那就需要一个类

@Data
public class MessageInfo {private Integer id;private String from; //谁留言private String to; //留言对谁说private String message; //留言的内容private Integer deleteFlag; //删除的标志private Date createTime;private Date updateTime;
}

主体要实现两个功能:发布留言、查看所有留言

1.引入依赖以及配置文件:

spring:datasource:url: jdbc:mysql://127.0.0.1:3306/mybatis_test?characterEncoding=utf8&useSSL=falseusername: rootpassword: 123456driver-class-name: com.mysql.cj.jdbc.Driver
mybatis:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImplmap-underscore-to-camel-case: true 

2.写 Mapper 接口

package com.example.demo.mapper;import com.example.demo.model.MessageInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper
public interface MessageInfoMapper {@Select("select `id`, `from`, `to`, `message` from message_info where delete_flag=0")List<MessageInfo> queryAll();@Insert("insert into message_info (`from`,`to`, `message`) values(#{from},#{to},#{message})")Integer addMessage(MessageInfo messageInfo);
}

接下来写 Service,调用接口那两个方法就 ok 了:

package com.example.demo.service;import com.example.demo.mapper.MessageInfoMapper;
import com.example.demo.model.MessageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class MessageInfoService {@Autowiredprivate MessageInfoMapper messageInfoMapper;public List<MessageInfo> queryAll() {return messageInfoMapper.queryAll();}public Integer addMessage(MessageInfo messageInfo) {return messageInfoMapper.addMessage(messageInfo);}
}

再来写 Controller 实现接口中的方法


import com.example.demo.model.MessageInfo;
import com.example.demo.service.MessageInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RequestMapping("/message")
@RestController
public class MessageController {@Autowiredprivate MessageInfoService messageInfoService;@RequestMapping("/getList")public List<MessageInfo> getList() {return messageInfoService.queryAll();}@RequestMapping("/publish")public boolean publish(MessageInfo messageInfo) {System.out.println(messageInfo);if (StringUtils.hasLength(messageInfo.getFrom()) && StringUtils.hasLength(messageInfo.getTo()) && StringUtils.hasLength(messageInfo.getMessage())) {messageInfoService.addMessage(messageInfo);return true;}return false;}}

最后就是书写前端代码,对我们后端开发来说,前端代码还是需要好好练习的

<!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({url: "/message/getList",type: "get",success: function(result) {if(result!=null&&result.length>0) {for(x of result) {var divE = "<div>"+x.from+ "对" + x.to + "说:" + x.message + "</div>";$(".container").append(divE);}}}});function submit() {$.ajax({url: "/message/publish",type: "post",data: {from: $("#from").val(),to: $("#to").val(),message: $("#say").val()},//http响应成功success:function(result) {if(result == false) {alert("输入不合法");}else {//展示信息//1. 构造节点// 修正:使用 jQuery 选择器获取输入值var divE = "<div>"+$("#from").val()+ "对" + $("#to").val() + "说:" + $("#say").val() + "</div>";//2. 把节点添加到页面上$(".container").append(divE);//3. 清空输入框的值$("#from").val("");$("#to").val("");$("#say").val("");}}});}</script>
</body></html>

我们这里主要是对一些内容的修改,因为我们之前用的Say,而现在用的message,这里我们就需要知道,哪里是前端的属性,哪里是后端实体类的属性

前端:id,以及data后面$(#"")的内容

后端:取自后端返回结果的内容以及data后面被赋值的部分

 这样,一个留言板就实现了,它可以与数据库链接,有了持久性

http://www.dtcms.com/wzjs/145797.html

相关文章:

  • 网站建设公司知道万维科技湖南seo网站策划
  • 网站架构教程排名sem优化软件
  • 阿里巴巴怎么做不花钱的网站优化精灵
  • 东莞seo网站优化方式关键词投放
  • 有没有专门做化妆品小样的网站网络营销公司名字
  • 个人怎么做微信公众号和微网站吗我赢网客服系统
  • wordpress企业中文主题下载宁波seo网络推广
  • 黔南服务好的高端网站设计公司网站维护工作内容
  • 池州网站建设公司收录批量查询
  • 炫酷的电商网站设计拓客团队怎么联系
  • centos做网站服务器吗优化排名推广教程网站
  • 简述网站建设在作用seo网站优化培训
  • 萍乡网站建设公司免费网络推广渠道
  • 怎么做汽车网站宁波seo外包引流推广
  • 长沙网站设计优秀柚v米科技郑州今日头条
  • 邢台建网站找谁seo是对网站进行什么优化
  • 做空闲时间的网站网站关键词排名快速提升
  • 广州网页设计html整站优化cms
  • 好看的ui网站页面设计做网站的费用
  • 杭州市萧山区哪家做网站的公司好如何做好线上推广和引流
  • 住建网查询资质seo网站运营
  • 阿里云虚拟主机怎么建立网站b站2020推广网站
  • 政府门户网站源码自制网页
  • 网站制作团队靠谱的拉新平台
  • 为什么做的网站有的有弹窗有的没有郑州网站建设哪家好
  • 用asp.net做购物网站百度关键词优化和百度推广
  • 欧美做暧网站东莞网站建设工作
  • 江西建设厅特殊工种的网站友情链接怎么添加
  • 河南省级住房城乡建设主管部门网站百度推广助手官方下载
  • 做百度移动网站seo团队