Java项目:学校社团管理系统(java+SSM+JSP+HTML+JavaScript+mysql)
源码获取:俺的博客首页 "资源" 里下载!项目介绍超级管理员角色包含以下功能:会员管理,物品管理,活动审批,系统用户管理,社团添加删除等功能。社团管理员角色包含以下功能:社团管理员登录,会员管理,物品管理,活动管理,查询社团信息,密码修改等功能。普通社员角色包含以下功能:社员登录,申请入社,物品查看,活动申请等功能。环境需要1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他
源码获取:俺的博客首页 "资源" 里下载!
项目介绍
超级管理员角色包含以下功能:
会员管理,物品管理,活动审批,系统用户管理,社团添加删除等功能。
社团管理员角色包含以下功能:
社团管理员登录,会员管理,物品管理,活动管理,查询社团信息,密码修改等功能。
普通社员角色包含以下功能:
社员登录,申请入社,物品查看,活动申请等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
技术栈
1. 后端:Spring+SpringMVC+Mybatis
2. 前端:HTML+CSS+JavaScript+jsp
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/ 登录
用户管理控制层:
@Controller
@RequestMapping(value = "user")
public class UserController {
private final GoodService goodService;
private final OrderService orderService;
private final ReviewService reviewService;
private final UserService userService;
private final CollectService collectService;
@Autowired
public UserController(GoodService goodService, OrderService orderService,
ReviewService reviewService, UserService userService,
CollectService collectService) {
this.goodService = goodService;
this.orderService = orderService;
this.reviewService = reviewService;
this.userService = userService;
this.collectService = collectService;
}
@RequestMapping(value = "userProfile", method = RequestMethod.GET)
public String getMyProfile(ModelMap model, HttpSession session) {
User user = (User) session.getAttribute("user");
if (user == null) {
return "redirect:/";
}
List<Collect> collects = collectService
.getCollectByUserId(user.getId());
for (Collect collect : collects) {
collect.setGood(goodService.getGoodById(collect.getGoodId()));
}
List<Good> goods = goodService.getGoodByUserId(user.getId());
List<Order> orders = orderService.getOrderByCustomerId(user.getId());
List<Review> reviews = reviewService.gerReviewByToUserId(user.getId());
List<Reply> replies = reviewService.gerReplyByToUserId(user.getId());
List<Order> sellGoods = orderService.getOrderBySellerId(user.getId());
model.addAttribute("collects", collects);
model.addAttribute("goods", goods);
model.addAttribute("orders", orders);
model.addAttribute("reviews", reviews);
model.addAttribute("replies", replies);
model.addAttribute("sellGoods", sellGoods);
return "user/userProfile";
}
@RequestMapping(value = "/review", method = RequestMethod.GET)
public String getReviewInfo(@RequestParam(required = false) Integer goodId,
@RequestParam(required = false) Integer reviewId) {
System.out.println("reviewId" + reviewId);
if (reviewId != null) {
System.out.println("reviewId" + reviewId);
if (reviewService.updateReviewStatus(1, reviewId) == 1) {
return "redirect:/goods/goodInfo?goodId=" + goodId;
}
}
return "redirect:/user/userProfile";
}
@RequestMapping(value = "/reply", method = RequestMethod.GET)
public String getReplyInfo(
@RequestParam(required = false) Integer reviewId,
@RequestParam(required = false) Integer replyId) {
if (replyId != null) {
if (reviewService.updateReplyStatus(1, replyId) == 1) {
Integer goodId = reviewService.getGoodIdByReviewId(reviewId);
return "redirect:/goods/goodInfo?goodId=" + goodId;
}
}
return "redirect:/user/userProfile";
}
@RequestMapping(value = "/userEdit", method = RequestMethod.GET)
public String getUserEdit(ModelMap model,
@RequestParam(value = "userId", required = false) Integer userId,
HttpSession session) {
User sessionUser = (User) session.getAttribute("user");
if (sessionUser == null) {
return "redirect:/";
}
User user = userService.getUserById(userId);
List<Order> sellGoods = orderService.getOrderBySellerId(user.getId());
List<Review> reviews = reviewService.gerReviewByToUserId(user.getId());
List<Reply> replies = reviewService.gerReplyByToUserId(user.getId());
model.addAttribute("user", user);
model.addAttribute("sellGoods", sellGoods);
model.addAttribute("reviews", reviews);
model.addAttribute("replies", replies);
return "user/userEdit";
}
@RequestMapping(value = "/userEdit", method = RequestMethod.POST)
public String postUserEdit(ModelMap model, @Valid User user,
HttpSession session,
@RequestParam(value = "photo", required = false) MultipartFile photo)
throws IOException {
String status;
Boolean insertSuccess;
User sessionUser = (User) session.getAttribute("user");
user.setId(sessionUser.getId());
InfoCheck infoCheck = new InfoCheck();
if (!infoCheck.isMobile(user.getMobile())) {
status = "请输入正确的手机号!";
} else if (!infoCheck.isEmail(user.getEmail())) {
status = "请输入正确的邮箱!";
} else if (userService.getUserByMobile(user.getMobile()).getId() != user
.getId()) {
System.out.println(userService.getUserByMobile(user.getMobile())
.getId() + " " + user.getId());
status = "此手机号码已使用!";
} else if (userService.getUserByEmail(user.getEmail()).getId() != user
.getId()) {
status = "此邮箱已使用!";
} else {
if (!photo.isEmpty()) {
RandomString randomString = new RandomString();
FileCheck fileCheck = new FileCheck();
String filePath = "/statics/image/photos/" + user.getId();
String pathRoot = fileCheck.checkGoodFolderExist(filePath);
String fileName = user.getId()
+ randomString.getRandomString(10);
String contentType = photo.getContentType();
String imageName = contentType.substring(contentType
.indexOf("/") + 1);
String name = fileName + "." + imageName;
photo.transferTo(new File(pathRoot + name));
String photoUrl = filePath + "/" + name;
user.setPhotoUrl(photoUrl);
} else {
String photoUrl = userService.getUserById(user.getId())
.getPhotoUrl();
user.setPhotoUrl(photoUrl);
}
insertSuccess = userService.updateUser(user);
if (insertSuccess) {
session.removeAttribute("user");
session.setAttribute("user", user);
return "redirect:/user/userProfile";
} else {
status = "修改失败!";
model.addAttribute("user", user);
model.addAttribute("status", status);
return "user/userEdit";
}
}
System.out.println(user.getMobile());
System.out.println(status);
model.addAttribute("user", user);
model.addAttribute("status", status);
return "user/userEdit";
}
@RequestMapping(value = "/password/edit", method = RequestMethod.POST)
public ResponseEntity editPassword(@RequestBody Password password) {
User user = userService.getUserById(password.getUserId());
String oldPass = DigestUtils
.md5DigestAsHex((password.getOldPassword() + user.getCode())
.getBytes());
if (oldPass.equals(user.getPassword())) {
RandomString randomString = new RandomString();
String code = (randomString.getRandomString(5));
String md5Pass = DigestUtils.md5DigestAsHex((password
.getNewPassword() + code).getBytes());
Boolean success = userService.updatePassword(md5Pass, code,
password.getUserId());
if (success) {
return ResponseEntity.ok(true);
} else {
return ResponseEntity.ok("密码修改失败!");
}
} else {
return ResponseEntity.ok("原密码输入不正确!");
}
}
}
后台管理员管理控制层:
@Controller
@RequestMapping(value = "admin")
public class AdminController {
private final UserService userService;
private final GoodService goodService;
private final TypeService typeService;
private final OrderService orderService;
@Autowired
public AdminController(UserService userService, GoodService goodService, TypeService typeService, OrderService orderService) {
this.userService = userService;
this.goodService = goodService;
this.typeService = typeService;
this.orderService = orderService;
}
@RequestMapping(value = "/adminLogin", method = RequestMethod.GET)
public String getAdminLogin(){
return "admin/adminLogin";
}
@RequestMapping(value = "/adminLogin", method = RequestMethod.POST)
public String postAdminLogin(ModelMap model,
@RequestParam(value = "email", required = false) String email,
@RequestParam(value = "password", required = false) String password,
HttpSession session) {
User admin = userService.getUserByEmail(email);
String message;
if (admin != null){
String mdsPass = DigestUtils.md5DigestAsHex((password + admin.getCode()).getBytes());
// if (!mdsPass .equals(admin.getPassword())){
// message = "用户密码错误!";
// }
if (!password .equals(admin.getPassword())){
message = "用户密码错误!";
} else if (admin.getRoleId() != 101){
message = "用户没有权限访问!";
} else {
session.setAttribute("admin",admin);
return "redirect:/admin/adminPage";
}
} else {
message = "用户不存在!";
}
model.addAttribute("message", message);
return "admin/adminLogin";
}
@RequestMapping(value = "/adminLogout", method = RequestMethod.GET)
public String adminLogout(@RequestParam(required = false, defaultValue = "false" )String adminLogout, HttpSession session){
if (adminLogout.equals("true")){
session.removeAttribute("admin");
}
// adminLogout = "false";
return "redirect:/";
}
@RequestMapping(value = "/adminPage", method = RequestMethod.GET)
public String getAdminPage(ModelMap model,
HttpSession session){
User admin = (User) session.getAttribute("admin");
if (admin == null){
return "redirect:/admin/adminLogin";
}
List<Good> goodList = goodService.getAllGoodList();
for (Good good : goodList) {
good.setGoodUser(userService.getUserById(good.getUserId()));
good.setGoodSecondType(typeService.getSecondTypeById(good.getSecondTypeId()));
}
List<User> userList = userService.getAllUser();
List<FirstType> firstTypeList = typeService.getAllFirstType();
List<Order> orderList = orderService.getOrderList();
model.addAttribute("goodList", goodList);
model.addAttribute("userList", userList);
model.addAttribute("firstTypeList", firstTypeList);
model.addAttribute("orderList", orderList);
return "admin/adminPage";
}
@RequestMapping(value = "/user/update/status/{statusId}&{userId}", method = RequestMethod.GET)
public ResponseEntity updateUserStatus(@PathVariable Integer statusId,
@PathVariable Integer userId){
Boolean success = userService.updateUserStatus(statusId, userId);
if (success){
List<User> userList = userService.getAllUser();
return ResponseEntity.ok(userList);
}
return ResponseEntity.ok(success);
}
@RequestMapping(value = "/user/delete/{userId}", method = RequestMethod.GET)
public ResponseEntity deleteUser(@PathVariable Integer userId){
Boolean success = userService.deleteUser(userId);
if (success){
List<User> userList = userService.getAllUser();
return ResponseEntity.ok(userList);
}
return ResponseEntity.ok(success);
}
}
角色管理控制层:
@Controller
@RequestMapping("role")
public class RoleController {
@Autowired
private RoleService roleService;
@Autowired
private PermissionService permissionService;
@RequestMapping("/list")
@RequiresPermissions("role:list")
public String roleList() {
return "role/list";
}
@ResponseBody
@RequestMapping("/getRoles")
@RequiresPermissions("role:list")
public PageInfo<Role> getAdmins(String keyWord,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
//开始分页,这里启动并设置页码,和每页结果数量后,后续结果会自动为分页后结果
PageHelper.startPage(pageNum, pageSize);
RoleExample roleExample = new RoleExample();
/**
* StringUtils.isNotBlank 可以判断 ""/" "/null 为 false
*/
if (StringUtils.isNotBlank(keyWord)) {
//角色条件
RoleExample.Criteria criteriaUserName = roleExample.createCriteria();
criteriaUserName.andRolenameLike("%" + keyWord + "%");
}
List<Role> roles = roleService.selectByExample(roleExample);
//获得分页对象
PageInfo<Role> pageInfo = new PageInfo<>(roles);
return pageInfo;
}
@ResponseBody
@RequestMapping("/delete")
@RequiresPermissions("role:delete")
public Map<String, String> delete(Long[] roleIds) {
HashMap<String, String> map = new HashMap<>();
if (roleIds.length == 1) {
int res = roleService.deleteByPrimaryKey(roleIds[0]);
if (res == 1) {
map.put("status", "true");
map.put("info", "删除成功!");
return map;
}
map.put("status", "false");
map.put("info", "删除失败!角色已经不存在");
return map;
}
//批量删除
int success = 0;
int total = roleIds.length;
for(Long roleId : roleIds) {
success += roleService.deleteByPrimaryKey(roleId);
}
map.put("status", "true");
map.put("info", "成功删除选中 " + total + " 个角色中的 " + success + " 个角色");
return map;
}
@RequestMapping("/add")
@RequiresPermissions("role:insert")
public String addRole() {
return "role/add";
}
@ResponseBody
@RequestMapping("/getTree")
public List<Permission> getTree(){
ArrayList<Permission> permissions = (ArrayList<Permission>) permissionService.selectByExample(new PermissionExample());
return permissions;
}
@ResponseBody
@RequestMapping("/insert")
@RequiresPermissions("role:insert")
public Boolean insert(Role role){
int res = roleService.insert(role);
if (res == 1)
return true;
return false;
}
@ResponseBody
@RequestMapping("/checkRole")
@RequiresPermissions("role:list")
public Boolean checkRole(String name, String curName) {
if (curName != null && name.equals(curName)) {
return true;
}
RoleExample roleExample = new RoleExample();
RoleExample.Criteria criteria = roleExample.createCriteria();
criteria.andRolenameEqualTo(name);
if (roleService.selectByExample(roleExample).size() != 0) {
return false;
}
return true;
}
@RequestMapping("/edit")
@RequiresPermissions("role:update")
public String edit(Model m, Long roleId) {
m.addAttribute("role", roleService.selectByPrimaryKey(roleId));
return "role/edit";
}
@ResponseBody
@RequestMapping("/update")
@RequiresPermissions("role:update")
public Boolean update(Role role) {
int res = roleService.updateByPrimaryKeySelective(role);
if (res == 1) {
return true;
}
return false;
}
}
源码获取:俺的博客首页 "资源" 里下载!
更多推荐
所有评论(0)