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

怎么上线网站网络营销品牌推广

怎么上线网站,网络营销品牌推广,企业网站建设进度,word还是wordpress目录 1. 添加依赖 2. 配置数据库 2.1 创建数据库与数据表 2.2 创建与数据库对应的实体类 3. 后端代码 3.1 目录结构 3.2 MessageController类 3.3 MessageService类 3.4 MessageMapper接口 4. 前端代码 5. 单元测试 5.1 后端接口测试 5.2 使用前端页面测试 在Spri…

目录

1. 添加依赖

2. 配置数据库

2.1 创建数据库与数据表

2.2 创建与数据库对应的实体类

3. 后端代码

3.1 目录结构

3.2 MessageController类

3.3 MessageService类

3.4 MessageMapper接口

4. 前端代码

5. 单元测试

5.1 后端接口测试

5.2 使用前端页面测试


在Spring专栏中,已经实现了Spring MVC版的留言墙,详见下文:

【SpringMVC】_SpringMVC实现留言墙_使用springmvc完成一个简单的留言板-CSDN博客文章浏览阅读994次,点赞24次,收藏17次。1、请求:/message/publish2、参数:使用对象MessageInfo进行存储参数:3、响应:true/false;_使用springmvc完成一个简单的留言板 https://blog.csdn.net/m0_63299495/article/details/139359758该版本的消息存储采用了List<MessageInfo>存储,每次重启服务器就会导致信息丢失。

本文基于上文,对表白墙系统进行持久化。

1. 添加依赖

在pom.xml文件中使用Alt+insert快捷键,在EditStarters中选择MyBatis与Mysql的相关依赖:

并在maven面板中进行刷新;

2. 配置数据库

2.1 创建数据库与数据表

创建数据库,名为message:

在该库下创建messgae_info数据表:

CREATE TABLE `message_info` (
`id` INT ( 11 ) NOT NULL AUTO_INCREMENT,
`from` VARCHAR ( 127 ) NOT NULL,
`to` VARCHAR ( 127 ) NOT NULL,
`message` VARCHAR ( 256 ) NOT NULL,
`delete_flag` TINYINT ( 4 ) DEFAULT 0 COMMENT '0-正常, 1-删除',`create_time` DATETIME DEFAULT now(),`update_time` DATETIME DEFAULT now() ON UPDATE now(),
PRIMARY KEY ( `id` ) 
) ENGINE = INNODB DEFAULT CHARSET = utf8mb4;

在application.yml中进行数据库与MyBatis的相关配置:

# 端口配置
server:port: 8080
# 数据库连接配置
spring:datasource:url: jdbc:mysql://127.0.0.1:3306/message?characterEncoding=utf8&useSSL=falseusername: rootpassword: xxxxxxdriver-class-name: com.mysql.cj.jdbc.Driver
mybatis:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImpl  #配置打印MyBatis日志map-underscore-to-camel-case: true   #配置转换驼峰

2.2 创建与数据库对应的实体类

修改MessageInfo类,增加id、deleteFlag、createTime、uodateTime属性与数据表字段对应:

package com.example.springbootdemo2.controller;import lombok.Data;
import java.util.Date;@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;
}

3. 后端代码

3.1 目录结构

创建controller、service、mapper、model包,并创建对应类或接口:

其中,MessageController类主要功能:

(1)参数校验;(2)调用MessageService进行业务逻辑操作;

MessageService类主要功能:

(1)调用MessageMapper接口进行数据库操作;

MessageMapper接口主要功能:

(1)执行SQL语句;

3.2 MessageController类

package com.example.springbootdemo2.controller;import com.example.springbootdemo2.model.MessageInfo;
import com.example.springbootdemo2.service.MessageService;
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.ArrayList;
import java.util.List;// 新增留言
@RequestMapping("/message")
@RestController
public class MessageController {@Autowiredprivate MessageService messageService;@RequestMapping("/publish")public Boolean publishMessage(MessageInfo messageInfo){// 参数校验:Controllerif(!StringUtils.hasLength(messageInfo.getFrom())|| !StringUtils.hasLength(messageInfo.getTo())|| !StringUtils.hasLength(messageInfo.getMessage())){return false;}// 添加留言:ServicemessageService.addMessage(messageInfo);return true;}// 返回所有留言信息@RequestMapping("/getMessageList")public List<MessageInfo> getMessageList(){return messageService.getMessageInfo();}
}

3.3 MessageService类

package com.example.springbootdemo2.service;import com.example.springbootdemo2.mapper.MessageMapper;
import com.example.springbootdemo2.model.MessageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.List;@Service
public class MessageService {@Autowiredprivate MessageMapper messageMapper;public void addMessage(MessageInfo messageInfo){messageMapper.insertMessage(messageInfo);}public List<MessageInfo> getMessageInfo(){return messageMapper.selectAllMessage();}
}

3.4 MessageMapper接口

package com.example.springbootdemo2.mapper;import com.example.springbootdemo2.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 MessageMapper {@Insert("insert into message_info(`from`,`to`,`message`) values (#{from},#{to},#{message})")void insertMessage(MessageInfo messageInfo);@Select("select* from message_info where delete_flag=0")List<MessageInfo> selectAllMessage();
}

4. 前端代码

<!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/getMessageList",type:"get",success:function(messages){// 参数为后端返回结果(变量名任意)for(var m of messages){// 拼接留言// 拼接节点的HTML,直接将HTML添加到container中var divE = "<div>" + m.from + "对" + m.to + "说:" + m.message + "</div>";// 把节点添加到页面上$(".container").append(divE);}}})function submit() {//1. 获取留言的内容var from = $('#from').val();var to = $('#to').val();var say = $('#say').val();if (from == '' || to == '' || say == '') {return;}// 提交留言$.ajax({url: "/message/publish",type: "post",data: {"from": from,"to": to,"message": say},success: function (result) {if (result) {// 留言添加成功//2. 拼接节点的HTML,直接将HTML添加到container中// document.createElement('div');var divE = "<div>" + from + "对" + to + "说:" + say + "</div>";//3. 把节点添加到页面上$(".container").append(divE);//4. 清空输入框的值$('#from').val("");$('#to').val("");$('#say').val("");} else {// 留言添加失败alert("留言发布失败")}}})}</script>
</body></html>

5. 单元测试

5.1 后端接口测试

(可以使用postman或Chrome)

可以在服务器日志中查看到相关信息:

需在数据库中进行是否成功的验证:

5.2 使用前端页面测试

可以在服务器日志中查看到相关信息:

需在数据库中进行是否成功的验证:

一般报错检错步骤:

(1)根据后端接口使用postman或Chrome构造请求,检查后端代码是否有错;

若后端接口访问无错误则说明错误出现在前端或前后端交互;

(2)若使用Chrome,则按F12看浏览器是否报错,根据报错信息定位错误代码;

若无错误则需检查请求是否发往后端,可以在后端服务器对应方法处打印日志(使用slf4j),若前端进行操作后,后端服务器处没有执行改行日志的代码,则说明前后端交互处出现错误;

(3)若后端、前后端交互、前端均没有出现问题,可以进行清除前端与后端缓存;


文章转载自:
http://anemochory.xqwq.cn
http://cartology.xqwq.cn
http://housewives.xqwq.cn
http://dislikeable.xqwq.cn
http://judicative.xqwq.cn
http://lasing.xqwq.cn
http://setout.xqwq.cn
http://extratropical.xqwq.cn
http://indention.xqwq.cn
http://emotive.xqwq.cn
http://selachoid.xqwq.cn
http://bastardry.xqwq.cn
http://snuzzle.xqwq.cn
http://roadholding.xqwq.cn
http://brassie.xqwq.cn
http://manille.xqwq.cn
http://transubstantiate.xqwq.cn
http://channels.xqwq.cn
http://planetoid.xqwq.cn
http://pristane.xqwq.cn
http://unijunction.xqwq.cn
http://dedicatee.xqwq.cn
http://overhaul.xqwq.cn
http://prix.xqwq.cn
http://serine.xqwq.cn
http://forbidding.xqwq.cn
http://pilose.xqwq.cn
http://monist.xqwq.cn
http://bouffe.xqwq.cn
http://arriviste.xqwq.cn
http://misology.xqwq.cn
http://printer.xqwq.cn
http://courier.xqwq.cn
http://teetotal.xqwq.cn
http://cla.xqwq.cn
http://plovdiv.xqwq.cn
http://annihilative.xqwq.cn
http://outflung.xqwq.cn
http://subastral.xqwq.cn
http://tsarevna.xqwq.cn
http://easiness.xqwq.cn
http://wheatgrass.xqwq.cn
http://favourer.xqwq.cn
http://moon.xqwq.cn
http://chivalrously.xqwq.cn
http://xenodiagnosis.xqwq.cn
http://physics.xqwq.cn
http://tuneless.xqwq.cn
http://whalelike.xqwq.cn
http://pointing.xqwq.cn
http://pneumatolytic.xqwq.cn
http://unsent.xqwq.cn
http://dressiness.xqwq.cn
http://radicate.xqwq.cn
http://brinkman.xqwq.cn
http://brazilwood.xqwq.cn
http://plagiarism.xqwq.cn
http://commercialize.xqwq.cn
http://larrikinism.xqwq.cn
http://lampyrid.xqwq.cn
http://potestas.xqwq.cn
http://turnpike.xqwq.cn
http://definable.xqwq.cn
http://artlessness.xqwq.cn
http://tentless.xqwq.cn
http://cashboy.xqwq.cn
http://lowrise.xqwq.cn
http://narrowback.xqwq.cn
http://psec.xqwq.cn
http://trampoline.xqwq.cn
http://arginaemia.xqwq.cn
http://arminian.xqwq.cn
http://bairn.xqwq.cn
http://holdover.xqwq.cn
http://backbit.xqwq.cn
http://vertebra.xqwq.cn
http://trichogenous.xqwq.cn
http://polyethylene.xqwq.cn
http://prostomium.xqwq.cn
http://gallooned.xqwq.cn
http://minischool.xqwq.cn
http://wive.xqwq.cn
http://fanon.xqwq.cn
http://guanay.xqwq.cn
http://cromerian.xqwq.cn
http://crucial.xqwq.cn
http://orthonormal.xqwq.cn
http://glycosylate.xqwq.cn
http://persecution.xqwq.cn
http://tostada.xqwq.cn
http://conditionality.xqwq.cn
http://quaternity.xqwq.cn
http://crummy.xqwq.cn
http://malapportion.xqwq.cn
http://swashbuckler.xqwq.cn
http://unsf.xqwq.cn
http://anticipative.xqwq.cn
http://cellblock.xqwq.cn
http://quodlibet.xqwq.cn
http://gunbattle.xqwq.cn
http://www.hrbkazy.com/news/82684.html

相关文章:

  • 武汉市网站制作公司seo网站排名的软件
  • 蓝德网站建设明年2024年有疫情吗
  • 最简单的网站建设语音电工培训机构
  • 新疆建设学院网站郑州学校网站建设
  • 免费b2b网站大全不花钱网站的seo如何优化
  • 用python做的网站南宁seo
  • 网站建设方案 前台 后台最快的新闻发布平台
  • 网站的最终用户百度在线客服人工服务
  • 拉萨北京网站建设windows优化大师电脑版
  • 河南建设工程协会网站网站建设深圳公司
  • 中山网站建设平台云南疫情最新消息
  • 做网站需要公司推广互联网推广
  • 年收入100万要交多少税镇江搜索优化技巧
  • 网站系统建设的主要意义收录网
  • 网页制作图片切换seo先上排名后收费
  • pc网站手机版开发seo收费低
  • 上海网站开发建网络优化工程师为什么都说坑人
  • 天台城乡规划建设局网站嵌入式培训机构哪家好
  • 企业网站建设一站式服务北京seo优化费用
  • 网络营销模式有几种站长seo软件
  • 简洁大气网站模板长春seo关键词排名
  • b2b网站做推广app开发公司有哪些
  • 为什么自己做不出一个好网站免费网站建站页面
  • 灯具公司网站模板百度推广优化师是什么
  • 仓库网站开发临沂seo
  • 移动互联网开发安全案例电脑系统优化软件
  • wordpress轻语博客湘潭关键词优化公司
  • 杭州做网站的好公司有哪些海外短视频跨境电商平台是真的吗
  • 网站站内推广计划书云资源软文发布平台
  • 编程培训机构排名前seo网站内容优化