基于javaweb+jsp的精美风在线音乐网站(java+JDBC+C3P0+servlet+mysql+JSP)
1.运行环境
环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
JSP + C3P0+ Servlert + html+ css + JavaScript + JQuery + Ajax + Fileupload等等
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
statusMsg = "参数数字型错误!!!";
statusCode = 201;
return webResponse.getWebResponse(statusCode, statusMsg, data);
}
User userVo = this.userService.getById(user_idNumNumeri);
if (userVo != null && userVo.getUser_id() > 0) {
data = userVo;
statusMsg = "获取单条数据成功!!!";
} else {
statusCode = 202;
statusMsg = "no record!!!";
}
user_Id = musicLinkService2.getUserId(user_name, user_password);
} catch (Exception e) {
}
int userId = 0;
try {
// 判断字符串是否是数字,并且抛出异常
boolean NotisNum = (user_Id.equals("null"));
// System.out.println(NotisNum);
if (!NotisNum) {
userId = Integer.parseInt(user_Id);
}
} catch (Exception e) {
}
System.out.println("歌曲名:" + songName);
String jSong = this.musicLinkService.judgeSong(songName, userId);
int my_Id = 0;
}
return webResponse.getWebResponse(statusCode, statusMsg, data);
}
@RequestMapping(value = "/getUserById", produces = "application/json;charset=UTF-8")
@ResponseBody
public WebResponse getUserById(String user_id) {
Object data = user_id;
Integer statusCode = 200;
String statusMsg = "";
if (user_id == null || user_id.length() == 0 || user_id.length() > 11) {
statusMsg = "参数为空或参数过长错误!!!";
statusCode = 201;
return webResponse.getWebResponse(statusCode, statusMsg, data);
}
Integer user_idNumNumeri = user_id.matches("^[0-9]*$") ? Integer.parseInt(user_id) : 0;
if (user_idNumNumeri == 0) {
statusMsg = "参数数字型错误!!!";
statusCode = 201;
return webResponse.getWebResponse(statusCode, statusMsg, data);
my_Id = Integer.parseInt(jSong);
}
} catch (Exception e) {
}
if (my_Id > 0) {
statusCode = 201;
statusMsg = "已收藏,请不要重复收藏!";
} else {
this.musicLinkService.insertSongRearch(song_id, userId);
}
System.out.println("收藏歌曲的用户id:" + userId);
return webResponse.getWebResponse(statusCode, statusMsg, data);
用户管理控制层:
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
boolean NotisNum = (user_Id.equals("null"));
// System.out.println(NotisNum);
if (!NotisNum) {
userId = Integer.parseInt(user_Id);
}
} catch (Exception e) {
}
//
session.setAttribute("tname", tname);
session.setAttribute("userId", userId);
Object data = null;
String statusMsg = "";
Integer statusCode = 200;
Map<String, String> paramMap = new HashMap<String, String>();
paramMap.put("user_name", user_name);
paramMap.put("user_password", user_password);
data = paramMap;
User user = new User();
user.setUser_id(userId);
System.out.println("登录的id:" + user.getUser_id());
System.out.println("登录的用户名:" + session.getAttribute(tname));
System.out.println("前端,用户名:" + user_name + " 密码:" + user_password);
System.out.println("根据前端在数据库中查找到的用户名:" + tname + " 用户的id:" + userId);
// 用户名和密码匹配不成功,则返回的用户名为空
return webResponse.getWebResponse(statusCode, statusMsg, data);
}
@RequestMapping(value = "/getAdminUserList", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@ResponseBody
public String getAdminTestList(HttpServletRequest request, HttpServletResponse response, HttpSession session,
@RequestParam(defaultValue = "1", required = false) Integer pageNo,
@RequestParam(defaultValue = "10", required = false) Integer pageSize,
@RequestParam(defaultValue = "正常", required = false) String tbStatus,
@RequestParam(required = false) String keyword,
@RequestParam(defaultValue = "test_id", required = false) String order,
@RequestParam(defaultValue = "desc", required = false) String desc) {
Object data = null;
String statusMsg = "";
int statusCode = 200;
LinkedHashMap<String, String> condition = new LinkedHashMap<String, String>();
if (tbStatus != null && tbStatus.length() > 0) {
condition.put("tb_status='" + tbStatus + "'", "and");
}
if (keyword != null && keyword.length() > 0) {
*
*
* @RequestParam(value="aa" required=false)
* 1.可以对传入参数指定参数名
*
* // 下面的对传入参数指定为aa,如果前端不传aa参数名,会报错
* @RequestParam(value="aa") String inputStr
*
* 2、可以通过required=false或者true来要求@RequestParam配置的前端参数是否一定要传
*
* 3、如果@requestParam注解的参数是int类型,并且required=false,此时如果不传参数的话,会报错。原因是,required=false时,不传参数的话,
* 会给参数赋值null,这样就会把null赋值给了int,因此会报错。
*
* @RequestMapping :是一个用来处理请求地址映射的注解,可用于类或方法上。
* 用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径;
* 用于方法上,表示在类的父路径下追加方法上注解中的地址将会访问到该方法
*
* @Autowired:@Autowired 注释,它可以对类成员变量、方法及构造函数进行标注,完成自动装配的工作。 通过 @Autowired的使用来消除 set ,get方法。
*
*
* @Resource:@Autowired与@Resource都可以用来装配bean. 都可以写在字段上,或写在setter方法上。
*
*
* @Responsebody 注解表示该方法的返回的结果直接写入 HTTP 响应正文(ResponseBody)中,
* 一般在异步获取数据时使用,通常是在使用 @RequestMapping 后,返回值通常解析为跳转路径,
* 加上 @Responsebody 后返回结果不会被解析为跳转路径,而是直接写入HTTP 响应正文中。
* 作用: 该注解用于将Controller的方法返回的对象,通过适当的HttpMessageConverter转换为指定格式后,写入到Response对象的body数据区。
*
*
*
*
* @RequestParam(value="aa" required=false)
* 1.可以对传入参数指定参数名
*
* // 下面的对传入参数指定为aa,如果前端不传aa参数名,会报错
* @RequestParam(value="aa") String inputStr
}
System.out.println("歌曲名:" + songName);
String jSong = this.musicLinkService.judgeSong(songName, userId);
int my_Id = 0;
try {
// 判断字符串是否是数字,并且抛出异常
// boolean NotisNum
// =(user_Id.equals(null)||user_Id.equals("")||user_Id.equals("null"));
boolean NotisNum = (jSong.equals("null"));
if (!NotisNum) {
my_Id = Integer.parseInt(jSong);
}
} catch (Exception e) {
}
if (my_Id > 0) {
statusCode = 201;
statusMsg = "已收藏,请不要重复收藏!";
} else {
this.musicLinkService.insertSongRearch(song_id, userId);
}
System.out.println("收藏歌曲的用户id:" + userId);
return webResponse.getWebResponse(statusCode, statusMsg, data);
用户管理控制层:
try {
List<MyMusic> list = this.myMusicService.getMyMusicList(userId);
Map<Object, Object> map = new HashMap<Object, Object>();
// map.put("total", count);
int size = list.size();
if (size > 0) {
List<MyMusic> listFont = new ArrayList<MyMusic>();
MyMusic vo;
MyMusic voFont = new MyMusic();
for (int i = 0; i < size; i++) {
vo = list.get(i);
// 通过java反射将类中当前属性字段对应的内容复制到另外一个类中
BeanUtils.copyProperties(vo, voFont);
listFont.add(voFont);
voFont = new MyMusic();
}
map.put("list", listFont);
data = map;
statusMsg = "根据条件获取分页数据成功!!!";
} else {
map.put("list", list);
data = map;
statusCode = 202;
statusMsg = "no record!!!";
@Resource
protected IMusicLinkService musicLinkService;
@Resource
protected MusicLinkService musicLinkService2;
/**
* //常用注解快速解释:
* @Controller :用于标记在一个类上,使用它标记的类就是一个SpringMVC Controller 对象。
* 分发处理器将会扫描使用了该注解的类的方法,并检测该方法是否使用了@RequestMapping 注解。@Controller
* 只是定义了一个控制器类,而使用@RequestMapping 注解的方法才是真正处理请求的处理器。
*
} else {
statusMsg = "no record!!!";
}
return webResponse.getWebResponse(statusMsg, data);
}
@RequestMapping(value = "/getUserList", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@ResponseBody
public WebResponse getTestList(HttpServletRequest request, HttpServletResponse response, HttpSession session,
@RequestParam(defaultValue = "1", required = false) Integer pageNo,
@RequestParam(defaultValue = "10", required = false) Integer pageSize,
user.setUser_password(user_password); // 建立密码
}
if (user_password != null && !("".equals(user_password.trim()))) {
if (user_password.length() > 65535) {
statusMsg = " 参数长度过长错误,info";
statusCode = 201;
return webResponse.getWebResponse(statusCode, statusMsg, data);
}
}
if (isAdd) {
// 插入语句,插入数据库,重要
this.userService.insert(user);
if (user.getUser_id() > 0) {
statusMsg = "成功插入!!!";
} else {
statusCode = 202;
statusMsg = "insert false";
}
return webResponse.getWebResponse(statusCode, statusMsg, data);
}
int num = this.userService.update(user);
if (num > 0) {
} catch (Exception e) {
}
//
session.setAttribute("tname", tname);
session.setAttribute("userId", userId);
Object data = null;
String statusMsg = "";
Integer statusCode = 200;
Map<String, String> paramMap = new HashMap<String, String>();
paramMap.put("user_name", user_name);
paramMap.put("user_password", user_password);
data = paramMap;
User user = new User();
user.setUser_id(userId);
System.out.println("登录的id:" + user.getUser_id());
System.out.println("登录的用户名:" + session.getAttribute(tname));
} else {
map.put("list", list);
data = map;
statusCode = 202;
statusMsg = "no record!!!";
}
return JSON.toJSONString(data);
}
@RequestMapping(value = "/delUser", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@ResponseBody
public WebResponse delTest(int id) {
int num = this.userService.delBySign(id);
Object data = null;
String statusMsg = "";
if (num > 0) {
statusMsg = "成功删除!!!";
} else {
statusMsg = "no record!!!";
data = map;
// for (int i = 0; i < map.size(); i++) {
// System.out.println(map.get(listFont).toString());
// }
//
statusMsg = "根据条件获取分页数据成功!!!";
} else {
map.put("list", list);
data = map;
statusCode = 202;
statusMsg = "no record!!!";
return webResponse.getWebResponse(statusCode, statusMsg, data);
}
return webResponse.getWebResponse(statusCode, statusMsg, data);
}
// 歌曲收藏
return webResponse.getWebResponse(statusCode, statusMsg, data);
}
} catch (Exception e) {
}
System.out.println("判断用户是否重复:" + rearchName);
if (user_id == null || user_id.length() == 0) {
return this.addUser(request, response, session, user_name, user_password);
} else {
return this.editUser(request, response, session, user_id, user_name, user_password);
}
}
// 添加用户
@RequestMapping(value = "/addUser", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@ResponseBody
public WebResponse addUser(HttpServletRequest request, HttpServletResponse response, HttpSession session,
String user_name, String user_password) {
Object data = null;
String statusMsg = "";
Integer statusCode = 200;
Map<String, String> paramMap = new HashMap<String, String>();
paramMap.put("user_name", user_name);
paramMap.put("user_password", user_password);
return webResponse.getWebResponse(statusMsg, data);
}
@RequestMapping(value = "/getUserList", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@ResponseBody
public WebResponse getTestList(HttpServletRequest request, HttpServletResponse response, HttpSession session,
@RequestParam(defaultValue = "1", required = false) Integer pageNo,
@RequestParam(defaultValue = "10", required = false) Integer pageSize,
@RequestParam(defaultValue = "正常", required = false) String tbStatus,
@RequestParam(required = false) String keyword,
@RequestParam(defaultValue = "test_id", required = false) String order,
@RequestParam(defaultValue = "desc", required = false) String desc) {
Object data = null;
String statusMsg = "";
int statusCode = 200;
LinkedHashMap<String, String> condition = new LinkedHashMap<String, String>();
/*
* if (tbStatus != null && tbStatus.length() > 0) { condition.put("tb_status='"
* + tbStatus + "'", "and"); }
*/
/*
*
*/
private WebResponse addOrEditUser(HttpServletRequest request, HttpServletResponse response, HttpSession session,
Object data, User user, String user_name, String user_password, boolean isAdd) {
String statusMsg = "";
Integer statusCode = 200;
if (user_name != null && !("".equals(user_name.trim()))) {
if (user_name.length() > 255) {
statusMsg = " 参数长度过长错误,testName";
statusCode = 201;
return webResponse.getWebResponse(statusCode, statusMsg, data);
}
// 重要,建立数据,以便后期数据库能调用数据
user.setUser_name(user_name); // 建立用户名
user.setUser_password(user_password); // 建立密码
}
if (user_password != null && !("".equals(user_password.trim()))) {
if (user_password.length() > 65535) {
statusMsg = " 参数长度过长错误,info";
statusCode = 201;
return webResponse.getWebResponse(statusCode, statusMsg, data);
}
}
System.out.println();
statusMsg = "用户或密码错误!";
statusCode = 201;
return webResponse.getWebResponse(statusCode, statusMsg, data);
} else {
statusCode = 200;
webResponse.setStatusCode(statusCode);
System.out.println("状态码:" + webResponse.getStatusCode());
System.out.println("登录成功了");
System.out.println();
return webResponse.getWebResponseUserId(statusCode, statusMsg, data, userId);
}
}
// 更改密码 更改密码 更改密码
@RequestMapping(value = "/resetUserPassword", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@ResponseBody
public WebResponse resetUserPassword(HttpServletRequest request, HttpSession session) {
Object data = null;
String statusMsg = "";
Integer statusCode = 200;
}
return webResponse.getWebResponse(statusCode, statusMsg, data);
}
// 歌曲收藏
@RequestMapping(value = "/addMusicCollect", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@ResponseBody
public WebResponse addMusicCollect(HttpServletRequest request, HttpServletResponse response, HttpSession session,
@RequestParam(required = false) int song_id, @RequestParam(required = false) String user_name,
@RequestParam(required = false) String user_password, @RequestParam(required = false) String songName) {
WebResponse webResponse = new WebResponse();
MusicLink musicLink = new MusicLink();
User user = new User();
System.out.println("歌曲id:" + song_id + " 用户名:" + user_name + " 户用密码:" + user_password);
Object data = null;
String statusMsg = "";
return JSON.toJSONString(data);
}
@RequestMapping(value = "/delUser", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@ResponseBody
public WebResponse delTest(int id) {
int num = this.userService.delBySign(id);
Object data = null;
String statusMsg = "";
if (num > 0) {
statusMsg = "成功删除!!!";
} else {
statusMsg = "no record!!!";
}
return webResponse.getWebResponse(statusMsg, data);
}
}
我的音乐歌单管理:
@Controller
// 取参数的方法,对应登录表单中的用户名
String user_name = request.getParameter("user_name");
String newUser_password = request.getParameter("newUser_password");
try {
uId = (int) this.userService2.resetPassword(user_name, newUser_password);
System.out.println("修改密码返回的id:" + uId);
} catch (Exception e) {
}
return webResponse.getWebResponse(statusCode, statusMsg, data);
}
// 用户注册
@RequestMapping(value = "/addOrEditUser", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@ResponseBody
public WebResponse addOrEditTest(HttpServletRequest request, HttpServletResponse response, HttpSession session,
String user_id, @RequestParam(required = false) String user_name,
@RequestParam(required = false) String user_password) {
Object data = null;
String statusMsg = "用户名已存在,请重新注册!";
Integer statusCode = 201;
order = order + " desc";
}
List<User> list = this.userService.getList(condition, pageNo, pageSize, order, field);
Map<Object, Object> map = new HashMap<Object, Object>();
map.put("total", count);
int size = list.size();
if (size > 0) {
List<User> listFont = new ArrayList<User>();
User vo;
User voFont = new User();
for (int i = 0; i < size; i++) {
}
if (isAdd) {
// 插入语句,插入数据库,重要
this.userService.insert(user);
if (user.getUser_id() > 0) {
statusMsg = "成功插入!!!";
} else {
statusCode = 202;
statusMsg = "insert false";
}
return webResponse.getWebResponse(statusCode, statusMsg, data);
}
int num = this.userService.update(user);
if (num > 0) {
statusMsg = "成功修改!!!";
} else {
statusCode = 202;
statusMsg = "update false";
}
return webResponse.getWebResponse(statusCode, statusMsg, data);
}
@RequestMapping(value = "/getUserById", produces = "application/json;charset=UTF-8")
@ResponseBody
public WebResponse getUserById(String user_id) {