-
简单的JAVA小作品
2019-05-04 16:08:15创建一个简单的乘法口诀 代码如下: public class cz { public static void main(String[] args) { int o=0; for(int i=1;i<10;i++){ for(int j=1;j<=i;j++){ o=i*j; ...创建一个简单的乘法口诀
代码如下:
public class cz { public static void main(String[] args) { int o=0; for(int i=1;i<10;i++){ for(int j=1;j<=i;j++){ o=i*j; System.out.print(i+"x"+j+"="+o+" "); } System.out.print("\n"); } } }
输出:
创建一个简单的正三角形
代码如下:
public class cz { public static void main(String[] args){ int i,j,k; for(i=1;i<=5;i++){ for(j=1;j<=5-i;j++){ System.out.print(" "); } for(k=1;k<=i;k++){ System.out.print("* "); } System.out.print("\n"); } } }
输出:
创建一个简单的菱形
代码如下:
public class cz12 { public static void main(String[] args){ int m=3; for (int i=1;i<=m;i++){ for (int j=1;j<=m-i;j++){ System.out.print(" "); } for (int k=1;k<=2*i-1;k++){ System.out.print("*"); } System.out.print("\n"); } for (int i=1;i<=2;i++){ for (int j=1;j<=i;j++){ System.out.print(" "); } for (int k=3;k>=2*i-1;k--){ System.out.print("*"); } System.out.print("\n"); } } }
输出:
冒泡排序
代码如下:
public class cz { public static void main(String[] args) { int[] arr={123,354,354,54,4,6,654};//将数存储到数组里 int max=getMax(arr);//调用getMax方法 System.out.println("最大值为"+max);//输出结果语句 int min=getMin(arr);//调用getMin方法 System.out.println("最小值为"+min);//输出结果语句 System.out.print("冒泡排序为:");//输出结果语句 getSunxu(arr); printArray(arr);System.out.println("\n"); System.out.println("长度为:"+arr.length); } public static int getMax(int[] arr)//定义方法 { int max=arr[0];//将数组的第一个值赋予最大值 for(int i=1;i<arr.length;i++)//遍历数组 { if(max<arr[i]) { max = arr[i]; }//将数组中的值一一与最大值对比 } return max;//返还最大值 } public static void printArray(int[] arr) { for(int i=0;i<arr.length;i++) { if(i!=arr.length) System.out.print(arr[i]+","); else System.out.println(arr[i]); } } public static int getMin(int[] arr) { int min=arr[0];//将数组的第一个值赋予最小值 for(int i=1;i<arr.length;i++)//遍历数组 { if (min>arr[i]) { min = arr[i];//将数组中的值一一与最大值对比 } } return min;//返还最小值 } //冒泡排序 public static void getSunxu(int[] arr) { for(int x=0;x<arr.length-1;x++) { for(int y=0;y<arr.length-1-x;y++) { if (arr[y]>arr[y+1]) { int temp=arr[y]; arr[y]=arr[y+1]; arr[y+1]=temp; } } } } }
输出:
-
【Java】寒假答辩作品:Java小游戏
2020-10-07 21:16:55文章目录java入门小游戏【test】游戏界面前言 (可直接跳到程序介绍)前期入门小项目前期收获后期自创关卡熄灯问题拓展新游戏拓展实现切换关卡切换音乐后续 java入门小游戏【test】 游戏界面 github地址: ...java入门小游戏【test】
2020-02-22 14:58[补]
游戏界面
github地址: https://github.com/404name/WinterReplyWorks
网盘(提取码pzgt):https://pan.baidu.com/s/1-JoHOCKYl_56fKCzhEmMvg
前言 (可直接跳到程序介绍)
前期入门小项目
过年这段时间在家写了两个C语言的大程序,当初在学校立的flag就是用C写一个游戏,一个程序。
游戏完成了:https://www.cnblogs.com/404name/p/12234419.html感觉想法很好,但就是操控有点麻烦。
而另一个程就另作他用了,所以就不介绍了。
之前学过python,但没什么实质性的作品,为此思考寒假其实还是什么都没学到的。仔细思考了很久。
还是决定走java,贴切目前学过的C,看基础部分实在没意思,在家也不是沉得心去琢磨java的基础用
法,就想着直接上项目吧。因为C++面向对象的编程其实我也是没太多接触的,当接手项目时其实自己
也是很懵的。这时候我开始在github上找我能接受理解的小项目,然后正巧在b站
看到了这个教学,然后就开始跟着去了解java的一些操作。
这时候才发现,java其实本质和C还是大不一样的。
几小时能看完的视频,我大概跟着弄了一天(配置环境,查找用法,de莫名其妙的bug);
终于在晚上成功用exe4j打包出了我的第一个简易的JAVA小游戏。
这个大概就是个熄灯问题的游戏,你点击一个地方,他的上下左右中间都会改变一个面,然后要实现全部
翻回来,为此我还临时写了个C语言代码去跑结果。(C语言程序也在游戏包里面)。
前期收获
大概明白了,入门阶段遇到的bug是最手足无措的,编译器界面莫名其妙给你报错,百度还是一些看不懂的名词,哈哈太刺激了。。
我还在教学视频了发现了许多不足,比如他点一个地方会改变上下左右中间5个,然后比如角落他只会
改变 3个 或者 4个,因为他建立的是一维数组,他居然用了将近70行的枚举去枚举每一类。
然而只要把一维转成二维(二维数组本质其实就是一维),然后加个next【5】【2】移动判断,10行
就能解决。但可能是讲给初学者听的,所以就怎么简单怎么来,但,,这里也是我唯一可以体现我学
过编程的地方,后面就全部都是惊讶与自闭了。
我最佩服的面对对象编程就是这个:
Start_click listener = new Start_click(); // 实例化监听器 JButton reset = new JButton("重置"); reset.addActionListener(listener);
简直了!!把鼠标实体化,然后把鼠标加在一个按钮上,然后只要判断if(e.getSource() == reset)
就能轻松的实现交互,想起来我C语言都是要先另建立一个map储存数据,然后再读取返回,而java直
接短短3行就能搞定。
然后感觉打开了新世界大门,十分佩服以前的人能把底层代码一步步进化到封装的对象和类操作。
再进化下感觉直接说 把监听器加在新键按钮上 编译器都能实现。
这里我学会了好多东西,建立窗口,把对象像拼积木一样搭载在上面,学习ps切割图片,学习如何打包。
当然也遇到了许多困难。
比如很自闭的搞不清包,类,static,public。
一开始也搞不清这个java怎么走的流程(看教学视频“哦,这是主方法,调用另一个java的…哦,我懂了”,然后来写程序时“这特么是什么,这怎么结束啊,这到底怎么走的啊…”)
最神奇的是我搞不清图片怎么操作(后来才搞清)
就这样我大概写完了最初的框架(这里能播放音乐,实现效果,和教学视频的一模一样了。mid格式的音乐,1分钟的歌曲他能给压缩到3kb,神了,然而音质,,绝了)
这里仅仅实现了,我游戏第七关的效果。后来就进入了自闭的自己创造模式了。
后期自创关卡
熄灯问题拓展
就自己会基础操作后,就跃跃欲试。这时候我的文件是 一个mygame.java,一个music.java
我先是尝试在基础原来关卡的基础上改变下熄灯方式,这不就来了几个关卡了嘛。
原先是点一个地方 改变上下左右自身,通过巧妙的控制next数组,就轻松的写出了几个关卡,但问题
来了,怎么跳关卡?要说是在C语言里面,我能拿出好几种方案,但一到这里,我连函数递归啥的都搞
不清了,原因是监听器太混淆视听了,我一个函数只会走一次,但监听器在上面,它就总都会反应
(其实就是我没及时删除监听器),导致切换关卡25个方格变成50个,还弹出了新的窗口,按键还没
用。这就很绝望,然后各种失败后,才搞懂了,应该跨文件调用初始的jf窗口,然后设置静态等等。
但这里也只是开头,马上我把设置的4个关卡发现,4个java是多余的,合并了一下,因为是同类游戏。
新游戏拓展
后来我就在想什么游戏可以搭在这个框架上,显然我想到了以前老手机上的一个游戏九宫格拼图。
直接上图,只要改变一下熄灯规则就变成新游戏了!原本的是按下一个按钮检索上下左右自身是否合
法,然后改变图片,这些图片是固定好的。而我只要变成检索上下左右是否有 空白图标的就交换就实
现了游戏。然后问题是怎么随机初始化游戏,有没有什么算法可以实现25个数随机填入25个空。
后来放弃了,因为它会卡位,就像魔方,你必须在它还原的基础上打乱它,它才能还原。把它拆卸后随机
重装是很难复位的,或许有时候也不能复位。所以随机方法就是系统后台在它还原的基础上随便按下100-1000次
思路我有,就随机生成一个1-5的数对应方向,每次交换一个位置后,自动挪到下一个可移动位置再重复循环。
但毕竟是新语言,不能像C一样能达到想到啥干啥。
所以我放弃了,使用了固定的开局。
但作为新时代的bug maker,怎么能一个一个的人工随机填入呢。
我使用的是差位填入,就是还原图往后移动几格的基础上人工交换1 2个就行了。
然后我加入9 宫格 16宫格,ps切好的图片,下一关按钮, 计步器按钮。实现起来简直简单的不要。这时候7 + 1个关卡就写完了。
实现切换关卡切换音乐
但是,这么丰富的内容,怎么能搭配mid格式的音乐呢。
这时候我又掉进了另一个坑,在各种博客辗转,加载了jar包,试过提高mid音质,都没用。
我那时候就想找一个直接调用 函数名(地址) 就能播放的简单代码。最后唯一找到的还是wav格
式播放器,纯代码实现,但问题来了,我看不懂。。我music song = new music; song.play();
它就播放了,还停不下来,还只能在源文件里改动。那岂不是我要写8个音乐源文件?
后来自己一步步尝试改造,终于在它的基础上写出了我想要的音乐类。而且直接调用song.aay.stop();
就能随时停下。
这时候我就基本完成了剩余内容:不同关卡不同音乐,音乐可开关,开关按钮状态会改变。
后续
待更
-
java web 技术小作品
2020-03-06 14:20:14本人骑士粉,刚刚学习java web技术,做一个假面骑士decade的网页,用了几种入门方法,做得很粗糙,请大佬们多多指教! ![在这里插入图片描述]...本人骑士粉,刚刚学习java web技术,做一个假面骑士decade的网页,用了几种入门方法,做得很粗糙,请大佬们多多指教!    
-
「小程序JAVA实战」小程序的个人信息作品,收藏,关注(66)
2020-01-10 09:10:43个人信息页面有一个tab(作品,收藏,关注)源码:...作品,收藏,关注的列表 VideoController.java package com.idig8.controller; import java.io.File; import java.util.Date...个人信息页面有一个tab(作品,收藏,关注)源码:https://github.com/limingios/wxProgram.git 中No.15和springboot
作品,收藏,关注的列表
VideoController.java
package com.idig8.controller; import java.io.File; import java.util.Date; import java.util.UUID; import org.apache.commons.lang3.StringUtils; 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.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import com.idig8.pojo.Bgm; import com.idig8.pojo.Videos; import com.idig8.service.BgmService; import com.idig8.service.VideoService; import com.idig8.utils.FetchVideoCover; import com.idig8.utils.JSONResult; import com.idig8.utils.MergeVideoMp3; import com.idig8.utils.PagedResult; import com.idig8.utils.enums.VideoStatusEnum; 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("/video") public class VideoController extends BasicController { @Autowired private BgmService bgmService; @Autowired private VideoService videosService; @Value("${server.file.path}") private String fileSpace; @Value("${server.ffmpeg.path}") private String ffmpegexe; @ApiOperation(value="上传视频", notes="上传视频的接口") @ApiImplicitParams({ @ApiImplicitParam(name="userId", value="用户id", required=true, dataType="String", paramType="form"), @ApiImplicitParam(name="bgmId", value="背景音乐id", required=false, dataType="String", paramType="form"), @ApiImplicitParam(name="videoSeconds", value="背景音乐播放长度", required=true, dataType="String", paramType="form"), @ApiImplicitParam(name="videoWidth", value="视频宽度", required=true, dataType="String", paramType="form"), @ApiImplicitParam(name="videoHeight", value="视频高度", required=true, dataType="String", paramType="form"), @ApiImplicitParam(name="desc", value="视频描述", required=false, dataType="String", paramType="form") }) @PostMapping(value="/upload", headers="content-type=multipart/form-data") public JSONResult upload(String userId, String bgmId, double videoSeconds, int videoWidth, int videoHeight, String desc, @ApiParam(value="短视频", required=true) MultipartFile file) throws Exception { if (StringUtils.isBlank(userId)) { return JSONResult.errorMsg("用户id不能为空..."); } // 文件保存的命名空间 String fileName = file.getOriginalFilename(); // 保存到数据库中的相对路径 String path = ""; String videOutPath = ""; String ImagePath = ""; try { path = FileUtil.uploadFile(file.getBytes(), fileSpace, fileName); } catch (Exception e) { e.getStackTrace(); return JSONResult.errorMsg(e.getMessage()); } if(StringUtils.isNotBlank(bgmId)){ Bgm bgm = bgmService.queryBgmById(bgmId); String mp3BgmPath = fileSpace + bgm.getPath(); MergeVideoMp3 mergeVideoMp3 = new MergeVideoMp3(ffmpegexe); String videOutPathName = UUID.randomUUID().toString()+".mp4"; File targetFile = new File(fileSpace + userId); if (!targetFile.exists()) { targetFile.mkdirs(); } videOutPath = "/"+userId+"/"+videOutPathName; String videoInput = fileSpace +path; mergeVideoMp3.convertor(videoInput, mp3BgmPath, videoSeconds, fileSpace +videOutPath); }else{ videOutPath = path; } ImagePath = "/"+userId+"/"+UUID.randomUUID().toString()+".jpg";; FetchVideoCover fetchVideoCover = new FetchVideoCover(ffmpegexe); fetchVideoCover.getCover(fileSpace +videOutPath, fileSpace +ImagePath); Videos videos = new Videos(); videos.setAudioId(bgmId); videos.setCreateTime(new Date()); videos.setVideoDesc(desc); videos.setId(UUID.randomUUID().toString()); videos.setUserId(userId); videos.setVideoHeight(videoHeight); videos.setVideoWidth(videoWidth); videos.setVideoPath(videOutPath); videos.setCoverPath(ImagePath); videos.setStatus(VideoStatusEnum.SUCCESS.value); videosService.saveVideo(videos); return JSONResult.ok(path); } @PostMapping(value="/showAll") @ApiOperation(value="视频列表", notes="分页的视频列表") public JSONResult showAll(@RequestBody Videos video,Integer isSaveRecord, Integer page) throws Exception { if(page == null){ page = 1; } PagedResult result = videosService.getAllVideos(video,isSaveRecord,page, PAGE_SIZE); return JSONResult.ok(result); } @PostMapping(value="/userLike") @ApiOperation(value="热搜词列表", notes="热搜词列表") public JSONResult userLike(String userId,String videoId,String videoCreaterId) throws Exception { videosService.userLikeVideo(userId, videoId, videoCreaterId); return JSONResult.ok(); } @PostMapping(value="/userUnLike") public JSONResult userUnLike(String userId,String videoId,String videoCreaterId) throws Exception { videosService.userUnLikeVideo(userId, videoId, videoCreaterId); return JSONResult.ok(); } @PostMapping(value="/hot") public JSONResult upload() throws Exception { return JSONResult.ok(videosService.gethostList()); } @PostMapping(value="/showMyLike") public JSONResult showMyLike(String userId,Integer page,Integer pageSize) throws Exception { if(StringUtils.isBlank(userId)){ return JSONResult.ok(); } if(page == null){ page = 1; } if(pageSize == null){ pageSize = PAGE_SIZE; } PagedResult videoList = videosService.queryMyLikeVideos(userId,page,pageSize); return JSONResult.ok(videoList); } @PostMapping(value="/showMyFollow") public JSONResult showMyFollow(String userId,Integer page,Integer pageSize) throws Exception { if(StringUtils.isBlank(userId)){ return JSONResult.ok(); } if(page == null){ page = 1; } if(pageSize == null){ pageSize = PAGE_SIZE; } PagedResult videoList = videosService.queryMyFollowVideos(userId,page,pageSize); return JSONResult.ok(videoList); } }
VideoService.java
package com.idig8.service; import java.util.List; import com.idig8.pojo.Videos; import com.idig8.utils.PagedResult; public interface VideoService { /** * 保存视频信息 * @param Id * @return */ public String saveVideo(Videos video); /** * 分析查询视频列表 * @param video * @param isSaveRecord * @param page * @param pageSize * @return */ public PagedResult getAllVideos(Videos video,Integer isSaveRecord,Integer page,Integer pageSize); /** * 获取热搜词列表 * @return */ public List<String> gethostList(); public void userLikeVideo(String userId,String videoId,String videoCreaterId); public void userUnLikeVideo(String userId,String videoId,String videoCreaterId); public PagedResult queryMyLikeVideos(String userId,Integer page,Integer pageSize); public PagedResult queryMyFollowVideos(String userId,Integer page,Integer pageSize); }
VideoServiceImpl.java
package com.idig8.service.Impl; import java.util.List; 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.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.idig8.mapper.SearchRecordsMapper; import com.idig8.mapper.UsersLikeVideosMapper; import com.idig8.mapper.UsersMapper; import com.idig8.mapper.VideosMapper; import com.idig8.mapper.VideosUsersMapper; import com.idig8.pojo.SearchRecords; import com.idig8.pojo.UsersLikeVideos; import com.idig8.pojo.Videos; import com.idig8.pojo.vo.VideosVO; import com.idig8.service.VideoService; import com.idig8.utils.PagedResult; import tk.mybatis.mapper.entity.Example; import tk.mybatis.mapper.entity.Example.Criteria; @Service public class VideoServiceImpl implements VideoService { @Autowired private VideosMapper videosMapper; @Autowired private UsersMapper usersMapper; @Autowired private VideosUsersMapper videosUsersMapper; @Autowired private SearchRecordsMapper searchRecordsMapper; @Autowired private UsersLikeVideosMapper usersLikeVideosMapper; @Autowired private Sid sid; @Transactional(propagation = Propagation.REQUIRED) public String saveVideo(Videos video) { String id = sid.nextShort(); video.setId(id); videosMapper.insertSelective(video); return id; } @Override @Transactional(propagation = Propagation.REQUIRED) public PagedResult getAllVideos(Videos video, Integer isSaveRecord, Integer page, Integer pageSize) { String desc = video.getVideoDesc(); String userId = video.getUserId(); if (isSaveRecord != null && isSaveRecord == 1) { SearchRecords record = new SearchRecords(); String recordId = sid.nextShort(); record.setId(recordId); record.setContent(desc); searchRecordsMapper.insert(record); } PageHelper.startPage(page, pageSize); List<VideosVO> list = videosUsersMapper.queryAllVideos(desc,userId); PageInfo<VideosVO> pageList = new PageInfo<>(list); PagedResult result = new PagedResult(); result.setPage(page); result.setTotal(pageList.getPages()); result.setRows(list); result.setRecords(pageList.getTotal()); return result; } @Transactional(propagation = Propagation.SUPPORTS) @Override public List<String> gethostList() { return searchRecordsMapper.gethotList(); } @Override public void userLikeVideo(String userId, String videoId, String videoCreaterId) { // 1.保存用戶和视频的关联关系 String likeId = sid.nextShort(); UsersLikeVideos usersLikeVideos = new UsersLikeVideos(); usersLikeVideos.setId(likeId); usersLikeVideos.setUserId(userId); usersLikeVideos.setVideoId(videoId); usersLikeVideosMapper.insert(usersLikeVideos); // 2.视频喜欢的累加 videosUsersMapper.addVideoLikeCount(videoId); // 3. 用户喜欢的累加 usersMapper.addReceiveLikeCount(userId); } @Override public void userUnLikeVideo(String userId, String videoId, String videoCreaterId) { Example example = new Example(UsersLikeVideos.class); Criteria criteria = example.createCriteria(); criteria.andEqualTo("userId", userId); criteria.andEqualTo("videoId", videoId); usersLikeVideosMapper.deleteByExample(example); // 2.视频喜欢的累减 videosUsersMapper.reduceVideoLikeCount(videoId); // 3. 用户喜欢的累减 usersMapper.reduceReceiveLikeCount(userId); } @Override public PagedResult queryMyLikeVideos(String userId, Integer page, Integer pageSize) { PageHelper.startPage(page,pageSize); List<VideosVO> list = videosUsersMapper.queryMyLikeVideos(userId); PageInfo<VideosVO> pageList = new PageInfo<>(list); PagedResult pagedResult = new PagedResult(); pagedResult.setTotal(pageList.getPages()); pagedResult.setRows(list); pagedResult.setPage(page); pagedResult.setRecords(pageList.getTotal()); return pagedResult; } @Override public PagedResult queryMyFollowVideos(String userId, Integer page, Integer pageSize) { PageHelper.startPage(page,pageSize); List<VideosVO> list = videosUsersMapper.queryMyFollowVideos(userId); PageInfo<VideosVO> pageList = new PageInfo<>(list); PagedResult pagedResult = new PagedResult(); pagedResult.setTotal(pageList.getPages()); pagedResult.setRows(list); pagedResult.setPage(page); pagedResult.setRecords(pageList.getTotal()); return pagedResult; } }
VideosUsersMapper.java
package com.idig8.mapper; import java.util.List; import org.apache.ibatis.annotations.Param; import com.idig8.pojo.vo.VideosVO; import com.idig8.utils.MyMapper; public interface VideosUsersMapper extends MyMapper<VideosVO> { public List<VideosVO> queryAllVideos(@Param("videoDesc") String videoDesc,@Param("userId")String userId); public void addVideoLikeCount(String videoId); public void reduceVideoLikeCount(String videoId); public List<VideosVO> queryMyLikeVideos(String userId); public List<VideosVO> queryMyFollowVideos(String userId); }
VideosUserMapper.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mapper namespace="com.idig8.mapper.VideosUsersMapper" > <resultMap id="BaseResultMap" type="com.idig8.pojo.vo.VideosVO" > <!-- WARNING - @mbg.generated --> <id column="id" property="id" jdbcType="VARCHAR" /> <result column="user_id" property="userId" jdbcType="VARCHAR" /> <result column="audio_id" property="audioId" jdbcType="VARCHAR" /> <result column="video_desc" property="videoDesc" jdbcType="VARCHAR" /> <result column="video_path" property="videoPath" jdbcType="VARCHAR" /> <result column="video_seconds" property="videoSeconds" jdbcType="REAL" /> <result column="video_width" property="videoWidth" jdbcType="INTEGER" /> <result column="video_height" property="videoHeight" jdbcType="INTEGER" /> <result column="cover_path" property="coverPath" jdbcType="VARCHAR" /> <result column="like_counts" property="likeCounts" jdbcType="BIGINT" /> <result column="status" property="status" jdbcType="INTEGER" /> <result column="create_time" property="createTime" jdbcType="TIMESTAMP" /> <result column="username" property="username" jdbcType="VARCHAR" /> <result column="face_image" property="faceImage" jdbcType="VARCHAR" /> <result column="nickname" property="nickname" jdbcType="VARCHAR" /> </resultMap> <select id="queryAllVideos" resultMap="BaseResultMap" parameterType="String"> select v.*,u.face_image,u.username,u.nickname from videos v left join users u on v.user_id = u.id where 1 = 1 <if test="videoDesc !=null and videoDesc != '' "> and v.video_desc like '%${videoDesc}%' </if> <if test="userId !=null and userId != '' "> and v.user_id = #{userId} </if> and v.status = 1 order by v.create_time </select> <update id="addVideoLikeCount" parameterType="String"> update videos set like_counts=like_counts+1 where id=#{videoId} </update> <update id="reduceVideoLikeCount" parameterType="String"> update videos set like_counts=like_counts-1 where id=#{videoId} </update> <select id="queryMyLikeVideos" resultMap="BaseResultMap" parameterType="String"> select v.*,u.face_image as face_image,u.nickname as nickname from videos v left join users u on v.user_id = u.id where v.id in (select ulv.video_id from users_like_videos ulv where ulv.user_id = #{userId}) and v.status = 1 order by v.create_time desc </select> <select id="queryMyFollowVideos" resultMap="BaseResultMap" parameterType="String"> select v.*,u.face_image as face_image,u.nickname as nickname from videos v left join users u on v.user_id = u.id where v.id in (select uf.user_id from users_fans uf where uf.fan_id = #{userId}) and v.status = 1 order by v.create_time desc </select> </mapper>
小程序开发
mine.js
// pages/mine/mine.js const app = getApp() var videoUtils = require('../../utils/videoUtils.js') Page({ /** * 页面的初始数据 */ data: { faceImage: "../../resource/images/noneface.png", nickname: "昵称", fansCounts: 0, followCounts: 0, receiveLikeCounts: 0, isMe:true, isFollow:false, publisherId: '', videoSelClass: "video-info", isSelectedWork: "video-info-selected", isSelectedLike: "", isSelectedFollow: "", myVideoList: [], myVideoPage: 1, myVideoTotal: 1, likeVideoList: [], likeVideoPage: 1, likeVideoTotal: 1, followVideoList: [], followVideoPage: 1, followVideoTotal: 1, myWorkFalg: false, myLikesFalg: true, myFollowFalg: true }, /** * 用户注销 */ logout: function(e) { var user = app.getGlobalUserInfo(); wx.showLoading({ title: '正在注销中。。。' }); wx.request({ url: app.serverUrl + "/logout?userId=" + user.id, method: "POST", header: { 'content-type': 'application/json' // 默认值 }, success: function(res) { console.log(res.data); var status = res.data.status; wx.hideLoading(); if (status == 200) { wx.showToast({ title: "用户注销成功~!", icon: 'none', duration: 3000 }) // app.userInfo = null; wx.removeStorageSync("userInfo"); wx.redirectTo({ url: '../userRegister/userRegister', }) } else if (status == 500) { wx.showToast({ title: res.data.msg, icon: 'none', duration: 3000 }) } } }) }, followMe: function (e) { var me = this; var user = app.getGlobalUserInfo(); var userId = user.id; var publisherId = me.data.publisherId; var followType = e.currentTarget.dataset.followtype; // 1:关注 0:取消关注 var url = ''; if (followType == '1') { url = '/user/beyourfans?userId=' + publisherId + '&fanId=' + userId; } else { url = '/user/dontbeyourfans?userId=' + publisherId + '&fanId=' + userId; } wx.showLoading(); wx.request({ url: app.serverUrl + url, method: 'POST', header: { 'content-type': 'application/json', // 默认值 'headerUserId': user.id, 'headerUserToken': user.userToken }, success: function () { wx.hideLoading(); if (followType == '1') { me.setData({ isFollow: true, fansCounts: ++me.data.fansCounts }) } else { me.setData({ isFollow: false, fansCounts: --me.data.fansCounts }) } } }) }, /** * 头像上传 */ uploadFace: function(e) { // var user = app.userInfo; var user = app.getGlobalUserInfo(); var me = this; wx.chooseImage({ count: 1, // 默认9 sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 success: function(res) { // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片 var tempFilePaths = res.tempFilePaths if (tempFilePaths.length > 0) { console.log(tempFilePaths[0]); wx.uploadFile({ url: app.serverUrl + "/user/uploadFace?userId=" + user.id, //仅为示例,非真实的接口地址 filePath: tempFilePaths[0], name: 'file', success: function(res) { var data = JSON.parse(res.data); console.log(data); wx.hideLoading(); if (data.status == 200) { wx.showToast({ title: "用户上传成功~!", icon: 'none', duration: 3000 }) me.setData({ faceUrl: app.serverUrl + data.data }) } else if (data.status == 500) { wx.showToast({ title: data.msg, icon: 'none', duration: 3000 }) } } }) } } }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function(params) { var me = this; var userInfo = app.getGlobalUserInfo(); var publisherId = params.publisherId; var userId = userInfo.id; if (publisherId != null && publisherId != '' && publisherId!=undefined){ userId = publisherId; me.setData({ isMe:false, publisherId: publisherId, }) } wx.showLoading({ title: '正在获取用户信息。。。' }); wx.request({ url: app.serverUrl + "/user/queryByUserId?userId=" + userId + "&fanId" + userInfo.id, method: "POST", header: { 'content-type': 'application/json', // 默认值 'headerUserId': userInfo.id, 'headerUserToken': userInfo.userToken }, success: function(res) { console.log(res.data); var status = res.data.status; if (status == 200) { var userInfo = res.data.data; wx.hideLoading(); var faceImage = me.data.faceUrl; if (userInfo.faceImage != null && userInfo.faceImage != '' && userInfo.faceImage != undefined) { faceImage = app.serverUrl + userInfo.faceImage; } me.setData({ faceImage: faceImage, fansCounts: userInfo.fansCounts, followCounts: userInfo.followCounts, receiveLikeCounts: userInfo.receiveLikeCounts, nickname: userInfo.nickname, isFollow: userInfo.follow }) me.getMyVideoList(1) } else if (status == 502){ wx.showToast({ title: res.data.msg, duration:3000, icon:'none', complete:function(){ wx.removeStorageSync("userInfo"); wx.navigateTo({ url: '../userLogin/userLogin', }) } }) } } }) }, uploadVideo: function(e) { videoUtils.uploadVideo(); }, doSelectWork: function () { this.setData({ isSelectedWork: "video-info-selected", isSelectedLike: "", isSelectedFollow: "", myWorkFalg: false, myLikesFalg: true, myFollowFalg: true, myVideoList: [], myVideoPage: 1, myVideoTotal: 1, likeVideoList: [], likeVideoPage: 1, likeVideoTotal: 1, followVideoList: [], followVideoPage: 1, followVideoTotal: 1 }); this.getMyVideoList(1); }, doSelectLike: function () { this.setData({ isSelectedWork: "", isSelectedLike: "video-info-selected", isSelectedFollow: "", myWorkFalg: true, myLikesFalg: false, myFollowFalg: true, myVideoList: [], myVideoPage: 1, myVideoTotal: 1, likeVideoList: [], likeVideoPage: 1, likeVideoTotal: 1, followVideoList: [], followVideoPage: 1, followVideoTotal: 1 }); this.getMyLikesList(1); }, doSelectFollow: function () { this.setData({ isSelectedWork: "", isSelectedLike: "", isSelectedFollow: "video-info-selected", myWorkFalg: true, myLikesFalg: true, myFollowFalg: false, myVideoList: [], myVideoPage: 1, myVideoTotal: 1, likeVideoList: [], likeVideoPage: 1, likeVideoTotal: 1, followVideoList: [], followVideoPage: 1, followVideoTotal: 1 }); this.getMyFollowList(1) }, getMyVideoList: function (page) { var me = this; // 查询视频信息 wx.showLoading(); // 调用后端 var serverUrl = app.serverUrl; wx.request({ url: serverUrl + '/video/showAll/?page=' + page + '&pageSize=6', method: "POST", data: { userId: me.data.userId }, header: { 'content-type': 'application/json' // 默认值 }, success: function (res) { console.log(res.data); var myVideoList = res.data.data.rows; wx.hideLoading(); var newVideoList = me.data.myVideoList; me.setData({ myVideoPage: page, myVideoList: newVideoList.concat(myVideoList), myVideoTotal: res.data.data.total, serverUrl: app.serverUrl }); } }) }, getMyLikesList: function (page) { var me = this; var userId = me.data.userId; // 查询视频信息 wx.showLoading(); // 调用后端 var serverUrl = app.serverUrl; wx.request({ url: serverUrl + '/video/showMyLike/?userId=' + userId + '&page=' + page + '&pageSize=6', method: "POST", header: { 'content-type': 'application/json' // 默认值 }, success: function (res) { console.log(res.data); var likeVideoList = res.data.data.rows; wx.hideLoading(); var newVideoList = me.data.likeVideoList; me.setData({ likeVideoPage: page, likeVideoList: newVideoList.concat(likeVideoList), likeVideoTotal: res.data.data.total, serverUrl: app.serverUrl }); } }) }, getMyFollowList: function (page) { var me = this; var userId = me.data.userId; // 查询视频信息 wx.showLoading(); // 调用后端 var serverUrl = app.serverUrl; wx.request({ url: serverUrl + '/video/showMyFollow/?userId=' + userId + '&page=' + page + '&pageSize=6', method: "POST", header: { 'content-type': 'application/json' // 默认值 }, success: function (res) { console.log(res.data); var followVideoList = res.data.data.rows; wx.hideLoading(); var newVideoList = me.data.followVideoList; me.setData({ followVideoPage: page, followVideoList: newVideoList.concat(followVideoList), followVideoTotal: res.data.data.total, serverUrl: app.serverUrl }); } }) }, // 点击跳转到视频详情页面 showVideo: function (e) { console.log(e); var myWorkFalg = this.data.myWorkFalg; var myLikesFalg = this.data.myLikesFalg; var myFollowFalg = this.data.myFollowFalg; if (!myWorkFalg) { var videoList = this.data.myVideoList; } else if (!myLikesFalg) { var videoList = this.data.likeVideoList; } else if (!myFollowFalg) { var videoList = this.data.followVideoList; } var arrindex = e.target.dataset.arrindex; var videoInfo = JSON.stringify(videoList[arrindex]); wx.redirectTo({ url: '../videoinfo/videoinfo?videoInfo=' + videoInfo }) }, // 到底部后触发加载 onReachBottom: function () { var myWorkFalg = this.data.myWorkFalg; var myLikesFalg = this.data.myLikesFalg; var myFollowFalg = this.data.myFollowFalg; if (!myWorkFalg) { var currentPage = this.data.myVideoPage; var totalPage = this.data.myVideoTotal; // 获取总页数进行判断,如果当前页数和总页数相等,则不分页 if (currentPage === totalPage) { wx.showToast({ title: '已经没有视频啦...', icon: "none" }); return; } var page = currentPage + 1; this.getMyVideoList(page); } else if (!myLikesFalg) { var currentPage = this.data.likeVideoPage; var totalPage = this.data.myLikesTotal; // 获取总页数进行判断,如果当前页数和总页数相等,则不分页 if (currentPage === totalPage) { wx.showToast({ title: '已经没有视频啦...', icon: "none" }); return; } var page = currentPage + 1; this.getMyLikesList(page); } else if (!myFollowFalg) { var currentPage = this.data.followVideoPage; var totalPage = this.data.followVideoTotal; // 获取总页数进行判断,如果当前页数和总页数相等,则不分页 if (currentPage === totalPage) { wx.showToast({ title: '已经没有视频啦...', icon: "none" }); return; } var page = currentPage + 1; this.getMyFollowList(page); } } })
mine.wxml
<view> <view class='container'> <image src="{{faceImage}}" class="face" bindtap='uploadFace'></image> <label class='nickname'>{{nickname}}</label> <block wx:if='{{isMe}}'> <button size='mini' class='primary' bindtap='uploadVideo'> 上传作品</button> <button size='mini' type='' class='logout' bindtap='logout'>注销</button> </block> <block wx:if='{{!isMe}}'> <block wx:if='{{isFollow}}'> <button size='mini' type='' class='follow' data-followType='0' bindtap='followMe'>已关注</button> </block> <block wx:if='{{!isFollow}}'> <button size='mini' type='primary' class='follow' data-followType='1' bindtap='followMe'>关注我</button> </block> </block> <view class='container-row'> <label class='info-items'>{{fansCounts}} 粉丝</label> <label class='info-items'>{{followCounts}} 关注</label> <label class='info-items'>{{receiveLikeCounts}} 获赞</label> </view> </view> </view> <view class="line"></view> <view class='container-video'> <!-- 发布过的作品 --> <view class='{{videoSelClass}} {{isSelectedWork}}' bindtap='doSelectWork'>作品</view> <!-- 收藏的点赞的视频 --> <view class='{{videoSelClass}} {{isSelectedLike}}' bindtap='doSelectLike'>收藏</view> <!-- 用户关注过人发表的视频 --> <view class='{{videoSelClass}} {{isSelectedFollow}}' bindtap='doSelectFollow'>关注</view> </view> <view class='container-video-list'> <view hidden='{{myWorkFalg}}'> <block wx:for="{{myVideoList}}"> <image src='{{serverUrl}}{{item.coverPath}}' class='videoImage' mode="aspectFill" bindtap='showVideo' data-arrindex='{{index}}'></image> </block> </view> <view hidden='{{myLikesFalg}}'> <block wx:for="{{likeVideoList}}"> <image src='{{serverUrl}}{{item.coverPath}}' class='videoImage' mode="aspectFill" bindtap='showVideo' data-arrindex='{{index}}'></image> </block> </view> <view hidden='{{myFollowFalg}}'> <block wx:for="{{followVideoList}}"> <image src='{{serverUrl}}{{item.coverPath}}' class='videoImage' mode="aspectFill" bindtap='showVideo' data-arrindex='{{index}}'></image> </block> </view> </view>
PS:基本操作,获取作品列表,关注列表,收藏列表
-
扫雷:我的Java之路--第一个小作品
2015-06-04 15:12:09这学期开始学Java,也许是为了工作,也许是对编程有了一点点兴趣,所以学的稍微有一点用心。而老师也只讲了一些基本的语法和操作,其他的都是自己一步步摸索来的,所以想写一点点东西来让以后的自己看看。废话不多说... -
[原创]我的作品:我的迷宫小游戏<Java版本>
2019-10-01 01:39:50这个小游戏是我选的第二个数据结构课程设计题目,觉得很有意思,也很有挑战性,对于一个自学Java的人来说写出这个小游戏我觉得无疑是一种鼓励,呵呵呵 实验题目: 随机生成一个迷宫图,迷宫大小为N*N,N预定义为常数... -
[原创]我的作品:我的算术24小游戏<Java版本>
2019-10-01 01:39:48下面是我的数据结构的课程设计题目 由于现在还没有验收,所以不好把代码直接附上来,过后一定发上来与大家分享一下,呵呵呵,如果时间可以的话,我会详细的讨论...使用的是Java Swing编程技术,采用了MVC的设计模式... -
java作品集:企业信息门户webtap
2020-06-08 14:41:51随着企业应用的软件越来越多,并且信息软件基本以B/S为主了,很多时候各种软件的...基于上述背景,个人利用业余时间在持续完善做一款小作品,或多或少的解决一点问题,虽然目前还没成熟,但是考虑再三,先开源出来,... -
java多线程小结
2017-09-10 01:58:31林炳文Evankaka原创作品。转载请注明出处http://blog.csdn.net/evankaka 写在前面的话:此文只能说是java多线程的一个入门,其实Java里头线程完全可以写一本书了,但是如果最基本的你都学掌握好,又怎么能更上一个... -
Android、Java、Php、Python作品大全
2019-05-27 15:45:43Android毕业设计、Java毕业设计、Php毕业设计、Python毕业设计作品大全 及时通讯类微信社交工具(前后端,APK) 高校教务管理(前后端,APK) 诗词音视频播放,非对称加解密(前后端,APK) 共享充电控制系统(PCB... -
Java小游戏之俄罗斯方块
2018-10-10 14:24:00前言:基于别人的作品上进行分析 1、划分对象 (1)小方块:Cell对象 (2)4个小方块组成的图形:Tetromino对象 (3)游戏面板:TetrisPanel对象 2、分析对象中应包含的属性和方法 (1)Cell类 private ... -
使用java实现持续移动的小球
2018-12-03 16:07:20原创作品,可以转载,地址http://www.4587.com/仅为自己学习作品,使用java的JFrame框架实现持续移动的小球。最核心的部分为实现小球移动的move()方法,在小球碰到墙壁四壁的时候得以反弹,不会移到墙壁之外MM图片... -
链接数据库的小作品
2013-11-02 21:25:37一个链接数据库的小作品,没什么技术技巧,仅供志同道合在学习java的同学参考参考 -
Java写的打地鼠小游戏
2017-12-05 14:17:18Java写的打地鼠小游戏,界面精美,压缩包内提供了源代码,素材以及编译打包好的jar包(可直接执行,经过多平台测试),原创作品,修改使用请注明原作者:muyangren907 -
2048小游戏Java课程设计报告书.docx
2020-07-04 10:10:34JAVA语言程序设计 课程设计报告 2048智力小游戏设计 专业班级 计算机科学与技术嵌入13-1 学生姓名 卓海有 学生学号 13031010166 小组成员 单建飞堵文斐李栋承梅孔伟 指导教师姓名 宋强 目录 TOC \o "1-5" \h \z 前言... -
java 图片文字水印 按文字多少自适应图片_小白也可做出专业级水印/海报丨毕业作品展播 01...
2020-12-24 22:03:351期零基础水印/海报设计训练营学员毕业作品展播@喵师傅三天!零基础也可做出专业级水印/海报1期零基础水印/海报设计训练营毕业寄语喵师傅:本着“让更多人能学会平面设计”的理念,喵师傅开发了用PPT做logo设计和... -
《Java从小白到大牛精简版》——前言
2017-09-16 16:17:05《Java从小白到大牛》纸质版已经上架了!!!内容简介本书是一本Java语言学习教程,读者群是零基础小白,通过本书的学习能够成为Java...版权声明《Java从小白到大牛精简版》免费电子图书是作者关东升原创作品,作者... -
java猜猜小游戏-源代码
2012-12-01 13:43:44java猜猜小游戏-源代码;是本来期末考试用的; 一、 作品题目 《猜猜小游戏》 二、 实现功能 1、 对数字的判断功能。 2、 每次判断的提示功能。 3、 重置功能。 4、 对界面的熟悉度,布局、控件的定位 等等。 三、 ...
-
TensorBoard的使用
-
MySQL 触发器
-
这个合同靠谱吗?
-
航天验证器运动参数摄影测量方法
-
linux 查看服务
-
DataStats:与数据科学有关的统计数据-源码
-
阴影效果
-
vue 刷新页面的三种方法
-
paradigm-shift:范式转换模板-源码
-
LVS + Keepalived 实现 MySQL 负载均衡与高可用
-
双颗粒凝聚气溶胶的吸湿增长模型及散射特性
-
MATLAB霍夫曼指针识别[GUI界面].rar
-
闭包与循环
-
Mycat 实现 MySQL的分库分表、读写分离、主从切换
-
用微服务spring cloud架构打造物联网云平台
-
华为1+X——网络系统建设与运维(高级)
-
MySQL 数据库权限管理(用户高级管理和精确访问控制)
-
不止是“焊门员”,Redmi K40又一次颠覆“性价比”
-
RSA2048、AES方式加密后端数据demo
-
MySQL Router 实现高可用、负载均衡、读写分离