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
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
软件架构 - java后台:music-server - 用户前台:music-client - 管理员前台:music-manage 前端采用的是基于VUE的ElmentUI框架开发,后端是基于springboot框架开发,数据库使用的是Mysql,分为三个项目,分别是用户前端,管理员前端,后台接口集成 技术选型 | Spring Boot| 2.1.6| MVC核心框架 | | Spring Security oauth2 | 2.1.5| 认证和授权框架| | MyBatis| 3.5.0| ORM框架 | | MyBatisPlus| 3.1.0| 基于mybatis,使用lambda表达式的 | | Swagger-UI | 2.9.2| 文档生产工具| | Hibernator-Validator | 6.0.17 | 验证框架| | redisson | 3.10.6 | 对redis进行封装、集成分布式锁等 | | hikari | 3.2.0| 数据库连接池| | log4j2 | 2.11.2 | 更快的log日志工具 | | fst| 2.57 | 更快的序列化
资源推荐
资源详情
资源评论
收起资源包目录
大学生毕设+基于SpringBoot和Vue、MyBatis带GUI界面+云音乐管理系统(前后端源码+数据库+环境搭建步骤) (381个子文件)
.browserslistrc 40B
.browserslistrc 40B
ConsumerController.class 8KB
SongController.class 8KB
SingerController.class 6KB
SongListController.class 6KB
CommentController.class 4KB
CollectController.class 4KB
Consumer.class 3KB
ListSongController.class 3KB
RankListController.class 3KB
Song.class 3KB
ConsumerServiceImpl.class 3KB
WebCharacterEncodingFilter.class 3KB
Comment.class 2KB
Singer.class 2KB
SongServiceImpl.class 2KB
SingerServiceImpl.class 2KB
SongListServiceImpl.class 2KB
AdminController.class 2KB
Collect.class 2KB
SongList.class 2KB
ListSongServiceImpl.class 2KB
CommentServiceImpl.class 2KB
YinMusicApplicationTests.class 2KB
RankListServiceImpl.class 2KB
CollectServiceImpl.class 2KB
SuccessMessage.class 1KB
SongController$MyPicConfig.class 1KB
ConsumerController$MyPicConfig.class 1KB
SongListController$MyPicConfig.class 1KB
SingerController$MyPicConfig.class 1KB
WebMvcConfig.class 1KB
Admin.class 1KB
ConsumerMapper.class 1KB
RankList.class 1KB
SongMapper.class 1KB
ListSong.class 1KB
SingerMapper.class 1KB
Constants.class 1KB
SongListMapper.class 1KB
CollectMapper.class 1KB
YinMusicApplication.class 1002B
WarningMessage.class 992B
ErrorMessage.class 984B
FatalMessage.class 984B
ConsumerService.class 983B
ListSongMapper.class 980B
AdminServiceImpl.class 956B
CommentMapper.class 914B
SongService.class 861B
SingerService.class 800B
SongListService.class 707B
AdminMapper.class 695B
RankListMapper.class 658B
ListSongService.class 639B
CommentService.class 577B
CollectService.class 545B
RankListService.class 394B
AdminService.class 246B
mvnw.cmd 6KB
main.css 649B
.gitignore 176B
.gitignore 98B
.gitignore 0B
index.html 611B
index.html 611B
favicon.ico 17KB
favicon.ico 17KB
yin.iml 9KB
music-manage.iml 458B
music-client.iml 458B
mysql-connector-java-8.0.13.jar 2.03MB
mysql-connector-java-8.0.13.jar 2.03MB
maven-wrapper.jar 47KB
ConsumerController.java 9KB
SongController.java 9KB
SingerController.java 6KB
SongListController.java 6KB
CommentController.java 4KB
YinMusicApplicationTests.java 3KB
CollectController.java 3KB
ListSongController.java 3KB
Consumer.java 3KB
RankListController.java 2KB
Song.java 2KB
ConsumerServiceImpl.java 2KB
Comment.java 2KB
WebCharacterEncodingFilter.java 2KB
SongServiceImpl.java 1KB
Singer.java 1KB
SongListServiceImpl.java 1KB
AdminController.java 1KB
Collect.java 1KB
SingerServiceImpl.java 1KB
RankListServiceImpl.java 1KB
CommentServiceImpl.java 1KB
SongList.java 1KB
ListSongServiceImpl.java 1KB
CollectServiceImpl.java 1KB
共 381 条
- 1
- 2
- 3
- 4
资源评论
心兰相随引导者
- 粉丝: 1146
- 资源: 5639
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Node.js和WebSocket的音频数据流分析音乐节奏展示设计源码
- 基于Surface框架的CURD和后台页面快速搭建设计源码
- 基于Snowflake算法的分布式唯一ID生成器UidGenerator在SpringBoot中的整合与应用设计源码
- 四轴直交机械手工程图机械结构设计图纸和其它技术资料和技术方案非常好100%好用.zip
- 基于Java语言的RabbitMQ精品课程设计源码
- 四合一测试设备(含bom)sw17可编辑工程图机械结构设计图纸和其它技术资料和技术方案非常好100%好用.zip
- 基于SSM框架和JavaScript的教材管理系统设计源码
- 基于JqueryMobile框架的kLink通讯录应用设计源码
- 基于2024暑假鸿蒙应用师资班培训的TeachObject20240715_01设计源码
- 卧式气动膏体灌装机工程图机械结构设计图纸和其它技术资料和技术方案非常好100%好用.zip
- 基于Vue的JavaScript光雨电子书后台源码
- 基于山东大学经验的转专业学生攻略设计源码
- 基于51单片机的蓝牙循迹小车设计源码
- Teaching Small Language Models to Reason 小模型如何在大模型中生效
- 基于Html和Ruby语言的test项目设计源码
- 线材激光焊接裁断机工程图机械结构设计图纸和其它技术资料和技术方案非常好100%好用.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功