package com.example.yin.controller;
import com.example.yin.common.FatalMessage;
import com.example.yin.common.ErrorMessage;
import com.example.yin.common.SuccessMessage;
import com.example.yin.common.WarningMessage;
import com.example.yin.constant.Constants;
import com.example.yin.domain.Consumer;
import com.example.yin.service.impl.ConsumerServiceImpl;
import org.apache.commons.lang3.ObjectUtils.Null;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@RestController
public class ConsumerController {
@Autowired
private ConsumerServiceImpl consumerService;
@Configuration
public static class MyPicConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/img/avatorImages/**")
.addResourceLocations(Constants.AVATOR_IMAGES_PATH);
}
}
/**
* 用户注册
*/
@ResponseBody
@RequestMapping(value = "/user/add", method = RequestMethod.POST)
public Object addUser(HttpServletRequest req) {
String username = req.getParameter("username").trim();
String password = req.getParameter("password").trim();
String sex = req.getParameter("sex").trim();
String phone_num = req.getParameter("phone_num").trim();
String email = req.getParameter("email").trim();
String birth = req.getParameter("birth").trim();
String introduction = req.getParameter("introduction").trim();
String location = req.getParameter("location").trim();
String avator = "/img/avatorImages/user.jpg";
if(consumerService.existUser(username)) {
return new WarningMessage("用户名已注册").getMessage();
}
Consumer consumer = new Consumer();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date myBirth = new Date();
try {
myBirth = dateFormat.parse(birth);
} catch (Exception e) {
e.printStackTrace();
}
consumer.setUsername(username);
consumer.setPassword(password);
consumer.setSex(new Byte(sex));
if ("".equals(phone_num)) {
consumer.setPhoneNum(null);
} else {
consumer.setPhoneNum(phone_num);
}
if ("".equals(email)) {
consumer.setEmail(null);
} else {
consumer.setEmail(email);
}
consumer.setBirth(myBirth);
consumer.setIntroduction(introduction);
consumer.setLocation(location);
consumer.setAvator(avator);
consumer.setCreateTime(new Date());
consumer.setUpdateTime(new Date());
try {
boolean res = consumerService.addUser(consumer);
if (res) {
return new SuccessMessage<Null>("注册成功").getMessage();
} else {
return new ErrorMessage("注册失败").getMessage();
}
} catch (DuplicateKeyException e) {
return new FatalMessage(e.getMessage()).getMessage();
}
}
/**
* 登录判断
*/
@ResponseBody
@RequestMapping(value = "/user/login/status", method = RequestMethod.POST)
public Object loginStatus(HttpServletRequest req, HttpSession session) {
String username = req.getParameter("username");
String password = req.getParameter("password");
boolean res = consumerService.veritypasswd(username, password);
if (res) {
session.setAttribute("username", username);
return new SuccessMessage<List<Consumer>>("登录成功", consumerService.loginStatus(username)).getMessage();
} else {
return new ErrorMessage("用户名或密码错误").getMessage();
}
}
/**
* 返回所有用户
*/
@RequestMapping(value = "/user", method = RequestMethod.GET)
public Object allUser() {
return new SuccessMessage<List<Consumer>>(null, consumerService.allUser()).getMessage();
}
/**
* 返回指定 ID 的用户
*/
@RequestMapping(value = "/user/detail", method = RequestMethod.GET)
public Object userOfId(HttpServletRequest req) {
String id = req.getParameter("id");
return new SuccessMessage<List<Consumer>>(null, consumerService.userOfId(Integer.parseInt(id))).getMessage();
}
/**
* 删除用户
*/
@RequestMapping(value = "/user/delete", method = RequestMethod.GET)
public Object deleteUser(HttpServletRequest req) {
String id = req.getParameter("id");
boolean res = consumerService.deleteUser(Integer.parseInt(id));
if (res) {
return new SuccessMessage<Null>("删除成功").getMessage();
} else {
return new ErrorMessage("删除失败").getMessage();
}
}
/**
* 更新用户信息
*/
@ResponseBody
@RequestMapping(value = "/user/update", method = RequestMethod.POST)
public Object updateUserMsg(HttpServletRequest req) {
String id = req.getParameter("id").trim();
String username = req.getParameter("username").trim();
String sex = req.getParameter("sex").trim();
String phone_num = req.getParameter("phone_num").trim();
String email = req.getParameter("email").trim();
String birth = req.getParameter("birth").trim();
String introduction = req.getParameter("introduction").trim();
String location = req.getParameter("location").trim();
// System.out.println(username);
Consumer consumer = new Consumer();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date myBirth = new Date();
try {
myBirth = dateFormat.parse(birth);
} catch (Exception e) {
e.printStackTrace();
}
consumer.setId(Integer.parseInt(id));
consumer.setUsername(username);
consumer.setSex(new Byte(sex));
consumer.setPhoneNum(phone_num);
consumer.setEmail(email);
consumer.setIntroduction(introduction);
consumer.setLocation(location);
consumer.setUpdateTime(new Date());
consumer.setBirth(myBirth);
boolean res = consumerService.updateUserMsg(consumer);
if (res) {
return new SuccessMessage<Null>("修改成功").getMessage();
} else {
return new ErrorMessage("修改失败").getMessage();
}
}
/**
* 更新用户密码
*/
@ResponseBody
@RequestMapping(value = "/user/updatePassword", method = RequestMethod.POST)
public Object updatePassword(HttpServletRequest req) {
String id = req.getParameter("id").trim();
String username = req.getParameter("username").trim();
String old_password = req.getParameter("old_password").trim();
String password = req.getParameter("password").trim();
boolean res = consumerService.veritypasswd(username, old_password);
if (!res) {
return new ErrorMessage("密码输入错误").getMessage();
}
Consumer consumer = new Consumer();
consumer.setId(Integer.parseInt(id));
consumer.setPassword(password);
boolean result = consumerService.updatePassword(consumer);
if (result) {
ret
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
毕业设计基于springboot+vue的音乐网的实现.zip 实现功能: 音乐播放 用户登录注册 用户信息编辑、头像修改 歌曲、歌单搜索 歌单打分 歌单、歌曲评论 歌单列表、歌手列表分页显示 歌词同步显示 音乐收藏、下载、拖动控制、音量控制 后台对用户、歌曲、歌手、歌单信息的管理 技术栈: 后端 SpringBoot + MyBatis 前端 Vue3.0 + TypeScript + Vue-Router + Vuex + Axios + ElementPlus + Echarts 开发环境: JDK: jdk-8u141 mysql:mysql-5.7 node:v14.17.3 IDE:IntelliJ IDEA 2021、webstorm2021 毕业设计基于springboot+vue的音乐网的实现.zip毕业设计基于springboot+vue的音乐网的实现.zip毕业设计基于springboot+vue的音乐网的实现.zip毕业设计基于springboot+vue的音乐网的实现.zip毕业设计基于springboot+vue的音乐网的实现.zip
资源推荐
资源详情
资源评论
收起资源包目录
毕业设计基于springboot+vue的音乐网的实现.zip (591个子文件)
.browserslistrc 40B
.browserslistrc 40B
.browserslistrc 40B
.browserslistrc 40B
ConsumerController.class 8KB
ConsumerController.class 8KB
SongController.class 8KB
SongController.class 8KB
SingerController.class 6KB
SingerController.class 6KB
SongListController.class 6KB
SongListController.class 6KB
CommentController.class 4KB
CommentController.class 4KB
CollectController.class 4KB
CollectController.class 4KB
Consumer.class 3KB
Consumer.class 3KB
ListSongController.class 3KB
ListSongController.class 3KB
RankListController.class 3KB
RankListController.class 3KB
Song.class 3KB
Song.class 3KB
ConsumerServiceImpl.class 3KB
ConsumerServiceImpl.class 3KB
WebCharacterEncodingFilter.class 3KB
WebCharacterEncodingFilter.class 3KB
Comment.class 2KB
Comment.class 2KB
Singer.class 2KB
Singer.class 2KB
SongServiceImpl.class 2KB
SongServiceImpl.class 2KB
SingerServiceImpl.class 2KB
SingerServiceImpl.class 2KB
SongListServiceImpl.class 2KB
SongListServiceImpl.class 2KB
AdminController.class 2KB
AdminController.class 2KB
Collect.class 2KB
Collect.class 2KB
SongList.class 2KB
SongList.class 2KB
ListSongServiceImpl.class 2KB
ListSongServiceImpl.class 2KB
CommentServiceImpl.class 2KB
CommentServiceImpl.class 2KB
YinMusicApplicationTests.class 2KB
YinMusicApplicationTests.class 2KB
RankListServiceImpl.class 2KB
RankListServiceImpl.class 2KB
CollectServiceImpl.class 2KB
CollectServiceImpl.class 2KB
SuccessMessage.class 1KB
SuccessMessage.class 1KB
SongController$MyPicConfig.class 1KB
SongController$MyPicConfig.class 1KB
ConsumerController$MyPicConfig.class 1KB
ConsumerController$MyPicConfig.class 1KB
SongListController$MyPicConfig.class 1KB
SongListController$MyPicConfig.class 1KB
SingerController$MyPicConfig.class 1KB
SingerController$MyPicConfig.class 1KB
WebMvcConfig.class 1KB
WebMvcConfig.class 1KB
Admin.class 1KB
Admin.class 1KB
ConsumerMapper.class 1KB
ConsumerMapper.class 1KB
RankList.class 1KB
RankList.class 1KB
SongMapper.class 1KB
SongMapper.class 1KB
ListSong.class 1KB
ListSong.class 1KB
SingerMapper.class 1KB
SingerMapper.class 1KB
Constants.class 1KB
Constants.class 1KB
SongListMapper.class 1KB
SongListMapper.class 1KB
CollectMapper.class 1KB
CollectMapper.class 1KB
WarningMessage.class 992B
WarningMessage.class 992B
ErrorMessage.class 984B
FatalMessage.class 984B
ErrorMessage.class 984B
FatalMessage.class 984B
ConsumerService.class 983B
ConsumerService.class 983B
ListSongMapper.class 980B
ListSongMapper.class 980B
AdminServiceImpl.class 956B
AdminServiceImpl.class 956B
CommentMapper.class 914B
CommentMapper.class 914B
SongService.class 861B
SongService.class 861B
共 591 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
程序猿阿存
- 粉丝: 1245
- 资源: 1804
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功