基于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个人信息修改及留言等。
后台:
后台管理员除了基本的系统管理功能(脚手架里的功能,这里不赘述)外,还有社团审核管理、活动新闻管理、学生管理、留言管理、活动申请审核、活动经费管理等等。
condeMsg.setMsg("图片大小不能超过"+(UploadMaxSize/1024)+"MB");
return Result.error(CodeMsg.UPLOAD_PHOTO_ERROR);
}
//准备保存文件
File filePath=new File(UploadPhotoPath);
if(!filePath.exists()){
//若不存在文件夹 则创建一个文件夹
filePath.mkdir();
}
//创建一个 带日期的文件夹 去判断根目录存不存在
String path=UploadPhotoPath+StringUtil.getFormatterDate(new Date(),"yyyy-MM-dd");
//按照日期创建文件夹
filePath= new File(path);
//判断当天日期的文件夹是否存在,若不存在则创建
if(!filePath.exists()){
//若不存在文件夹,则创建一个文件夹
filePath.mkdir();
}
String fileName=System.currentTimeMillis()+suffix;
try {
//把地址写到目的地里面 相当于重写地址
photo.transferTo(new File(path+"/"+fileName));
} catch (IOException e) {
e.printStackTrace();
}
log.info("图片上传成功,保存位置:"+path+"/"+fileName);
return Result.success(StringUtil.getFormatterDate(new Date(),"yyyy-MM-dd")+"/"+fileName);
}
@RequestMapping("/uploadJson")
@ResponseBody
public void uploadJson(HttpServletRequest request, HttpServletResponse response, String dir) throws Exception {
response.setContentType("application/json; charset=UTF-8");
PrintWriter out = response.getWriter();
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
//文件保存的目录路径
String savePath = UploadPhotoPath + StringUtil.getFormatterDate(new Date(), "yyyy-MM-dd");
//文件保存目录url
HashMap<String, String> extMap = new HashMap<String, String>();
/**
* 公用上传类
* 图片上传控制器
*/
@RequestMapping("/admin/upload")
@Controller
public class UploadController {
//图片支持的格式
@Value("${jinku.upload.photo.suffix}")
private String uploadPhotoSufix;
//文件的大小限制
private Long UploadMaxSize=10240L;
//文件保存的位置
private String UploadPhotoPath=System.getProperty("user.dir") + "/src/main/resources/upload/";
private Logger log= LoggerFactory.getLogger(UploadController.class);
@Autowired
private OperaterLogService operaterLogService;
/**
* 图片统一上传类
Style findbyId = styleService.find(style.getId());
//把source原来的字段复制到目标对象当中ignoreProperties表示忽略哪些字段 该方法会覆盖新字段内容
BeanUtils.copyProperties(style, findbyId, "id", "createTime", "updateTime", "createUser");
//到这说明一切通过 开始进行数据库编辑
if (styleService.save(findbyId) == null) {
return Result.error(CodeMsg.ADMIN_STYLE_EDIT_ERROR);
}
operaterLogService.add("编辑风采,风采标题:" + style.getTitle());
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) {
Style style = styleService.find(Long.valueOf(id));
if (style != null) {
try {
styleService.delete(Long.valueOf(id));
operaterLogService.add("删除风采,id为:" + id);
}catch (Exception e){
return Result.error(CodeMsg.ADMIN_STYLE_DELETE_ERROR);
}
}
}
}
return Result.success(true);
}
}
/**
* 前台社团创建
*
* @param model
* @param association
* @return at wjk
*/
@ResponseBody
@RequestMapping(value = "/teamAdd", method = RequestMethod.POST)
public Result<Boolean> add(Model model, Association association, HttpServletRequest request) {
Student homeLoginedUser = SessionUtil.getHomeLoginedUser();
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(association);
if (validate.getCode() != CodeMsg.SUCCESS.getCode()) {
return Result.error(validate);
}
association.setAuditType(1);
association.setCreateUserId(homeLoginedUser.getId());
association.setBuildStu(homeLoginedUser.getStuName());
if (associationService.save(association) == null) {
return Result.error(CodeMsg.HOME_USERINFO_ASSOCIATION_ADD_ERROR);
}
operaterLogService.add("添加社团,社团名称:" + association.getTeamName());
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";
}
/**
* 前台我的社团编辑
headerParaMap.put("timeToken", timeToken);
String sendPost = HttpUtil.sendPost("http://120.25.120.129:8081/order_auth/verify",headerParaMap,"orderSn="+orderSn+"&phone="+phone+"&mac="+mac);
JSONObject parseObject = JSONObject.parseObject(sendPost);
if(parseObject.getIntValue("code") != CodeMsg.SUCCESS.getCode()){
return false;
}
return true;
}
public static String readFileToString(File file){
String string = "";
if(file != null){
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line = null;
while ((line = br.readLine()) != null) {
string += line;
}
br.close();
} catch (Exception e) {
// TODO: handle exception
}
}
return string;
}
}
/**
}
/**
* 登录拦截器
*/
@Component
public class LoginInterceptor implements HandlerInterceptor {
@Autowired
private SiteConfig siteConfig;
private Logger log= LoggerFactory.getLogger(LoginInterceptor.class);
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){
String requestURI = request.getRequestURI();
HttpSession session =request.getSession();
session.setAttribute(SessionConstant.SESSION_USER_AUTH_KEY, AppConfig.ORDER_AUTH);
Object attribute = session.getAttribute(SessionConstant.SESSION_USER_LOGIN_KEY);
if(attribute==null){
log.info("用户还未登录或者session失效,重定向登录页面,Url="+requestURI);
//首先判断是否是ajax类型的
if(StringUtil.isAjax(request)){
//表示是ajax请求
* @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()){
return Result.error(CodeMsg.ADMIN_APPLAY_NUMBER_EXCEED_ERROR);
}
//未审核状态
if(associationApplay.getApplayType()==1){
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));
operaterLogService.add("删除社团申请,id为:" + id);
} catch (Exception e) {
return Result.error(CodeMsg.ADMIN_ASSOCIATIONAPPLAY_DELETE_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) {
try {
userService.delete(id);
} catch (Exception e){
return Result.error(CodeMsg.ADMIN_USER_DELETE_ERROR);
}
operaterLogService.add("删除用户,id为:"+id);
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("associations", associationService.findAll());
model.addAttribute("news", newsService.find(id));
return "admin/news/edit";
}
/**
* 新闻编辑
*
* @param siteNews
* @return
*/
@ResponseBody
@RequestMapping(value = "/edit", method = RequestMethod.POST)
public Result<Boolean> edit(SiteNews siteNews) {
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(siteNews);
if (validate.getCode() != CodeMsg.SUCCESS.getCode()) {
return Result.error(validate);
}
//将提交的用户信息指定字段复制到已存在的user对象中
SiteNews findbyId = newsService.find(siteNews.getId());
//把source原来的字段复制到目标对象当中ignoreProperties表示忽略哪些字段 该方法会覆盖新字段内容
BeanUtils.copyProperties(siteNews, findbyId, "id", "createTime", "updateTime", "createUser");
//到这说明一切通过 开始进行数据库编辑
if (newsService.save(findbyId) == null) {
return Result.error(CodeMsg.ADMIN_NEWS_EDIT_ERROR);
}
operaterLogService.add("编辑新闻,新闻标题:" + siteNews.getTitle());
return Result.success(true);
}
/**
* 新闻删除
model.addAttribute("logTotal",operaterLogService.total());
model.addAttribute("dataTotal",0);
model.addAttribute("onlineUserTotal", HttpSessionS.onlineUserCount);
model.addAttribute("associationTotal",associationService.count(Association.TEAM_AUDIT_SUCCESS));
model.addAttribute("activitesTotal",activitiesService.count(Activities.ACTIVITIES_AUDIT_SUCCESS));
model.addAttribute("styleTotal",styleService.count(Style.STYLE_AUDIT_SUCCESS));
model.addAttribute("studentTotal",studentService.count());
model.addAttribute("showTipsText", showTipsText);
model.addAttribute("showTipsUrlText", showTipsUrlText);
model.addAttribute("showTipsUtl", showTipsUtl);
model.addAttribute("showTipsBtnText", showTipsBtnText);
return "admin/system/index";
}
@ResponseBody
@RequestMapping(value = "/login",method = RequestMethod.POST)
public Result<Boolean> login(HttpServletRequest request,User user, String cpacha){
Map<String,String>ret=new HashMap<String,String>();
if(user==null) {
return Result.error(CodeMsg.DATA_ERROR);
}
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(user);
if(validate.getCode()!=CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
//表示实体信息合法,开始验证验证码是否为空、
if(StringUtils.isEmpty(cpacha)){
return Result.error(CodeMsg.CPACHA_EMPTY);
}
//说明验证码不为空,从session里获取验证码
Object attribute = request.getSession().getAttribute("admin_login");
if(attribute==null){
return Result.error(CodeMsg.SESSION_EXPIRED);
}
//表示session未失效,进一步判断用户填写的验证码是否正确
if(!cpacha.equalsIgnoreCase(attribute.toString())){
return Result.error(CodeMsg.CPACHA_ERROR);
}
//表示验证码正确,开始查询数据库,检验密码是否正确
model.addAttribute("activitiesAll",activitiesService.findAll());
return "admin/financial/list";
}
/**
* 财务添加页面
*
* @param model
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String add(Model model) {
//这里要把活动查询出来并返回给页面
model.addAttribute("activitiesAll",activitiesService.findAll());
return "admin/financial/add";
}
/**
* 财务添加
*
* @param model
* @param financial
* @return at wjk
*/
@ResponseBody
@RequestMapping(value = "/add", method = RequestMethod.POST)
public Result<Boolean> add(Model model, Financial financial, HttpServletRequest request) {
User loginedUser = SessionUtil.getLoginedUser();
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(financial);
if (validate.getCode() != CodeMsg.SUCCESS.getCode()) {
return Result.error(validate);
}
financial.setCreateUser(loginedUser.getUsername());
if (financialService.save(financial) == null) {
return Result.error(CodeMsg.ADMIN_FINANCIAL_ADD_ERROR);
}
operaterLogService.add("添加财务,财务活动编号:" + financial.getActId());
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("financial", financialService.find(id));
//这里要把活动查询出来并返回给页面
model.addAttribute("activitiesAll",activitiesService.findAll());
return "admin/financial/edit";
*
* @param model
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String add(Model model) {
model.addAttribute("MessageTitle","留言列表");
return "admin/message/add";
}
/**
* 后台留言添加
*
* @param model
* @param message
* @return at wjk
*/
@ResponseBody
@RequestMapping(value = "/add", method = RequestMethod.POST)
public Result<Boolean> add(Model model, Message message, HttpServletRequest request) {
HttpSession session = request.getSession();
User user = (User) session.getAttribute(SessionConstant.SESSION_USER_LOGIN_KEY);
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(message);
if (validate.getCode() != CodeMsg.SUCCESS.getCode()) {
return Result.error(validate);
}
message.setSender(user.getUsername());
if (messageService.save(message) == null) {
return Result.error(CodeMsg.ADMIN_MESSAGE_ADD_ERROR);
}
operaterLogService.add("添加留言,留言人:" + message.getSender());
return Result.success(true);
}
/**
* 留言编辑页面
*
* @param model
* @param id
* @return
}
/**
* 新闻编辑页面
*
* @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("associations", associationService.findAll());
model.addAttribute("news", newsService.find(id));
return "admin/news/edit";
}
/**
* 新闻编辑
*
* @param siteNews
* @return
*/
@ResponseBody
@RequestMapping(value = "/edit", method = RequestMethod.POST)
public Result<Boolean> edit(SiteNews siteNews) {
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(siteNews);
if (validate.getCode() != CodeMsg.SUCCESS.getCode()) {
return Result.error(validate);
}
//将提交的用户信息指定字段复制到已存在的user对象中
SiteNews findbyId = newsService.find(siteNews.getId());
//把source原来的字段复制到目标对象当中ignoreProperties表示忽略哪些字段 该方法会覆盖新字段内容
BeanUtils.copyProperties(siteNews, findbyId, "id", "createTime", "updateTime", "createUser");
//到这说明一切通过 开始进行数据库编辑
if (newsService.save(findbyId) == null) {
return Result.error(CodeMsg.ADMIN_NEWS_EDIT_ERROR);
}
/**
* 后台学生管理
*/
@RequestMapping("/admin/student/")
@Controller
public class StudentController {
@Autowired
private StudentService studentService ;
@Autowired
private OperaterLogService operaterLogService;
/**
* 学生管理列表
* @param model
* @return
*/
@RequestMapping("/list")
public String list(Model model, Student student, PageBean<Student> pageBean){
model.addAttribute("pageBean",studentService.findList(student, pageBean));
model.addAttribute("studentLoginName",student.getLoginName());
model.addAttribute("title","学生列表");
return "/admin/student/list";
}
/**
* 后台学生添加页面
*/
@RequestMapping(value = "/add",method = RequestMethod.GET)
public String add(){
return "/admin/student/add";
}
/**
* 后台学生添加信息操作
*/
@ResponseBody
@RequestMapping(value = "/add",method = RequestMethod.POST)
public Result<Boolean> add(Model model,Student student){
CodeMsg validate = ValidateEntityUtil.validate(student);
if (validate.getCode() != CodeMsg.SUCCESS.getCode()) {
return Result.error(validate);
}
if(studentService.findByLoginName(student.getLoginName())!=null){
activitiesService.delete(Long.valueOf(id));
operaterLogService.add("删除社团活动,id为:" + id);
}catch (Exception e){
return Result.error(CodeMsg.ADMIN_ACTIVITIES_DELETE_ERROR);
}
}
}
}
return Result.success(true);
}
}
/**
* 财务管理
*/
@RequestMapping("/admin/financial")
@Controller
public class FinancialController {
* @param association
* @return
*/
@ResponseBody
@RequestMapping(value = "/edit", 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", "buildStu","createUserId");
//到这说明一切通过 开始进行数据库编辑
if (associationService.save(findbyId) == null) {
return Result.error(CodeMsg.ADMIN_ASSOCIATION_EDIT_ERROR);
}
operaterLogService.add("编辑社团,社团名称:" + association.getTeamName());
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) {
Association association = associationService.find(Long.valueOf(id));
if (association != null) {
try {
associationService.delete(Long.valueOf(id));
operaterLogService.add("删除社团,id为:" + id);
}catch (Exception e){
return Result.error(CodeMsg.ADMIN_ASSOCIATION_DELETE_ERROR);
}
}
@RequestMapping(value = "/list")
public String list(Model model, PageBean<Financial> pageBean, Financial financial,@RequestParam(name = "actTitle",defaultValue = "",required = false)String actTitle
) {
if(StringUtils.isNotEmpty(actTitle)){
Activities findActivities = activitiesService.findByTitle(actTitle);
if(findActivities!=null){
financial.setActId(findActivities.getId());
}
}
model.addAttribute("actTitle",actTitle);
model.addAttribute("pageBean", financialService.findList(financial, pageBean));
model.addAttribute("title", "财务列表");
model.addAttribute("moneyType", financial.getType()==null?0:financial.getType());
//把所有活动查询出来
model.addAttribute("activitiesAll",activitiesService.findAll());
return "admin/financial/list";
}
/**
* 财务添加页面
*
* @param model
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String add(Model model) {
//这里要把活动查询出来并返回给页面
model.addAttribute("activitiesAll",activitiesService.findAll());
return "admin/financial/add";
}
/**
* 财务添加
*
* @param model
* @param financial
* @return at wjk
*/
@ResponseBody
@RequestMapping(value = "/add", method = RequestMethod.POST)
public Result<Boolean> add(Model model, Financial financial, HttpServletRequest request) {
User loginedUser = SessionUtil.getLoginedUser();