基于javaweb+mysql的springboot高校学生社团活动管理系统(java+springboot+freemark+jpa+mysql)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot高校学生社团活动管理系统(java+springboot+freemark+jpa+mysql)
前台:
1、社团信息浏览搜索、社团活动风采、新闻信息浏览搜索。
2、学生注册登录。
3、登录后可自己申请创建社团,也可申请加入其他社团活动。
4、管理自己社团的申请人员。
5个人信息修改及留言等。
后台:
后台管理员除了基本的系统管理功能(脚手架里的功能,这里不赘述)外,还有社团审核管理、活动新闻管理、学生管理、留言管理、活动申请审核、活动经费管理等等。
/**
* 留言管理 留言列表
*/
@RequestMapping("/admin/message")
@Controller
public class MessageController {
@Autowired
private MessageService messageService;
@Autowired
private OperaterLogService operaterLogService;
@Autowired
private NewsService newsService;
@RequestMapping(value = "/list")
public String list(Model model, PageBean<Message> pageBean, Message message) {
model.addAttribute("pageBean", messageService.findList(message, pageBean));
model.addAttribute("sender",message.getSender()==null?null:message.getSender());
model.addAttribute("title", "留言列表");
model.addAttribute("auditStatus",message.getAuditStatus()==null?0:message.getAuditStatus());
return "admin/message/list";
}
/**
* 留言添加页面
*
* @param model
* 个人中心留言列表
* @param model
* @param stuName
* @return
*/
@GetMapping("/myMessage")
public String myMessage(Model model,@RequestParam("stuName")String stuName){
model.addAttribute("myMessage",messageService.findByStuName(stuName));
return "/home/userInfo/my_message_list";
}
/**
* 个人中心我的社团申请列表
* @param model
* @param stuId
* @return
*/
@GetMapping("/myTeamApplayList")
public String myTeamApplayList(Model model,@RequestParam("stuId")Long stuId){
Student homeLoginedUser = SessionUtil.getHomeLoginedUser();
//根据学生的id和姓名查询自己的社团
List<Association> byStuNameAndId = associationService.findByStuNameAndId(homeLoginedUser.getStuName(), stuId);
String teamIds="";
String ids="";
//获取自己社团的id 查询申请表
if(byStuNameAndId.size()>0){
for (Association asc : byStuNameAndId){
teamIds+=asc.getId()+",";
}
ids = teamIds.substring(0, teamIds.length() - 1);
}
List<AssociationApplay> MyApplayTeamList = associationApplayService.findByTeamIds(ids);
model.addAttribute("MyTeamList",byStuNameAndId);
model.addAttribute("MyApplayTeamList",MyApplayTeamList);
return "/home/userInfo/my_team_applay_list";
}
/**
* 我的社团审核
* @param associationApplay
* @return
*/
@ResponseBody
@PostMapping("/myTeamExamine")
public Result<Boolean> myTeamExamine(AssociationApplay associationApplay){
//根据社团id找到该社团
Association association = associationService.find(associationApplay.getApplayTeam());
if(association==null){
return Result.error(CodeMsg.ADMIN_ASSOCIATIONAPPLAY_NOTEXIST_ERROR);
}
//判断社团的成员人数和申请人数是否一致 如果一致说明社团人数已满
if(association.getMembers()==association.getApplayNumber()){
if (validate.getCode() != CodeMsg.SUCCESS.getCode()) {
return Result.error(validate);
}
//将提交的用户信息指定字段复制到已存在的user对象中
Financial findbyId = financialService.find(financial.getId());
//把source原来的字段复制到目标对象当中ignoreProperties表示忽略哪些字段 该方法会覆盖新字段内容
BeanUtils.copyProperties(financial, findbyId, "id", "createTime", "updateTime", "createUser");
//到这说明一切通过 开始进行数据库编辑
if (financialService.save(findbyId) == null) {
return Result.error(CodeMsg.ADMIN_FINANCIAL_EDIT_ERROR);
}
operaterLogService.add("编辑财务,财务活动编号:" + financial.getActId());
return Result.success(true);
}
/**
* 财务删除
* @param ids
* @return
*/
@ResponseBody
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public Result<Boolean> delete(@RequestParam(name = "ids", required = true) String ids) {
if (!StringUtils.isEmpty(ids)) {
String[] splitIds = ids.split(",");
for (String id : splitIds) {
Financial financial = financialService.find(Long.valueOf(id));
if (financial != null) {
try {
financialService.delete(Long.valueOf(id));
operaterLogService.add("删除财务,id为:" + id);
}catch (Exception e){
return Result.error(CodeMsg.ADMIN_FINANCIAL_DELETE_ERROR);
}
}
}
}
return Result.success(true);
}
}
/**
* 用户编辑页面
* @param model
* @param id
* @return
*/
@RequestMapping(value = "/edit",method = RequestMethod.GET)
public String edit(Model model,@RequestParam(name = "id",required = true) Long id){
model.addAttribute("user",userService.find(id));
model.addAttribute("roles",roleService.findAll());
return "admin/user/edit";
}
/**
* 编辑用户信息表单提交处理
* @param user
* @return
*/
@ResponseBody
@RequestMapping(value = "/edit",method = RequestMethod.POST)
public Result<Boolean> edit(User user){
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(user);
if(validate.getCode()!=CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
//判断用户的角色是否选择
if(user.getRole()==null ||user.getRole().getId()==null){
return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY);
}
if(user.getId()==null||user.getId().longValue()<=0){
return Result.error(CodeMsg.ADMIN_USER_NO_EXIST);
}
//判断数据库user表有没有这个用户名
if(userService.isExistUsername(user.getUsername(),user.getId().longValue())){
return Result.error(CodeMsg.ADMIN_USER_NAME_EXIST);
}
//将提交的用户信息指定字段复制到已存在的user对象中
User findbyId = userService.find(user.getId());
//把source原来的字段复制到目标对象当中ignoreProperties表示忽略哪些字段 该方法会覆盖新字段内容
BeanUtils.copyProperties(user,findbyId,"id","createTime","updateTime");
//到这说明一切通过 开始进行数据库编辑
if(userService.save(findbyId)==null){
return Result.error(CodeMsg.ADMIN_USER_EDIT_ERROR);
}
operaterLogService.add("编辑用户,用户名:"+user.getUsername());
return Result.success(true);
}
@ResponseBody
@RequestMapping(value = "/delete",method = RequestMethod.POST)
public Result<Boolean> delete(@RequestParam(name = "id",required = true) Long id) {
*/
@ResponseBody
@RequestMapping("/delete")
public Result<Boolean>delete(Model model,@RequestParam("id")Long id){
if(associationService.find(id)==null){
return Result.error(CodeMsg.HOME_ASSOCIATION_FIND_ERROR);
}
//开始删除社团
associationService.delete(id);
return Result.success(true);
}
/**
* 前台学生申请的社团列表
* @param model
* @return
*/
@GetMapping("/myApplayTeam")
public String myApplayTeam(Model model,@RequestParam("stuId")Long stuId){
List<AssociationApplay> myTeamApplayList =associationApplayService.findBystuId(stuId);
model.addAttribute("myTeamApplayList",myTeamApplayList);
model.addAttribute("teamList",associationService.findAll());
return "/home/userInfo/my_applay_team";
}
/**
* 前台学生申请的活动列表
* @param model
* @param stuId
* @return
*/
@GetMapping("/myApplayActivities")
public String myApplayActivities(Model model,@RequestParam("stuId")Long stuId){
model.addAttribute("myActivitiesApplayList",activitiesApplayService.findBystuId(stuId));
model.addAttribute("activitiesList",activitiesService.findAll());
return "/home/userInfo/my_applay_activities";
}
/**
* 个人中心留言列表
* @param model
* @param stuName
* @return
*/
@GetMapping("/myMessage")
public String myMessage(Model model,@RequestParam("stuName")String stuName){
model.addAttribute("myMessage",messageService.findByStuName(stuName));
return "/home/userInfo/my_message_list";
}
/**
* 个人中心我的社团申请列表
* @param model
* @param stuId
* @return
*/
@GetMapping("/myTeamApplayList")
public String myTeamApplayList(Model model,@RequestParam("stuId")Long stuId){
Student homeLoginedUser = SessionUtil.getHomeLoginedUser();
//根据学生的id和姓名查询自己的社团
List<Association> byStuNameAndId = associationService.findByStuNameAndId(homeLoginedUser.getStuName(), stuId);
String teamIds="";
String ids="";
//获取自己社团的id 查询申请表
if(byStuNameAndId.size()>0){
for (Association asc : byStuNameAndId){
teamIds+=asc.getId()+",";
}
ids = teamIds.substring(0, teamIds.length() - 1);
}
List<AssociationApplay> MyApplayTeamList = associationApplayService.findByTeamIds(ids);
model.addAttribute("MyTeamList",byStuNameAndId);
model.addAttribute("MyApplayTeamList",MyApplayTeamList);
return "/home/userInfo/my_team_applay_list";
}
/**
* 我的社团审核
* @param associationApplay
* @return
*/
@ResponseBody
@PostMapping("/myTeamExamine")
public Result<Boolean> myTeamExamine(AssociationApplay associationApplay){
//根据社团id找到该社团
Association association = associationService.find(associationApplay.getApplayTeam());
if(association==null){
return Result.error(CodeMsg.ADMIN_ASSOCIATIONAPPLAY_NOTEXIST_ERROR);
}
return Result.success(true);
}
}
/**
* 社团管理 社团列表
*/
@RequestMapping("/admin/association")
@Controller
public class AssociationController {
@Autowired
private AssociationService associationService;
@Autowired
private OperaterLogService operaterLogService;
@Autowired
private NewsService newsService;
* 修改密码表单提交
* @param oldPwd
* @param newPwd
* @return
*/
@ResponseBody
@RequestMapping(value = "/update_pwd",method = RequestMethod.POST)
public Result<Boolean> updatePwd(@RequestParam(name = "oldPwd",required = true) String oldPwd,
@RequestParam(name = "newPwd",required = true)String newPwd){
User loginedUser = SessionUtil.getLoginedUser();
if(!loginedUser.getPassword().equals(oldPwd)){
return Result.error(CodeMsg.ADMIN_USER_PASSWORD_OLD_ERROR);
}
if(StringUtils.isEmpty(newPwd)){
return Result.error(CodeMsg.ADMIN_USER_PASSWORD_NEW_ERROR);
}
//设置新密码
loginedUser.setPassword(newPwd);
//更新数据库
userService.save(loginedUser);
//更新session
//更新session里的值
SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY,loginedUser);
return Result.success(true);
}
/**
* 日志管理页面
* @param model
* @param operaterLog
* @param pageBean
* @return
*/
@RequestMapping(value = "/operator_log_list")
public String operatorLogList(Model model,OperaterLog operaterLog, PageBean<OperaterLog> pageBean){
model.addAttribute("pageBean",operaterLogService.findList(operaterLog,pageBean));
model.addAttribute("operator",operaterLog.getOperator());
model.addAttribute("title","日志列表");
return "admin/system/operator_log_list";
}
return Result.success(true);
}
/**
* 前台我的社团列表
* @param model
* @return
*/
@GetMapping("/myTeamList")
public String myTeamList(Model model, @RequestParam("stuName") String stuName){
Student homeLoginedUser = SessionUtil.getHomeLoginedUser();
//根据学生查询所创建的社团
model.addAttribute("myTeamList", associationService.findByStuNameAndId(stuName,homeLoginedUser.getId()));
return "/home/userInfo/my_team_list";
}
/**
* 前台我的社团编辑
* @param model
* @param id
* @return
*/
@GetMapping("/myTeamEdit")
public String myTeamEdit(Model model,@RequestParam("id") Long id){
model.addAttribute("myTeam",associationService.find(id));
return "/home/userInfo/my_team_edit";
}
/**
* 前台社团编辑
* @param association
* @return
*/
@ResponseBody
@RequestMapping(value = "/myTeamEdit", method = RequestMethod.POST)
public Result<Boolean> edit(Association association) {
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(association);
if (validate.getCode() != CodeMsg.SUCCESS.getCode()) {
return Result.error(validate);
}
//将提交的社团信息指定字段复制到已存在的user对象中
Association findbyId = associationService.find(association.getId());
//把source原来的字段复制到目标对象当中ignoreProperties表示忽略哪些字段 该方法会覆盖新字段内容
BeanUtils.copyProperties(association, findbyId, "id", "createTime", "updateTime", "auditType","buildStu","createUserId");
//到这说明一切通过 开始进行数据库编辑
if (associationService.save(findbyId) == null) {
return Result.error(CodeMsg.HOME_ASSOCIATION_EDIT_ERROR);
}
*
* @param model
* @param association
* @return at wjk
*/
@ResponseBody
@RequestMapping(value = "/add", method = RequestMethod.POST)
public Result<Boolean> add(Model model, Association association, HttpServletRequest request) {
HttpSession session = request.getSession();
User user = (User) session.getAttribute(SessionConstant.SESSION_USER_LOGIN_KEY);
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(association);
if (validate.getCode() != CodeMsg.SUCCESS.getCode()) {
return Result.error(validate);
}
association.setCreateUserId(user.getId());
association.setBuildStu(user.getUsername());
if (associationService.save(association) == null) {
return Result.error(CodeMsg.ADMIN_ASSOCIATION_ADD_ERROR);
}
operaterLogService.add("添加社团,社团名称:" + association.getTeamName());
return Result.success(true);
}
/**
* 社团编辑页面
*
* @param model
* @param id
* @return
*/
@RequestMapping(value = "/edit", method = RequestMethod.GET)
public String edit(Model model, @RequestParam(name = "id", required = true) Long id) {
model.addAttribute("AssocaitionTitle","社团列表");
model.addAttribute("association", associationService.find(id));
return "admin/association/edit";
}
/**
* 社团编辑
*
* @param association
* @return
*/
@ResponseBody
@RequestMapping(value = "/edit", method = RequestMethod.POST)
public Result<Boolean> edit(Association association) {
//用统一验证实体方法验证是否合法
if(isSend){
redisTemplate.opsForValue().set(phone,code,5, TimeUnit.SECONDS);
return Result.success(true);
}else {
return Result.error(CodeMsg.ADMIN_PHONE_SMS_ERROR);
}
}
}
/**
/**
* 申请活动列表删除
*
* @param ids
* @return
*/
@ResponseBody
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public Result<Boolean> delete(@RequestParam(name = "ids", required = true) String ids) {
if (!StringUtils.isEmpty(ids)) {
String[] splitIds = ids.split(",");
for (String id : splitIds) {
ActivitiesApplay activitiesApplay = activitiesApplayService.findById(Long.valueOf(id));
if (activitiesApplay != null) {
try {
activitiesApplayService.delete(Long.valueOf(id));
operaterLogService.add("删除活动申请,id为:" + id);
} catch (Exception e) {
return Result.error(CodeMsg.ADMIN_ACTIVITIESAPPLAY_DELETE_ERROR);
}
}
}
}
return Result.success(true);
}
}
/**
* 社团管理 社团列表
*/
@RequestMapping("/admin/association")
@Controller
public class AssociationController {
@Autowired
private AssociationService associationService;
@Autowired
private OperaterLogService operaterLogService;
@Autowired
private NewsService newsService;
/**
* 社团列表
* @param model
* @param pageBean
* @param association
* @param
* @return
*/
@RequestMapping(value = "/list")
public String list(Model model, PageBean<Association> pageBean, Association association) {
model.addAttribute("pageBean", associationService.findList(association, pageBean));
model.addAttribute("auditType",association.getAuditType()==null?0:association.getAuditType());
model.addAttribute("title", "社团列表");
model.addAttribute("teamName",association.getTeamName()==null?null:association.getTeamName());
return "admin/association/list";
}
/**
* 社团添加页面
*
* @param model
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String add(Model model) {
model.addAttribute("title","社团列表");
return "admin/association/add";
}
/**
* 后台社团添加
*
@Autowired
private AssociationService associationService;
@RequestMapping(value = "/list")
public String list(Model model, PageBean<Style> pageBean, Style style) {
model.addAttribute("pageBean", styleService.findList(style, pageBean));
model.addAttribute("teamId",style.getBelonTeam());
model.addAttribute("title", "社团风采列表");
model.addAttribute("styleTitle",style.getTitle()==null?null:style.getTitle());
//这里要把社团查询出来并返回给页面
model.addAttribute("associations", associationService.findAll());
model.addAttribute("auditStatus",style.getIsAudit());
return "admin/style/list";
}
/**
* 社团风采添加页面
*
* @param model
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String add(Model model) {
//这里要把社团查询出来并返回给页面
model.addAttribute("title","社团风采列表");
model.addAttribute("associations",associationService.findAll());
return "admin/style/add";
}
/**
* 社团风采添加
*
* @param model
* @param style
* @return at wjk
*/
@ResponseBody
@RequestMapping(value = "/add", method = RequestMethod.POST)
public Result<Boolean> add(Model model, Style style, HttpServletRequest request) {
HttpSession session = request.getSession();
User user = (User) session.getAttribute(SessionConstant.SESSION_USER_LOGIN_KEY);
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(style);
if (validate.getCode() != CodeMsg.SUCCESS.getCode()) {
@RequestMapping("/admin/role")
@Controller
public class RoleController {
@Autowired
private MenuService menuService;
private Logger log= LoggerFactory.getLogger(RoleController.class);
@Autowired
private OperaterLogService operaterLogService;
@Autowired
private RoleService roleService;
/**
* 分页搜索角色列表
* @param model
* @param role
* @param pageBean
* @return
*/
@RequestMapping(value = "/list")
public String list(Model model, Role role, PageBean<Role> pageBean){
model.addAttribute("title","角色列表");
model.addAttribute("name",role.getName());
model.addAttribute("pageBean",roleService.findByName(role,pageBean));
return "admin/role/list";
}
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile mf = entity.getValue();
String fileFullname = mf.getOriginalFilename();
fileFullname = fileFullname.replace('&', 'a');
fileFullname = fileFullname.replace(',', 'b');
fileFullname = fileFullname.replace(',', 'c');
String fileExt = fileFullname.substring(fileFullname.lastIndexOf(".") + 1).toLowerCase();
if (!Arrays.<String>asList(extMap.get(dirName).split(",")).contains(fileExt)) {
out.println(getError("上传文件扩展名是不允许的扩展名。\n只允许" + extMap.get(dirName) + "格式。"));
}
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
String newFileName=df.format(new Date())+"_"+new Random().nextInt(1000)+"."+fileExt;
File uploadFile=null;
if(extMap.get("file").contains(fileExt)){
uploadFile=new File(savePath+fileFullname);
}else{
uploadFile=new File(savePath+"/"+newFileName);
}
try{
FileCopyUtils.copy(mf.getBytes(),uploadFile);
JSONObject obj = new JSONObject();
obj.put("error", 0);
obj.put("url", "/photo/view?filename="+StringUtil.getFormatterDate(new Date(),"yyyy-MM-dd")+"/"+newFileName);
out.println(obj.toJSONString());
}catch (IOException e){
e.printStackTrace();
out.println(getError("上传文件失败。"));
}
}
// return Result.success(StringUtil.getFormatterDate(new Date(),"yyyy-MM-dd")+"/");
}
private String getError(String message) {
JSONObject obj = new JSONObject();
obj.put("error", 1);
obj.put("message", message);
return obj.toJSONString();
}
@RequestMapping("/fileManagerJson")
public void fileManagerJson(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setContentType("application/json; charset=UTF-8");
PrintWriter out = response.getWriter();
//根目录路径,可以指定绝对路径,比如 /var/www/attached/
String rootPath = UploadPhotoPath + StringUtil.getFormatterDate(new Date(), "yyyy-MM-dd");
//根目录URL,可以指定绝对路径,比如 http://www.yoursite.com/attached/
String rootUrl = request.getContextPath() + "/team/";
//图片扩展名
String[] fileTypes = new String[]{"gif", "jpg", "jpeg", "png", "bmp"};
String dirName = request.getParameter("dir");
//审核通过
if (associationApplayService.Approved(id) == 0) {
return Result.error(CodeMsg.ADMIN_APPLAY_EXAMINE_ERROR);
}
//审核未通过
if (associationApplayService.NotAudit(id) == 0) {
return Result.error(CodeMsg.ADMIN_APPLAY_NOTEXAMINE_ERROR);
}
//更新该社团的申请人数字段
int i = associationService.editApplayNumber(association.getId(), association.getApplayNumber() == null ? 1 : association.getApplayNumber() + 1);
if (i == 0) {
return Result.error(CodeMsg.ADMIN_APPLAY_NUMBER_EDIT_ERROR);
}
return Result.success(true);
}
/**
* 社团审核未通过
*
* @param
* @param id
* @return at wjk
*/
@ResponseBody
@RequestMapping(value = "/noaudit", method = RequestMethod.POST)
public Result<Boolean> NoAudit(@RequestParam("id") Long id) {
//审核未通过
if (associationApplayService.NotAudit(id) == 0) {
return Result.error(CodeMsg.ADMIN_APPLAY_NOTEXAMINE_ERROR);
}
return Result.success(true);
}
/**
* 社团申请删除
*
* @param ids
* @return
*/
@ResponseBody
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public Result<Boolean> delete(@RequestParam(name = "ids", required = true) String ids) {
if (!StringUtils.isEmpty(ids)) {
String[] splitIds = ids.split(",");
for (String id : splitIds) {
AssociationApplay associationApplay = associationApplayService.find(Long.valueOf(id));
if (associationApplay != null) {
try {
associationApplayService.delete(Long.valueOf(id));
if (associationApplayService.NotAudit(id) == 0) {
return Result.error(CodeMsg.ADMIN_APPLAY_NOTEXAMINE_ERROR);
}
return Result.success(true);
}
/**
* 社团申请删除
*
* @param ids
* @return
*/
@ResponseBody
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public Result<Boolean> delete(@RequestParam(name = "ids", required = true) String ids) {
if (!StringUtils.isEmpty(ids)) {
String[] splitIds = ids.split(",");
for (String id : splitIds) {
AssociationApplay associationApplay = associationApplayService.find(Long.valueOf(id));
if (associationApplay != null) {
try {
associationApplayService.delete(Long.valueOf(id));
operaterLogService.add("删除社团申请,id为:" + id);
} catch (Exception e) {
return Result.error(CodeMsg.ADMIN_ASSOCIATIONAPPLAY_DELETE_ERROR);
}
}
}
}
return Result.success(true);
}
}