当前位置: 首页 > 编程日记 > 正文

「小程序JAVA实战」小程序的视频展示页面初始化(63)

转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeshipinzhanshiyemianchushihua62/

进入列表详情,展示点赞状态用户的名称,头像名称。源码:https://github.com/limingios/wxProgram.git 中No.15和springboot

后台开发

拦截器,不拦截获取视频初始化信息。游客可以直接观看。通过用户id,视频id,视频创建id获取是否点赞视频,并获取创建者的信息。

  • 拦截器

package com.idig8;import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;import com.idig8.controller.interceptor.MiniInterceptor;@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {@Value("${server.file.path}")private String fileSpace;@Overridepublic void addResourceHandlers(ResourceHandlerRegistry registry) {//资源的路径.swagger2的资源.所在的目录,registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/").addResourceLocations("file:"+fileSpace);}@Beanpublic MiniInterceptor miniInterceptor() {return new MiniInterceptor();}@Overridepublic void addInterceptors(InterceptorRegistry registry) {registry.addInterceptor(miniInterceptor()).addPathPatterns("/user/**").addPathPatterns("/video/upload", "/video/uploadCover","/video/userLike","/video/userUnLike").addPathPatterns("/bgm/**").excludePathPatterns("/user/queryPublisher");super.addInterceptors(registry);}}

UserController.java

package com.idig8.controller;import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;import com.idig8.pojo.Users;
import com.idig8.pojo.vo.PublisherVideo;
import com.idig8.pojo.vo.UsersVO;
import com.idig8.service.UserService;
import com.idig8.utils.JSONResult;
import com.idig8.utils.file.FileUtil;import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;@RestController
@Api(value="用户接口",tags={"用户的controller"})
@RequestMapping(value = "/user")
public class UserController extends BasicController{@Autowiredprivate UserService userService;@Value("${server.file.path}")private String fileSpace;@ApiOperation(value="用户上传头像",notes="用户上传头像的接口")@ApiImplicitParams({@ApiImplicitParam(name="userId",value="用户id",required=true,dataType="String",paramType="query"),})@PostMapping(value="/uploadFace",headers="content-type=multipart/form-data")public JSONResult uploadFace(String userId,@ApiParam(value="图片",required=true) MultipartFile file) {if (StringUtils.isBlank(userId)) {return JSONResult.errorMsg("用户id不能为空...");}// 文件保存的命名空间String fileName = file.getOriginalFilename();// 保存到数据库中的相对路径String path = "";try {path = FileUtil.uploadFile(file.getBytes(), fileSpace, fileName);} catch (Exception e) {e.getStackTrace();return JSONResult.errorMsg(e.getMessage());}Users user = new Users();user.setId(userId);user.setFaceImage(path);userService.updateUser(user);return JSONResult.ok(path);}@ApiOperation(value="通过用户Id获取用户信息",notes="通过用户Id获取用户信息的接口")@ApiImplicitParam(name="userId",value="用户id",required=true,dataType="String",paramType="query")@PostMapping("/queryByUserId")public JSONResult queryByUserId(String userId) {if (StringUtils.isBlank(userId)) {return JSONResult.errorMsg("用户id不能为空...");}Users user = userService.queryUserId(userId);UsersVO usersVO= new UsersVO();BeanUtils.copyProperties(user, usersVO);return JSONResult.ok(usersVO);}@PostMapping("/queryPublisher")public JSONResult queryPublisher(String loginUserId, String videoId, String publishUserId) throws Exception {if (StringUtils.isBlank(publishUserId)) {return JSONResult.errorMsg("");}// 1. 查询视频发布者的信息Users userInfo = userService.queryUserInfo(publishUserId);UsersVO publisher = new UsersVO();BeanUtils.copyProperties(userInfo, publisher);// 2. 查询当前登录者和视频的点赞关系boolean userLikeVideo = userService.isUserLikeVideo(loginUserId, videoId);PublisherVideo bean = new PublisherVideo();bean.setPublisher(publisher);   bean.setUserLikeVideo(userLikeVideo);return JSONResult.ok(bean);}}

  • service 和 serviceImp
package com.idig8.service;import com.idig8.pojo.Users;public interface UserService {/*** 判断用户名是否存在* @param username* @return*/public boolean queryUsernameIsExist(String username);/*** 保存用户* @param user* @return*/public void saveUser(Users user);/*** 查询用户对象* @param username* @return*/public Users queryUserIsExist(Users user);/*** 更新对象* @param username* @return*/public void updateUser(Users user);/*** userId查询用户对象* @param username* @return*/public Users queryUserId(String userId);/*** 查询用户信息*/public Users queryUserInfo(String userId);/*** 查询用户是否喜欢点赞视频*/public boolean isUserLikeVideo(String userId, String videoId);}
package com.idig8.service.Impl;import java.util.List;import org.apache.commons.lang3.StringUtils;
import org.n3r.idworker.Sid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;import com.idig8.mapper.UsersLikeVideosMapper;
import com.idig8.mapper.UsersMapper;
import com.idig8.pojo.Users;
import com.idig8.pojo.UsersLikeVideos;
import com.idig8.service.UserService;
import com.idig8.utils.MD5Utils;import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;@Service
public class UserServiceImpl implements UserService {@Autowiredprivate UsersMapper usersMapper;@Autowiredprivate UsersLikeVideosMapper usersLikeVideosMapper;@Autowiredprivate UsersMapper userMapper;@Autowiredprivate Sid sid;@Transactional(propagation =Propagation.SUPPORTS)@Overridepublic boolean queryUsernameIsExist(String username) {Users user = new Users();user.setUsername(username);Users result = usersMapper.selectOne(user);return result==null? false:true;}@Transactional(propagation =Propagation.REQUIRED)@Overridepublic void saveUser(Users user) {String userId =sid.nextShort();user.setId(userId);usersMapper.insert(user);}@Transactional(propagation =Propagation.SUPPORTS)@Overridepublic Users queryUserIsExist(Users user) {Example queryExample = new Example(Users.class);Criteria criteria = queryExample.createCriteria();criteria.andEqualTo("username",user.getUsername());try {criteria.andEqualTo("password",MD5Utils.getMD5Str(user.getPassword()));} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}Users userOne =  usersMapper.selectOneByExample(queryExample);return userOne;}@Transactional(propagation =Propagation.REQUIRED)@Overridepublic void updateUser(Users user) {Example userExample = new Example(Users.class);Criteria criteria = userExample.createCriteria();criteria.andEqualTo("id", user.getId());usersMapper.updateByExampleSelective(user, userExample);}@Transactional(propagation =Propagation.SUPPORTS)@Overridepublic Users queryUserId(String userId){Example queryExample = new Example(Users.class);Criteria criteria = queryExample.createCriteria();criteria.andEqualTo("id",userId);Users userOne =  usersMapper.selectOneByExample(queryExample);return userOne;}@Transactional(propagation = Propagation.SUPPORTS)@Overridepublic Users queryUserInfo(String userId) {Example userExample = new Example(Users.class);Criteria criteria = userExample.createCriteria();criteria.andEqualTo("id", userId);Users user = userMapper.selectOneByExample(userExample);return user;}@Transactional(propagation = Propagation.SUPPORTS)@Overridepublic boolean isUserLikeVideo(String userId, String videoId) {if (StringUtils.isBlank(userId) || StringUtils.isBlank(videoId)) {return false;}Example example = new Example(UsersLikeVideos.class);Criteria criteria = example.createCriteria();criteria.andEqualTo("userId", userId);criteria.andEqualTo("videoId", videoId);List<UsersLikeVideos> list = usersLikeVideosMapper.selectByExample(example);if (list != null && list.size() >0) {return true;}return false;}}

小程序修改

  • videoInfo.js
var videoUtils = require('../../utils/videoUtils.js')
const app = getApp()
Page({data: {cover:'cover',videoContext:"",videoInfo:{},videId:'',src:'',userLikeVideo:false,serverUrl:'',publisher:[]},showSearch:function(){wx.navigateTo({url: '../videoSearch/videoSearch',})},onLoad:function(params){var me = this;me.videoContext = wx.createVideoContext('myVideo', me);var videoInfo = JSON.parse(params.videoInfo);var videoWidth = videoInfo.videoWidth;var videoHeight = videoInfo.videoHeight;var cover = 'cover';if (videoWidth > videoHeight){cover = '';}me.setData({videId: videoInfo.id,src: app.serverUrl + videoInfo.videoPath,videoInfo: videoInfo,cover: cover})var serverUrl = app.serverUrl;var user = app.getGlobalUserInfo();var loginUserId = "";if (user != null && user != undefined && user != '') {loginUserId = user.id;}wx.request({url: serverUrl + '/user/queryPublisher?loginUserId=' + loginUserId + "&videoId=" + videoInfo.id + "&publishUserId=" + videoInfo.userId,method: 'POST',success: function (res) {console.log(res.data);var publisher = res.data.data.publisher;var userLikeVideo = res.data.data.userLikeVideo;me.setData({serverUrl: serverUrl,publisher: publisher,userLikeVideo: userLikeVideo});}})},showIndex:function(){wx.redirectTo({url: '../index/index',})},onShow:function(){var me = this;me.videoContext.play();},onHide:function(){var me = this;me.videoContext.pause();},upload:function(){var me = this;var userInfo = app.getGlobalUserInfo();var videoInfo = JSON.stringify(me.data.videoInfo);var realUrl = '../videoInfo/videoInfo#videoInfo@' + videoInfo;if (userInfo.id == '' || userInfo.id == undefined) {wx.navigateTo({url: '../userLogin/userLogin?realUrl=' + realUrl,})} else {videoUtils.uploadVideo();}},showMine: function () {var me = this;var userInfo = app.getGlobalUserInfo();var videoInfo = JSON.parseif (userInfo.id == '' || userInfo.id == undefined){wx.navigateTo({url: '../userLogin/userLogin',})}else{wx.navigateTo({url: '../mine/mine',})}},likeVideoOrNot: function () {var me = this;var userInfo = app.getGlobalUserInfo();var videoInfoStr = JSON.stringify(me.data.videoInfo);var realUrl = '../videoInfo/videoInfo#videoInfo@' + videoInfoStr;if (userInfo.id == '' || userInfo.id == undefined) {wx.navigateTo({url: '../userLogin/userLogin?realUrl=' + realUrl,})} else {var videoInfo = me.data.videoInfo;var userLikeVideo = me.data.userLikeVideo;var url = "/video/userLike?userId=" + userInfo.id + "&videoId=" + videoInfo.id + "&videoCreaterId=" + userLikeVideo.userId;if (userLikeVideo){var url = "/video/userUnLike?userId=" + userInfo.id + "&videoId=" + videoInfo.id + "&videoCreaterId=" + userLikeVideo.userId;}wx.showLoading({title: '....',})wx.request({url: app.serverUrl + url,method: "POST",header: {'content-type': 'application/json', // 默认值'headerUserId': userInfo.id,'headerUserToken': userInfo.userToken},success: function (res) {wx.hideLoading();me.setData({userLikeVideo: !userLikeVideo,})}})}}
})

PS:拦截器excludePathPatterns可以不拦截,分析业务,那些需要登录后才可以获得,那些不需要登录就可以看到。

转载于:https://www.cnblogs.com/sharpest/p/10316492.html

相关文章:

.NET判断字符串是否是数值型或xxx型

using System.Text.RegularExpressions; Regex digitregex new Regex("^[0-9]\d*[.]?\d*$"); if (!digitregex.IsMatch(TextBox1.Text)) { TextBox1.Text""; MessageBox.Show("只能输入数字&#xff01;","提示…

Spring.net使用说明

使用方法&#xff1a;1.在配置文件设置Spring.net 节点在配置节中&#xff0c;声明Spring.net&#xff0c;配置 context&#xff0c;objects 标签&#xff0c;来源&#xff08;type&#xff09;<!--配置节&#xff1a;主要用来 配置 asp.net框架之外的 标签&#xff0c;告诉…

逻辑覆盖测试(三)条件覆盖

条件覆盖&#xff1a;设计测试用例时应保证程序中每个复合判定表达式中&#xff0c;每个简单判定条件的取真和取假情况至少执行一次。 例子&#xff1a; 流程图&#xff1a; 测试用例&#xff1a; 程序中一共两个if语句&#xff0c;都是复合判定条件&#xff0c;其中的简单…

Linux UserSpace Back-Door、Rootkit SSH/PAM Backdoor Attack And Defensive Tchnology

catalog 0. 引言 1. Pam后门 2. SSH后门 3. Hijacking SSH 4. Hijacking SSH By Setup A Tunnel Which Allows Multiple Sessions Over The Same SSH Connection Without Re-Authentication 5. Hijacking Active SSH Screen Sessions 0. 引言 0x1: 安全攻防观点 1. Know Your …

澳大利亚多地热浪来袭 最高温度超40摄氏度

中新网1月24日电 据澳洲网报道&#xff0c;近日&#xff0c;澳大利亚多地热浪来袭&#xff0c;其中&#xff0c;南澳和维州的部分地区气温将飙升至40摄氏度以上。维州政府发布声明&#xff0c;提醒民众做好应对高温天气的准备。资料图&#xff1a;当地时间1月21日&#xff0c;澳…

Multithread 之 introduction

Why multithreading?&#xff08;摘自《win32 多线程程序设计》&#xff09;单线程程序就像超级市场中唯一的一位出纳&#xff0c;这个出纳对于小量采购可以快速结账。但如果有人采购了一大车货品&#xff0c;结账就需要点时间了&#xff0c;其他每个人都必须等待。多线程程序…

逻辑覆盖测试(四)判定/条件覆盖

判定/条件覆盖&#xff1a;测试用例的设计应满足判定节点的取真和取假分支至少执行一次&#xff0c;且每个简单判定条件的取真和取假情况也至少执行一次。 简单来说&#xff0c;就是判定覆盖和条件覆盖取交集。 例子&#xff1a; 流程图&#xff1a; 当判定覆盖和条件覆盖…

jQuery选择器的工作原理和优化

至于有那些选择器&#xff0c;在帮助手册中都有&#xff0c;自己去看&#xff0c;这篇主要是分析他的工作原理&#xff0c;而优化我们写 的选择器&#xff0c;尤其在页面内容很多的情况下&#xff0c;更应该需要优化。下边就言归正传。 每次申明一个jQuery对象的时候&#xff0…

webservice发送字符串

假设只是发送一个字符串client&#xff0c;这是很easy&#xff0c;只需要输入xfire包&#xff0c;编写接口&#xff0c;编写的实现方法。变化。 假设你要传输的数组或自定义类。到用于接口准备的需要agexis文件。更复杂。 尝试传输这些假设没有成功。在发送成功的字符串&#x…

600余名外出务工者免费乘高铁“返乡专列”回云南过春节

中新网昆明1月25日电(缪超)记者25日从中国铁路昆明局集团获悉&#xff0c;云南与广东两省人社部门近日组织开行高铁“返乡专列”&#xff0c;免费安排600多名云南籍外出务工人员乘坐高铁动车返乡过春节。图为志愿者与乘务员为外出务工人员精心准备的歌舞节目。中国铁路昆明局集…

逻辑覆盖测试(六)--路径测试

路径覆盖&#xff1a;设计足够多的测试用例&#xff0c;使得程序中所有可能的路径都被至少被执行一次。 例子&#xff1a; 测试用例&#xff1a; 思路&#xff1a; 先是都经过a&#xff0c;到一个if分支&#xff0c;可以有a 、b和 a、c&#xff0c;然后到第二个if分支&#…

浅谈MVP设计模式

最近公司在做一个医疗项目&#xff0c;使用WinForm界面作为客户端交互界面。在整个客户端解决方案中。使用了MVP模式实现。由于之前没有接触过该设计模式&#xff0c;所以在项目完成到某个阶段时&#xff0c;将使用MVP的体会写在博客里面。 所谓的MVP指的是Model&#xff0c;Vi…

C#委托与事件

之前写过一篇关于C#委托与事件的文章&#xff08;见《C#委托和事件例析》&#xff09;&#xff0c;不过还是收到一些网友的提问。所以&#xff0c;今天再换另一个角度来详解一下这个问题。 一、在控制台下使用委托和事件 我们都知道&#xff0c;C#中有“接口”这个概念&#xf…

Docker for mac安装

Mac安装Docker docker下载地址: https://hub.docker.com/editions/community/docker-ce-desktop-mac docker for mac document: https://docs.docker.com/docker-for-mac/ 系统要求 Docker Desktop - Mac适用于OS X Sierra 10.12和更新的macOS版本。 获得Docker 稳定边缘Stable…

白盒测试--基本路径测试法

1.为什么要有基本路径测试法&#xff1f; 对于路径测试&#xff0c;最理想的情况是路径全部覆盖&#xff0c;单对于复杂的大程序要做到路径覆盖是不可能的&#xff0c;因此可以采用基本路径测试。 2.基本路径测试法的步骤&#xff1f; &#xff08;1&#xff09;画出程序的控制…

Postmortem报告

1. 每个成员在beta 阶段的实践和alpha 阶段有何改进? 2. 团队在beta 阶段吸取了那些alpha 阶段的经验教训? 在alpha阶段中&#xff0c;虽然我们团队已经对软件主要功能核心代码完成了&#xff0c;但是由于我们团队现有掌握有关于安卓开发的技术并不成熟&#xff0c;无法对软件…

是否可以人为修改发表时间

是否可以人为修改发表时间转载于:https://blog.51cto.com/14188306/2346747

关于win7_iis报500.19和500.21错误的解决方法

关于win7_iis报500.19和500.21错误的解决方法HTTP 错误 500.19 Internal Server Error的解决方法WIN7下.Net开发遇到的又一问题&#xff1a;HTTP 错误 500.19 - Internal Server Error&#xff0c;无法访问请求的页面&#xff0c;因为该页的相关配置数据无效。详细错误信息模块…

黑盒测试--因果图法

例子&#xff1a; (1)根据题目可以得到原因和结果分别是&#xff1a; &#xff08;2&#xff09;画出因果图 根据题意来画因果图&#xff0c;输入第一个字符是A或B要写成一个状态&#xff0c;且第二个字符为数字。 画因果图主要就是理清不同状态之间的关系&#xff0c;还有有…

php 学习笔记 数组1

1、一般情况下$name[tom]和$name[tom]是相同的&#xff1b;但没有引号的键不能和常量区别开&#xff0c;如&#xff1a;define(index, 5)时&#xff1b;$name[tom]和$name[tom]不同 2、双引号里的变量一般要用{}括起来是好习惯&#xff0c;如&#xff1a; echo "{$name}&q…

Linux的文件系统

一、文件的属性 linux文件属性的格式为- --- --- ---。第一位为文件的类型&#xff0c;剩下的9位&#xff0c;每三位为一组&#xff0c;分别对应文件所有者&#xff0c;文件所以者所属的用户组&#xff0c;其他人的关系。 r为可读&#xff0c;w为可写&#xff0c;x为可执行。如…

Python-100 练习题 01 列表推导式

最近打算好好练习下 python&#xff0c;因此找到一个练习题网站&#xff0c;打算每周练习 3-5 题吧。 www.runoob.com/python/pyth… 另外&#xff0c;这个网站其实也还有 Python 的教程&#xff0c;从基础到高级的知识都有。 Example-1 三位数组合 题目&#xff1a;有四个数字…

在思科模拟器下搭建WWW、DNS、FTP、Email服务

目录一、搭建基本的拓扑结构二、配置基本IP三、配置静态路由Router0&#xff1a;Router1:四、搭建WWW服务0号服务器&#xff1a;1号服务器&#xff1a;五、在pc0上测试www服务六、搭建FTP服务对于3号服务器&#xff1a;七、在pc0上测试搭建的FTP服务八、搭建E-mail服务对于2号服…

Android SQLite数据库之事务的学习

SQLite是Android系统内置的一款轻量级的关系型数据库&#xff0c;它的运算速度非常快&#xff0c;占用资源很少&#xff0c;通常只需要几百K的内存就足够了。SQLite不仅支持标准的SQL语法&#xff0c;还遵循了数据库的ACID事务。 模拟一个应用场景&#xff1a;进行一次转账操作…

1组合逻辑电路--多路选择器与多路分解器

1.2多路选择器 1.2.1不带优先级的多路选择器 四路选择器如下 代码如下 View Code 1 module multiplexer 2 ( 3 input iA, 4 input iB, 5 input iC, 6 input iD, 7 input [1:0] iSel, 8 output reg oQ 9 );10 11 always (*)12 begin13 case(iSel)1…

java——慎用可变参数列表

说起可变参数&#xff0c;我们先看下面代码段&#xff0c;对它有个直观的认识&#xff0c;下方的红字明确地解释了可变参数的意思&#xff1a; 1 public class VarargsDemo{2 3 static int sum(int... args) {4 int sum 0;5 for(int arg:args)6 …

一位老码农的分享:一线程序员该如何面对「中年危机」?

如果这是第二次看到我的文章&#xff0c;欢迎文末扫码订阅我个人的公众号&#xff08;跨界架构师&#xff09;哟~ 本文长度为2728字&#xff0c;建议阅读8分钟。坚持原创&#xff0c;每一篇都是用心之作&#xff5e;先来聊一下这个问题的背景吧。前两天有小伙伴问到Z哥这个问题…

白话spring依赖注入

Spring能有效地组织J2EE应用各层的对象。Action&#xff1f;Service&#xff1f;DAO&#xff1f;&#xff0c;都可在Spring的管理下有机地协调、运行。Spring将各层的对象以松耦合的方式组织在一起&#xff0c;对象与对象之间没有直接的联系&#xff0c;各层对象的调用完全面向…

2软件测试初相识

软件测试初相识 软件测试初识为什么要做软件测试,做软件测试的必要性是什么?关于软件测试的定义有很多种软件测试的两面性软件测试的价值总结软件测试初相识 文章目录 软件测试初识为什么要做软件测试,做软件测试的必要性是什么?关于软件测试的定义有很多种软件测试的两面性…

【go】sdk + idea-plugin 开发工具安装

http://golang.org/doc/install/source第一步&#xff1a;windows 安装 git第二步$ git clone https://go.googlesource.com/go $ cd go $ git checkout go1.4.1保持翻墙姿势 D:\Program Files (x86)\Git\bin>git clone https://go.googlesource.com/go Cloning into go... …