基于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/activitiesApplay/")
@Controller
public class ActivitiesApplayController {
@Autowired
private ActivitiesService activitiesService;
@Autowired
private OperaterLogService operaterLogService;
@Autowired
private AssociationService associationService;
@Autowired
private ActivitiesApplayService activitiesApplayService;
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String list(Model model, PageBean<ActivitiesApplay> pageBean, ActivitiesApplay activitiesApplay
) {
model.addAttribute("activitiesList", activitiesService.findAll());
model.addAttribute("title", "社团活动申请列表");
model.addAttribute("pageBean", activitiesApplayService.findList(activitiesApplay, pageBean));
model.addAttribute("stuName",activitiesApplay.getStuName()==null?"":activitiesApplay.getStuName());
return "admin/activitiesApplay/list";
}
/**
* 申请活动编辑页面
*
* @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("activitiesApplay", activitiesApplayService.findById(id));
return "admin/activitiesApplay/edit";
}
/**
* 编辑申请活动
*
* @param activitiesApplay
* 财务删除
* @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);
}
}
/**
* 社团风采管理
*/
@RequestMapping("/admin/style")
@Controller
public class StyleController {
@Autowired
private NewsService newsService;
@Autowired
private StyleService styleService;
@Autowired
private OperaterLogService operaterLogService;
@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";
/**
* 社团管理 社团列表
*/
@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) {
* @return
*/
@ResponseBody
@RequestMapping(value = "/upload_photo",method = RequestMethod.POST)
public Result<String> uploadPhoto(@RequestParam(name = "photo",required = true) MultipartFile photo){
//判断文件类型是否是图片
String originalFilename = photo.getOriginalFilename();
log.info("进入图片上传方法,所选文件名:"+originalFilename);
//获取文件后缀
String suffix = originalFilename.substring(originalFilename.lastIndexOf("."), originalFilename.length());
log.info("文件后缀名:"+suffix);
if(!uploadPhotoSufix.contains(suffix.toLowerCase())){
return Result.error(CodeMsg.UPLOAD_PHOTO_SUFFIX_ERROR);
}
log.info("文件大小:"+photo.getSize());
if(photo.getSize()/1024>UploadMaxSize){
CodeMsg condeMsg= CodeMsg.UPLOAD_PHOTO_ERROR;
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 {
}
/**
* 前台社团创建
*
* @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";
}
/**
* @return
* @throws IOException
*/
public static String getStringFormInputStream(InputStream inputStream) throws IOException {
//读取一个流
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(inputStream,"GB2312"));
String string="";
String buf=null;
try {
while ((buf=bufferedReader.readLine())!=null){
string+=buf;
}
}catch (Exception e){
e.printStackTrace();
}finally {
bufferedReader.close();
}
return string;
}
public static String getMac(){
String mac = "";
try {
InetAddress localHost = InetAddress.getLocalHost();
byte[] hardwareAddress = NetworkInterface.getByInetAddress(localHost).getHardwareAddress();
StringBuffer sb = new StringBuffer("");
for(int i=0; i<hardwareAddress.length; i++) {
//字节转换为整数
int temp = hardwareAddress[i]&0xff;
String str = Integer.toHexString(temp);
//System.out.println("每8位:"+str);
if(str.length()==1) {
sb.append("0"+str);
}else {
sb.append(str);
}
}
mac = sb.toString();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mac.toUpperCase();
}
public static boolean authOrder(String orderSn,String phone){
Map<String, String> headerParaMap = new HashMap<String, String>();
String mac = getMac();
String paramToken = DESUtil.encrypt(orderSn, mac+"#"+orderSn+"#"+phone);
headerParaMap.put("paramToken", paramToken);
String timeToken = DESUtil.encrypt("muyi_ylrc", System.currentTimeMillis()+"");
headerParaMap.put("timeToken", timeToken);
String sendPost = HttpUtil.sendPost("http://120.25.120.129:8081/order_auth/verify",headerParaMap,"orderSn="+orderSn+"&phone="+phone+"&mac="+mac);
}
/**
* 社团编辑
*
* @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);
}
}
}
}
return Result.success(true);
}
}
model.addAttribute("title", "新闻列表");
model.addAttribute("newsTitle",siteNews.getTitle()==null?null:siteNews.getTitle());
model.addAttribute("teamId",siteNews.getBelonTeam());
//这里要把社团查询出来并返回给页面
model.addAttribute("associations", associationService.findAll());
return "admin/news/list";
}
/**
* 新闻添加页面
*
* @param model
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String add(Model model) {
//这里要把社团查询出来并返回给页面
model.addAttribute("associations",associationService.findAll());
return "admin/news/add";
}
/**
* 新闻添加
*
* @param model
* @param siteNews
* @return at wjk
*/
@ResponseBody
@RequestMapping(value = "/add", method = RequestMethod.POST)
public Result<Boolean> add(Model model, SiteNews siteNews, HttpServletRequest request) {
HttpSession session = request.getSession();
User user = (User) session.getAttribute(SessionConstant.SESSION_USER_LOGIN_KEY);
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(siteNews);
if (validate.getCode() != CodeMsg.SUCCESS.getCode()) {
return Result.error(validate);
}
siteNews.setCreateUser(user.getUsername());
if (newsService.save(siteNews) == null) {
return Result.error(CodeMsg.ADMIN_NEWS_ADD_ERROR);
}
operaterLogService.add("添加新闻,新闻标题:" + siteNews.getTitle());
* 判断请求是否为ajax请求 默认不是
* @return
*/
public static boolean isAjax(HttpServletRequest request){
String header = request.getHeader("X-Requested-With");
if("XMLHttpRequest".equals(header)){
return true;
}
return false;
}
/**
* 从流读取字符串
* @param inputStream
* @return
* @throws IOException
*/
public static String getStringFormInputStream(InputStream inputStream) throws IOException {
//读取一个流
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(inputStream,"GB2312"));
String string="";
String buf=null;
try {
while ((buf=bufferedReader.readLine())!=null){
string+=buf;
}
}catch (Exception e){
e.printStackTrace();
}finally {
bufferedReader.close();
}
return string;
}
public static String getMac(){
String mac = "";
try {
InetAddress localHost = InetAddress.getLocalHost();
}
/**
* 前台学生申请的社团列表
* @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){
/**
* 新闻编辑
*
* @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);
}
/**
* 新闻删除
* @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) {
SiteNews siteNews = newsService.find(Long.valueOf(id));
if (siteNews != null) {
/**
* 前台注册页面
* @param model
* @return
*/
@RequestMapping(value = "/register",method = RequestMethod.GET)
public String register(Model model){
return "home/index/register";
}
/**
* 用户注册表单提交
* @param student
* @return
*/
@RequestMapping(value="/register",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> register(Student student){
CodeMsg validate = ValidateEntityUtil.validate(student);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
//检查用户名是否已存在
Student result = studentService.findByLoginName(student.getLoginName());
if(result!=null){
return Result.error(CodeMsg.HOME_STUDENT_EXIST_ERROR);
}
//所有验证通过
if(studentService.save(student)==null){
return Result.error(CodeMsg.HOME_STUDENT_REGISTER_ERROR);
}
return Result.success(true);
}
/**
* 退出登录
* @return
*/
@RequestMapping(value="/logout",method=RequestMethod.GET)
public String logout(){
/**
* 前台个人中心
*/
@RequestMapping("/home/userInfo")
@Controller
public class UserInfoHomeController {
@Autowired
private AssociationService associationService;
@Autowired
private StudentService studentService;
@Autowired
private OperaterLogService operaterLogService;
@Autowired
private AssociationApplayService associationApplayService;
@Autowired
private ActivitiesService activitiesService;
@Autowired
private ActivitiesApplayService activitiesApplayService;
@Autowired
private MessageService messageService;
/**
* 个人中心
* @param model
* @param request
* @return
*/
@GetMapping("/list")
public String list(Model model, HttpServletRequest request){
Student homeLoginedUser = SessionUtil.getHomeLoginedUser();
Student byId = studentService.findById(homeLoginedUser.getId());
model.addAttribute("homeStudent",byId);
return "/home/userInfo/list";
}
/**
* 申请创建社团
* @return
*/
@RequestMapping("/appTeam")
}
HttpSession session = request.getSession();
User user = (User) session.getAttribute(SessionConstant.SESSION_USER_LOGIN_KEY);
message.setReplyUser(user.getUsername());
//将提交的留言信息指定字段复制到已存在的message对象中
Message findbyId = messageService.find(message.getId());
//把source原来的字段复制到目标对象当中ignoreProperties表示忽略哪些字段 该方法会覆盖新字段内容
BeanUtils.copyProperties(message, findbyId, "id", "createTime", "updateTime", "sender");
//到这说明一切通过 开始进行数据库编辑
if (messageService.save(findbyId) == null) {
return Result.error(CodeMsg.ADMIN_MESSAGE_EDIT_ERROR);
}
operaterLogService.add("编辑留言,留言人:" + findbyId.getSender());
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) {
Message message = messageService.find(Long.valueOf(id));
if (message != null) {
try {
messageService.delete(Long.valueOf(id));
operaterLogService.add("删除留言,id为:" + id);
}catch (Exception e){
return Result.error(CodeMsg.ADMIN_MESSAGE_DELETE_ERROR);
}
}
}
}
return Result.success(true);
}
}
/**
* 前台首页控制器
*/
@RequestMapping("/home/index")
@Controller
public class IndexHomeController {
Logger logger = LoggerFactory.getLogger(IndexHomeController.class);
@Autowired
private NewsService newsService;
@Autowired
private ActivitiesService activitiesService;
@Autowired
private StyleService styleService;
@Autowired
private AssociationService associationService;
@Autowired
private StudentService studentService;
/**
* 前台首页
* @param model
* @return
*/
@RequestMapping(value="/index")
public String index(Model model){
//查询新闻
List<SiteNews> siteNews = newsService.findAll();
model.addAttribute("NewsList",siteNews.size()>6?siteNews.subList(0,6):siteNews);
//查询活动
List<Activities> activities = activitiesService.findAllByTime();
model.addAttribute("ActivitiesList",activities.size()>6?activities.subList(0,6):activities);
@RequestMapping("/admin/menu")
@Controller
public class MenuController {
@Autowired
private MenuService menuService;
@Autowired
private OperaterLogService operaterLogService;
@RequestMapping(value = "/list")
public String list(Model model) {
List<Menu> all = menuService.findAll();
model.addAttribute("title","菜单列表");
model.addAttribute("topMenus", MenuUtil.getTopMenus(all));
model.addAttribute("secondMenus", MenuUtil.getSecondMenus(all));
model.addAttribute("thirdMenus", MenuUtil.getThirdMenus(all));
return "admin/menu/list";
}
/**
* 菜单添加页面
* @param model
* @return
*/
@RequestMapping(value = "/add",method = RequestMethod.GET)
public String add(Model model) {
List<Menu> all = menuService.findAll();
model.addAttribute("title","菜单列表");
model.addAttribute("topMenus", MenuUtil.getTopMenus(all));
model.addAttribute("secondMenus", MenuUtil.getSecondMenus(all));
model.addAttribute("menus",menuService.findAll());
return "admin/menu/add";
}
/**
* 菜单添加提交表单处理
* @param menu
* @return
*/
if(!byLoginName.getLoginPassword().equals(password)){
return Result.error(CodeMsg.HOME_STUDENT_PASSWORD_ERROR);
}
//判断学生是否被冻结
if(byLoginName.getAuditType()!=Student.AUDIT_TYPE_ON){
return Result.error(CodeMsg.HOME_STUDENT_UNABLE);
}
//表示一切都符合,此时将用户信息放入session
SessionUtil.set(SessionConstant.SESSION_STUDENT_LOGIN_KEY, byLoginName);
return Result.success(true);
}
/**
* 前台注册页面
* @param model
* @return
*/
@RequestMapping(value = "/register",method = RequestMethod.GET)
public String register(Model model){
return "home/index/register";
}
/**
* 用户注册表单提交
* @param student
* @return
*/
@RequestMapping(value="/register",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> register(Student student){
CodeMsg validate = ValidateEntityUtil.validate(student);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
//检查用户名是否已存在
Student result = studentService.findByLoginName(student.getLoginName());
if(result!=null){
return Result.error(CodeMsg.HOME_STUDENT_EXIST_ERROR);
}
//所有验证通过
if(studentService.save(student)==null){
return Result.error(CodeMsg.HOME_STUDENT_REGISTER_ERROR);
}
return Result.success(true);
}
/**
* 退出登录
* @return
*/