1.运行环境
环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
JSP + C3P0+ Servlert + html+ css + JavaScript + JQuery + Ajax + Fileupload等等
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
}
System.out.println("收藏歌曲的用户id:" + userId);
return webResponse.getWebResponse(statusCode, statusMsg, data);
}
}
用户管理控制层:
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
protected WebResponse webResponse;
@Resource
protected IUserService userService;
@Resource
protected IMyMusicService MyMusicService;
@Autowired
UserService userService2;
String newName = null;
// 登录功能
@RequestMapping(value = "/loginPage", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@ResponseBody
public WebResponse loginCon(HttpServletRequest request, HttpSession session) {
// 取参数的方法,对应登录表单中的用户名name="user_name"
String user_name = request.getParameter("user_name");
@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) {
StringBuffer buf = new StringBuffer();
buf.append("(");
buf.append("test_name like '%").append(keyword).append("%'");
buf.append(" or ");
buf.append("info like '%").append(keyword).append("%'");
buf.append(" or ");
buf.append("other like '%").append(keyword).append("%'");
// 插入语句,插入数据库,重要
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
Integer statusCode = 201;
String rearchName = null;
try {
rearchName = this.userService.rearchUserName(user_name);
if (!(rearchName.equals("null"))) {
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 = "";
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);
}
}
if (isAdd) {
// 插入语句,插入数据库,重要
this.userService.insert(user);
if (user.getUser_id() > 0) {
if (user_id == null || "".equals(user_id.trim())) {
statusMsg = "未获得主键参数错误!!!";
statusCode = 201;
return webResponse.getWebResponse(statusCode, statusMsg, data);
}
Integer user_idNumeri = user_id.matches("^[0-9]*$") ? Integer.parseInt(user_id) : 0;
if (user_idNumeri == 0) {
statusMsg = "主键不为数字错误!!!";
statusCode = 201;
return webResponse.getWebResponse(statusCode, statusMsg, data);
}
User userVo = this.userService.getById(user_idNumeri);
User user = new User();
BeanUtils.copyProperties(userVo, user); // 浅复制,重要
boolean isAdd = false;
return this.addOrEditUser(request, response, session, data, user, user_name, user_password, isAdd);
vo = list.get(i);
// 通过java反射将类中当前属性字段对应的内容复制到另外一个类中
BeanUtils.copyProperties(vo, voFont);
listFont.add(voFont);
voFont = new MusicLink();
}
map.put("list", listFont);
// data是一个map对象
data = map;
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);
}
// 歌曲搜索功能
buf.append(")");
condition.put(buf.toString(), "and");
}
String field = null;
if (condition.size() > 0) {
condition.put(condition.entrySet().iterator().next().getKey(), "");
}
int count = this.userService.getCount(condition, field);
if (order != null && order.length() > 0 & "desc".equals(desc)) {
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++) {
vo = list.get(i);
BeanUtils.copyProperties(vo, voFont);
listFont.add(voFont);
voFont = new User();
}
map.put("list", listFont);
if (user_name.length() > 255 || user_password.length() > 65535) {
statusMsg = " 参数长度过长错误!!!";
statusCode = 201;
return webResponse.getWebResponse(statusCode, statusMsg, data);
}
User user = new User();
boolean isAdd = true;
return this.addOrEditUser(request, response, session, data, user, user_name, user_password, isAdd);
}
@RequestMapping(value = "/editUser", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@ResponseBody
public WebResponse editUser(HttpServletRequest request, HttpServletResponse response, HttpSession session,
String user_id, @RequestParam(required = false) String user_name,
@RequestParam(required = false) String user_password) {
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) {
StringBuffer buf = new StringBuffer();
buf.append("(");
buf.append("test_name like '%").append(keyword).append("%'");
buf.append(" or ");
buf.append("info like '%").append(keyword).append("%'");
buf.append(" or ");
buf.append("other like '%").append(keyword).append("%'");
buf.append(")");
condition.put(buf.toString(), "and");
}
String field = null;
if (condition.size() > 0) {
condition.put(condition.entrySet().iterator().next().getKey(), "");
}
int count = this.userService.getCount(condition, field);
if (order != null && order.length() > 0 & "desc".equals(desc)) {
order = order + " desc";
}