功能介绍
系统中的核心用户是系统管理员,管理员登录后,主要功能有管理员信息管理、网站用户管理、新闻公告信息管理、演唱会类型信息管理、演唱会信息管理、票务信息管理、订单信息管理。
用户登录后,主要功能模块有首页、网站公告、推荐演唱会、全部演唱会。
部分功能模块代码
package com.action;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.entity.Admin;
import com.service.AdminService;
import com.util.PageHelper;
import com.util.VeDate;
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/admin", produces = "text/plain;charset=utf-8")
public class AdminAction extends BaseAction {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private AdminService adminService;
// 管理员登录 1 验证用户名是否存在 2 验证密码是否正确
@RequestMapping("login.action")
public String login() {
String username = this.getRequest().getParameter("username");
String password = this.getRequest().getParameter("password");
Admin adminEntity = new Admin();
adminEntity.setUsername(username);
List<Admin> adminlist = this.adminService.getAdminByCond(adminEntity);
if (adminlist.size() == 0) {
this.getRequest().setAttribute("message", "用户名不存在");
return "admin/index";
} else {
Admin admin = adminlist.get(0);
if (password.equals(admin.getPassword())) {
this.getSession().setAttribute("adminid", admin.getAdminid());
this.getSession().setAttribute("adminname", admin.getUsername());
this.getSession().setAttribute("realname", admin.getRealname());
} else {
this.getRequest().setAttribute("message", "密码错误");
return "admin/index";
}
}
return "admin/main";
}
// 修改密码
@RequestMapping("editpwd.action")
public String editpwd() {
String adminid = (String) this.getSession().getAttribute("adminid");
String password = this.getRequest().getParameter("password");
String repassword = this.getRequest().getParameter("repassword");
Admin admin = this.adminService.getAdminById(adminid);
if (password.equals(admin.getPassword())) {
admin.setPassword(repassword);
this.adminService.updateAdmin(admin);
} else {
this.getRequest().setAttribute("message", "旧密码错误");
}
return "admin/editpwd";
}
// 管理员退出登录
@RequestMapping("exit.action")
public String exit() {
this.getSession().removeAttribute("adminid");
this.getSession().removeAttribute("adminname");
this.getSession().removeAttribute("realname");
return "admin/index";
}
// 准备添加数据
@RequestMapping("createAdmin.action")
public String createAdmin() {
return "admin/addadmin";
}
// 添加数据
@RequestMapping("addAdmin.action")
public String addAdmin(Admin admin) {
admin.setAddtime(VeDate.getStringDateShort());
this.adminService.insertAdmin(admin);
return "redirect:/admin/createAdmin.action";
}
// 通过主键删除数据
@RequestMapping("deleteAdmin.action")
public String deleteAdmin(String id) {
this.adminService.deleteAdmin(id);
return "redirect:/admin/getAllAdmin.action";
}
// 批量删除数据
@RequestMapping("deleteAdminByIds.action")
public String deleteAdminByIds() {
String[] ids = this.getRequest().getParameterValues("adminid");
for (String adminid : ids) {
this.adminService.deleteAdmin(adminid);
}
return "redirect:/admin/getAllAdmin.action";
}
// 更新数据
@RequestMapping("updateAdmin.action")
public String updateAdmin(Admin admin) {
this.adminService.updateAdmin(admin);
return "redirect:/admin/getAllAdmin.action";
}
// 显示全部数据
@RequestMapping("getAllAdmin.action")
public String getAllAdmin(String number) {
List<Admin> adminList = this.adminService.getAllAdmin();
PageHelper.getPage(adminList, "admin", null, null, 10, number, this.getRequest(), null);
return "admin/listadmin";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryAdminByCond.action")
public String queryAdminByCond(String cond, String name, String number) {
Admin admin = new Admin();
if (cond != null) {
if ("username".equals(cond)) {
admin.setUsername(name);
}
if ("password".equals(cond)) {
admin.setPassword(name);
}
if ("realname".equals(cond)) {
admin.setRealname(name);
}
if ("contact".equals(cond)) {
admin.setContact(name);
}
if ("addtime".equals(cond)) {
admin.setAddtime(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.adminService.getAdminByLike(admin), "admin", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/queryadmin";
}
// 按主键查询数据
@RequestMapping("getAdminById.action")
public String getAdminById(String id) {
Admin admin = this.adminService.getAdminById(id);
this.getRequest().setAttribute("admin", admin);
return "admin/editadmin";
}
public AdminService getAdminService() {
return adminService;
}
public void setAdminService(AdminService adminService) {
this.adminService = adminService;
}
}
package com.service.impl;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dao.AdminDAO;
import com.entity.Admin;
import com.service.AdminService;
@Service("adminService")
public class AdminServiceImpl implements AdminService {
@Autowired
@Resource
private AdminDAO adminDAO;
@Override // 继承接口的新增 返回值0(失败),1(成功)
public int insertAdmin(Admin admin) {
return this.adminDAO.insertAdmin(admin);
}
@Override // 继承接口的更新 返回值0(失败),1(成功)
public int updateAdmin(Admin admin) {
return this.adminDAO.updateAdmin(admin);
}
@Override // 继承接口的删除 返回值0(失败),1(成功)
public int deleteAdmin(String adminid) {
return this.adminDAO.deleteAdmin(adminid);
}
@Override // 继承接口的查询全部
public List<Admin> getAllAdmin() {
return this.adminDAO.getAllAdmin();
}
@Override // 继承接口的按条件精确查询
public List<Admin> getAdminByCond(Admin admin) {
return this.adminDAO.getAdminByCond(admin);
}
@Override // 继承接口的按条件模糊查询
public List<Admin> getAdminByLike(Admin admin) {
return this.adminDAO.getAdminByLike(admin);
}
@Override // 继承接口的按主键查询 返回Entity实例
public Admin getAdminById(String adminid) {
return this.adminDAO.getAdminById(adminid);
}
}
package com.dao;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.entity.Admin;
@Repository("adminDAO") // Repository标签定义数据库连接的访问 Spring中直接
public interface AdminDAO {
/**
* AdminDAO 接口 可以按名称直接调用admin.xml配置文件的SQL语句
*/
// 插入数据 调用entity包admin.xml里的insertAdmin配置 返回值0(失败),1(成功)
public int insertAdmin(Admin admin);
// 更新数据 调用entity包admin.xml里的updateAdmin配置 返回值0(失败),1(成功)
public int updateAdmin(Admin admin);
// 删除数据 调用entity包admin.xml里的deleteAdmin配置 返回值0(失败),1(成功)
public int deleteAdmin(String adminid);
// 查询全部数据 调用entity包admin.xml里的getAllAdmin配置 返回List类型的数据
public List<Admin> getAllAdmin();
// 按照Admin类里面的值精确查询 调用entity包admin.xml里的getAdminByCond配置 返回List类型的数据
public List<Admin> getAdminByCond(Admin admin);
// 按照Admin类里面的值模糊查询 调用entity包admin.xml里的getAdminByLike配置 返回List类型的数据
public List<Admin> getAdminByLike(Admin admin);
// 按主键查询表返回单一的Admin实例 调用entity包admin.xml里的getAdminById配置
public Admin getAdminById(String adminid);
}