uniapp微信小程序投票系统实战 (SpringBoot2+vue3.2+element plus ) -投票创建后端实现

本文主要是介绍uniapp微信小程序投票系统实战 (SpringBoot2+vue3.2+element plus ) -投票创建后端实现,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

锋哥原创的uniapp微信小程序投票系统实战:

uniapp微信小程序投票系统实战课程 (SpringBoot2+vue3.2+element plus ) ( 火爆连载更新中... )_哔哩哔哩_bilibiliuniapp微信小程序投票系统实战课程 (SpringBoot2+vue3.2+element plus ) ( 火爆连载更新中... )共计21条视频,包括:uniapp微信小程序投票系统实战课程 (SpringBoot2+vue3.2+element plus ) ( 火爆连载更新中... )、第2讲 投票项目后端架构搭建、第3讲 小程序端 TabBar搭建等,UP主更多精彩视频,请关注UP账号。icon-default.png?t=N7T8https://www.bilibili.com/video/BV1ea4y137xf/新建Vote投票类:

package com.java1234.entity;import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;import java.util.Date;
import java.util.List;/*** 投票实体* @author java1234_小锋 (公众号:java1234)* @site www.java1234.vip* @company 南通小锋网络科技有限公司*/
@TableName("t_vote")
@Data
public class Vote {private Integer id; // 编号private String title; // 标题private String explanation; // 投票说明private String coverImage; // 封面图片@JsonSerialize(using=CustomDateTimeSerializer.class)@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")private Date voteEndTime; // 投票结束时间private String openid; // 投票发起人openid@TableField(select=false,exist = false)private List<VoteItem> voteItemList;@TableField(select=false,exist = false)private WxUserInfo wxUserInfo;private Integer type=1; // 1 文字投票  2 图片投票}

新建VoteItem投票选项类:

package com.java1234.entity;import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;/*** 投票选项实体* @author java1234_小锋 (公众号:java1234)* @site www.java1234.vip* @company 南通小锋网络科技有限公司*/
@TableName("t_vote_item")
@Data
public class VoteItem {private Integer id; // 编号private Integer voteId; // 投票IDprivate String name; // 投票选项名称private String image; // 投票选项图片private Integer number; // 票数}

数据库新建t_vote投票表:

create table `t_vote` (`id` int (11),`title` varchar (600),`explanation` varchar (3000),`cover_image` varchar (600),`vote_end_time` datetime ,`openid` varchar (600),`type` int (11)
); 

数据库再新建t_vote_item投票选项表:

create table `t_vote_item` (`id` int (11),`vote_id` int (11),`name` varchar (600),`image` varchar (600),`number` int (11)
); 

新建VoteMapper:

/*** 投票Mapper接口*/
public interface VoteMapper extends BaseMapper<Vote> {
}

新建VoteItemMapper:

/*** 投票选项Mapper接口*/
public interface VoteItemMapper extends BaseMapper<VoteItem> {}

新建IVoteService:

/*** 投票Service接口*/
public interface IVoteService extends IService<Vote> {}

新建IVoteItemService:

/*** 投票选项Service接口*/
public interface IVoteItemService extends IService<VoteItem> {}

新建IVoteServiceImpl:

@Service("voteService")
public class IVoteServiceImpl extends ServiceImpl<VoteMapper,Vote> implements IVoteService {@Autowiredprivate VoteMapper voteMapper;}

新建IVoteItemServiceImpl:

@Service("voteItemService")
public class IVoteItemServiceImpl extends ServiceImpl<VoteItemMapper, VoteItem> implements IVoteItemService {@Autowiredprivate VoteItemMapper voteItemMapper;}

VoteController添加add方法:

/*** 添加投票* @param vote* @return*/
@RequestMapping("/add")
@Transactional
public R add(@RequestBody Vote vote, @RequestHeader String token){System.out.println("token="+token);Claims claims = JwtUtils.validateJWT(token).getClaims();System.out.println("openid="+claims.getId());vote.setOpenid(claims.getId());voteService.save(vote);// 存投票选项List<VoteItem> voteItemList=vote.getVoteItemList();for(VoteItem voteItem:voteItemList){voteItem.setVoteId(vote.getId());voteItem.setNumber(0);voteItemService.save(voteItem);}return R.ok();
}

前端验证以及提交:

submitVote:async function(e){// 验证if(isEmpty(this.title)){uni.showToast({icon:"error",title:"请填写投票标题"})return;}// 投票选项片段 至少2个选项let resultOptions=this.options.filter(function(value,index,self){  // 过滤掉名称为空的投票选项console.log("value="+value.name)return !isEmpty(value.name)})console.log("xx"+JSON.stringify(resultOptions));console.log("length="+resultOptions.length)if(resultOptions.length<2){uni.showToast({icon:"error",title:"请至少填写两个投票选项"})return;}// 提交表单let form={title:this.title,coverImage:this.coverImageFileName,explanation:this.explanation,voteEndTime:this.voteEndTime,voteItemList:resultOptions,type:1}const result=await requestUtil({url:"/vote/add",data:form,method:"post"});if(result.code==0){console.log("发布成功")uni.showToast({icon:"success",title:"投票发起成功!"})}
}

这篇关于uniapp微信小程序投票系统实战 (SpringBoot2+vue3.2+element plus ) -投票创建后端实现的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/590259

相关文章

Spring三级缓存解决循环依赖的解析过程

《Spring三级缓存解决循环依赖的解析过程》:本文主要介绍Spring三级缓存解决循环依赖的解析过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、循环依赖场景二、三级缓存定义三、解决流程(以ServiceA和ServiceB为例)四、关键机制详解五、设计约

spring IOC的理解之原理和实现过程

《springIOC的理解之原理和实现过程》:本文主要介绍springIOC的理解之原理和实现过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、IoC 核心概念二、核心原理1. 容器架构2. 核心组件3. 工作流程三、关键实现机制1. Bean生命周期2.

Redis实现分布式锁全解析之从原理到实践过程

《Redis实现分布式锁全解析之从原理到实践过程》:本文主要介绍Redis实现分布式锁全解析之从原理到实践过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、背景介绍二、解决方案(一)使用 SETNX 命令(二)设置锁的过期时间(三)解决锁的误删问题(四)Re

Gradle下如何搭建SpringCloud分布式环境

《Gradle下如何搭建SpringCloud分布式环境》:本文主要介绍Gradle下如何搭建SpringCloud分布式环境问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录Gradle下搭建SpringCloud分布式环境1.idea配置好gradle2.创建一个空的gr

springboot集成Lucene的详细指南

《springboot集成Lucene的详细指南》这篇文章主要为大家详细介绍了springboot集成Lucene的详细指南,文中的示例代码讲解详细,具有一定的借鉴价值,感兴趣的小伙伴可以跟随小编一起... 目录添加依赖创建配置类创建实体类创建索引服务类创建搜索服务类创建控制器类使用示例以下是 Spring

Java根据IP地址实现归属地获取

《Java根据IP地址实现归属地获取》Ip2region是一个离线IP地址定位库和IP定位数据管理框架,这篇文章主要为大家详细介绍了Java如何使用Ip2region实现根据IP地址获取归属地,感兴趣... 目录一、使用Ip2region离线获取1、Ip2region简介2、导包3、下编程载xdb文件4、J

PyQt5+Python-docx实现一键生成测试报告

《PyQt5+Python-docx实现一键生成测试报告》作为一名测试工程师,你是否经历过手动填写测试报告的痛苦,本文将用Python的PyQt5和python-docx库,打造一款测试报告一键生成工... 目录引言工具功能亮点工具设计思路1. 界面设计:PyQt5实现数据输入2. 文档生成:python-

Android实现一键录屏功能(附源码)

《Android实现一键录屏功能(附源码)》在Android5.0及以上版本,系统提供了MediaProjectionAPI,允许应用在用户授权下录制屏幕内容并输出到视频文件,所以本文将基于此实现一个... 目录一、项目介绍二、相关技术与原理三、系统权限与用户授权四、项目架构与流程五、环境配置与依赖六、完整

浅析如何使用xstream实现javaBean与xml互转

《浅析如何使用xstream实现javaBean与xml互转》XStream是一个用于将Java对象与XML之间进行转换的库,它非常简单易用,下面将详细介绍如何使用XStream实现JavaBean与... 目录1. 引入依赖2. 定义 JavaBean3. JavaBean 转 XML4. XML 转 J

Flutter实现文字镂空效果的详细步骤

《Flutter实现文字镂空效果的详细步骤》:本文主要介绍如何使用Flutter实现文字镂空效果,包括创建基础应用结构、实现自定义绘制器、构建UI界面以及实现颜色选择按钮等步骤,并详细解析了混合模... 目录引言实现原理开始实现步骤1:创建基础应用结构步骤2:创建主屏幕步骤3:实现自定义绘制器步骤4:构建U