1、开发环境
(1)操作系统: Windows10
(2)数据库与数据库管理工具: MySQL 5.7.19、Navicat for MySQL
(3)Web服务器: Tomcat8.5.38
(4)开发工具与技术: Eclipse IDEA、SSM框架、Ajax
2、数据库部署:
(1)安装MySQL 5.7.19
(2)安装并打开Navicat for MySQL数据库可视化工具
(3)创建一个新的数据库,启动数据库,运行SQL源码文件
3、后台部署:
(1)安装ECLIPSE,配制支持动态网页开发。
(2)导入代码文件
(3)配置Tomcat,并将附件导入Tomcat本地存储文件夹。
(4)配置application.properties中的相关信息。
演示视频:
【java毕业设计】基于ssm校园学生协会管理系统jsp校园社团管理系统源码和论文
package com.association.controller;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.association.po.Admin;
import com.association.po.Apply;
import com.association.po.AssShow;
import com.association.po.Assall;
import com.association.po.Association;
import com.association.po.Inform;
import com.association.po.Member;
import com.association.po.VMember;
import com.association.service.AssociationService;
import com.zhenzi.sms.ZhenziSmsClient;
@Controller
@RequestMapping("/association")
public class AssociationController {
@Autowired
private AssociationService associationService;
// 管理员查询所有协会
@RequestMapping("/findAllAssociation")
public String findAllAssociation(Model model) {
List<Association> as = associationService.findAllAssociation();
List<Association> association = new ArrayList<>();
Association ass;
for(int i=0;i<as.size();i++) {
ass = new Association();
ass.setAss_id(as.get(i).getAss_id());
ass.setAss_name(as.get(i).getAss_name());
String member_id=as.get(i).getMember_id();//获得会长ID
ass.setMember_id(member_id);
if(member_id!=null && member_id.length()!=0){
ass.setMember_name(associationService.findhuizhangById(member_id).getMember_name());//根据id查询出会长名
}
else
{
ass.setMember_name("无");
}
ass.setAss_qqgroup(as.get(i).getAss_qqgroup());
ass.setAss_img(as.get(i).getAss_img());
ass.setAss_show(as.get(i).getAss_show());
ass.setAss_email(as.get(i).getAss_email());
ass.setAss_asset(as.get(i).getAss_asset());
ass.setAss_introduce(as.get(i).getAss_introduce());
ass.setAss_state(as.get(i).getAss_state());
association.add(ass);
}
model.addAttribute("association", association);
return "association/association-list";
}
// 管理员查询所有 新 协会
@RequestMapping("/findAllnewAssociation")
public String findAllnewAssociation(Model model) {
List<Association> newassociation = associationService.findAllnewAssociation();
model.addAttribute("newassociation", newassociation);
return "association/NewAssociation-list";
}
// 前端查询所有协会会
@RequestMapping("/findAllAssociationWeb")
public String findAllAssociationWeb(Model model,HttpSession session) {
List<Association> association = associationService.findAllAssociationWeb();
Member self = (Member) session.getAttribute("self");
List<Apply> apply = null;
List<Association> assid = null;
//如果有成员信息,通过成员id查找申请表
if(self != null) {
apply = associationService.findMemberAssociationApply(self.getMember_id());//查找出该会员申请信息
assid = associationService.findAssidbyMid(self.getMember_id());//查找出该会员已在协会信息,防止重复申请相同协会
}
model.addAttribute("apply", apply);
model.addAttribute("assid", assid);
model.addAttribute("association", association);
return "web/association-apply";
}
// 前端根据协会名查询所有协会会
@RequestMapping("/findUpAssByTitleWeb")
public String findUpAssByTitleWeb(Model model,HttpSession session,HttpServletRequest request) {
String ass_name=request.getParameter("input");
List<Association> association = associationService.findUpAssByTitleWeb(ass_name);
Member self = (Member) session.getAttribute("self");
List<Apply> apply = null;
List<Association> assid = null;
//如果有成员信息,通过成员id查找申请表
if(self != null) {
apply = associationService.findMemberAssociationApply(self.getMember_id());//查找出该会员申请信息
assid = associationService.findAssidbyMid(self.getMember_id());//查找出该会员已在协会信息,防止重复申请相同协会
}
model.addAttribute("apply", apply);
model.addAttribute("assid", assid);
model.addAttribute("association", association);
return "web/association-apply";
}
//协会的升级与降级
@RequestMapping("/updatestate")
@ResponseBody
public int updatestate(HttpServletRequest request) {
int i;
String ass_state = request.getParameter("ass_state");
String ass_id = request.getParameter("ass_id");
try {
i = associationService.updatestate(ass_id, ass_state);
} catch (Exception e) {
e.printStackTrace();
i = 0;
}
return i;
}
//协会的升级与降级
@RequestMapping("/updatestate2")
@ResponseBody
public int updatestate2(HttpServletRequest request) {
int i;
String ass_show = request.getParameter("ass_show");
String ass_id = request.getParameter("ass_id");
try {
i = associationService.updatestate2(ass_id, ass_show);
} catch (Exception e) {
e.printStackTrace();
i = 0;
}
return i;
}
//查找出该协会的成员(发送通知处)
@RequestMapping("/findMemberByassId")
@ResponseBody
public List<Member> findMemberByassId(Model model,HttpServletRequest request) {
String id = request.getParameter("ass_id");
List<Member> member = associationService.findMemberByAssociation(id);
return member;
}
// 跳转指定协会修改信息界面,查出所有对应协会成员提供修改会长功能
@RequestMapping("/toUpdateAssociation")
public String toUpdateAssociation(Model model, HttpServletRequest request) {
String id = request.getParameter("ass_id");
Association association = associationService.findAssociationById(id);
List<Member> member = associationService.findMemberByAssociation(id);
model.addAttribute("association", association);
model.addAttribute("member", member);
return "association/association-edit";
}
//跳转指定 新 协会修改信息界面,查找出有资格成为会长的——协会数量小于2,且不是任一协会的会长
@RequestMapping("/toUpdatenewAssociation")
public String toUpdatenewAssociation(Model model, HttpServletRequest request) {
String id = request.getParameter("ass_id");
Association association = associationService.findAssociationById(id);
List<Member> member = associationService.findMembercanLeader(id);
model.addAttribute("association", association);
model.addAttribute("member", member);
return "association/Newassociation-edit";
}
// 修改协会信息 包括换会长功能
@RequestMapping("/updateAssociation")
@ResponseBody
public int updateAssociation(Model model, Association association, HttpServletRequest request, HttpSession session) {
int i;
Admin admin= (Admin) session.getAttribute("adminSelf"); //为了获得admin_id
int adminid=admin.getAdmin_id(); //为了获得admin_id
String member_id=request.getParameter("member_id");//所选的会员ID
String tel = associationService.findMember(member_id).getMember_phone();//新会长手机
String assname=association.getAss_name();
Association as =associationService.findAssociationByById(association.getAss_id());
String oldMember_id=as.getMember_id();//原先会长ID
VMember member = associationService.findMember(oldMember_id);
String oldphone=member.getMember_phone();//老会长手机
List<Member> leader = associationService.findleaderbyid(member_id);//用id从会长视图中查找是否存在
System.out.println(member_id+":::"+oldMember_id+":::"+leader.size());
try {
if(member_id.equals(oldMember_id)) {//会长没变
i = associationService.updateAssociation(association);
}
else {//会长变了
if(leader.size()==0) { //确保他不是其他协会会长
i = associationService.updateAssociation(association);
if(tel!=null) { //向新会长发送成为会长信息
Inform inform = new Inform();
int mid=Integer.parseInt(member_id); //转换member_id
inform.setAdmin_id(adminid);
inform.setMember_id(mid);
inform.setInform_title("会长任命");
inform.setInform_content("你好,你已成为" + assname + "的会长。详情请登录学生协会管理系统查看");
associationService.addInform(inform);
sendMessageUp(tel,assname);
}
if(oldphone!=null) { //向老会长发送会长变更信息
Inform inform2 = new Inform();
int mid2=Integer.parseInt(oldMember_id); //转换member_id
inform2.setAdmin_id(adminid);
inform2.setMember_id(mid2);
inform2.setInform_title("会长退任");
inform2.setInform_content("你好,你已退任" + assname + "会长的职位。详情请登录学生协会管理系统查看");
associationService.addInform(inform2);
sendMessage(oldphone,assname);
}
}
else
i=2;//存在不可修改
}
} catch (Exception e) {
i = 0;
}
return i;
}
// 修改 新 协会信息 包括换会长功能
@RequestMapping("/updatenewAssociation")
@ResponseBody
public int updatenewAssociation(Model model, Association association, HttpServletRequest request, HttpSession session) {
int i;
String member_id = request.getParameter("member_id");
String tel = associationService.findMember(member_id).getMember_phone();
String assname=association.getAss_name();
String ass_id = request.getParameter("ass_id");
int member_state=associationService.findMember(member_id).getMember_state();
try {
i =associationService.addMemberState(member_id,member_state);//该成员协会数量信息
i += associationService.updatenewAssociation(association);//修改协会信息
i += associationService.addMember_ass(member_id, ass_id);//增加信息到协会——成员表
if(tel!=null) {
Inform inform = new Inform();
Admin admin= (Admin) session.getAttribute("adminSelf"); //为了获得admin_id
int adminid=admin.getAdmin_id(); //为了获得admin_id
int mid=Integer.parseInt(member_id); //转换member_id
inform.setAdmin_id(adminid);
inform.setMember_id(mid);
inform.setInform_title("会长任命");
inform.setInform_content("你好,你已成为" + assname + "的会长。详情请登录学生协会管理系统查看");
associationService.addInform(inform);
sendMessageUp(tel,assname);
}
} catch (Exception e) {
i = 0;
}
return i;
}
// 发送手机短信通知成为会长
public void sendMessageUp(String tel,String assname) {
try {
final String apiUrl = "https://sms_developer.zhenzikj.com";// 短信API请求地址
final String appId = "103901";// 短信API产品id
final String appSecret = "6fa889bf-a4e6-4c2a-9c78-833952fdbf7a";// 短信API
ZhenziSmsClient client = new ZhenziSmsClient(apiUrl, appId, appSecret);
String result = client.send(tel, "你好,你已成为" + assname + "的会长。详情请登录学生协会管理系统查看");
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
}
// 发送手机短信通知会长变更
public void sendMessage(String tel,String assname) {
try {
final String apiUrl = "https://sms_developer.zhenzikj.com";// 短信API请求地址
final String appId = "103901";// 短信API产品id
final String appSecret = "6fa889bf-a4e6-4c2a-9c78-833952fdbf7a";// 短信API
ZhenziSmsClient client = new ZhenziSmsClient(apiUrl, appId, appSecret);
String result = client.send(tel, "你好,你已退任"+assname +"会长的职位。详情请登录学生协会管理系统查看");
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
}
// 发送手机短信通知退会
public void sendMessagetuihui(String tel,String assname) {
try {
final String apiUrl = "https://sms_developer.zhenzikj.com";// 短信API请求地址
final String appId = "103901";// 短信API产品id
final String appSecret = "6fa889bf-a4e6-4c2a-9c78-833952fdbf7a";// 短信API
ZhenziSmsClient client = new ZhenziSmsClient(apiUrl, appId, appSecret);
String result = client.send(tel, "你好,你已被" + assname + "退会。如有疑问,请联系会长。");
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
}
// 修改协会信息(前端)
@RequestMapping("/updateAssociationWeb")
public String updateAssociationWeb(Model model, Association association,
@RequestParam("file") MultipartFile file,HttpServletRequest request) {
try {
if (!file.isEmpty()) {
// 上传文件路径
String path = request.getServletContext().getRealPath("/AssShow");
// 上传文件名
String filename = file.getOriginalFilename();
File filepath = new File(path, filename);
// 判断路径是否存在,如果不存在就创建一个
if (!filepath.getParentFile().exists()) {
filepath.getParentFile().mkdirs();
}
// 将上传文件保存到一个目标文件夹里
file.transferTo(new File(path + File.separator + filename));
association.setAss_img(filename);
}
int i = associationService.updateAssociationWeb(association);
if (i == 1) {
model.addAttribute("msg", "修改成功!");
} else
model.addAttribute("msg", "修改失败!");
} catch (Exception e) {
e.printStackTrace();
}
return "activity/msg";
}
//跳转添加协会界面
@RequestMapping("/toaddAssociation")
public String toaddAssociation() {
return "association/association-add";
}
// 添加协会
@RequestMapping("/addAssociation")
@ResponseBody
public int addAssociation(Model model, Association association) {
int i;
try {
i = associationService.addAssociation(association);
System.out.println(i);
} catch (Exception e) {
e.printStackTrace();
i = 0;
}
return i;
}
// 展示会长信息
@RequestMapping("/showhuizhang")
public String showhuizhang(Model model, HttpServletRequest request) {
String id = request.getParameter("member_id");
VMember member = associationService.findhuizhangById(id);
model.addAttribute("member", member);
return "association/showhuizhang";
}
// 会员申请协会
@RequestMapping("/applyAssociation")
@ResponseBody
public int applyAssociation(HttpServletRequest request, HttpSession session) {
String id = request.getParameter("ass_id");
int i = 0;
Member self = (Member) session.getAttribute("self");
if(self==null||self.equals("")) { //登陆否
i=8;
}
else {
List<Association> ass = null;
try {
if (associationService.findApplyByMemberId(self.getMember_id())==null) {// 没有入会申请在审批中
int count=associationService.findAsscount(self.getMember_id());//得出加入协会数量
ass = associationService.findAssidbyMid(self.getMember_id());//查找出该会员已在协会id,防止重复申请相同协会
for(int j=0;j<ass.size();j++) {
String assid=ass.get(j).getAss_id();
if(assid.equals(id)) {
i=9;break;
}
}
if(i!=9) {
if(count<2) {//如果没有加入两个协会及以上
i = associationService.addApply(id, self.getMember_id());//添加申请信息
}
else i=0;
}
}
else {
i=0;
}
}
catch(Exception e){
e.printStackTrace();
}
}
return i;
}
// 我的协会(前端)
@RequestMapping("/myAssociation")
public String findAllAssociationMemberWeb(Model model, HttpSession session) {
Member self = (Member) session.getAttribute("self");//获得会员信息
List <Association> associationList = associationService.findAssidbyMid(self.getMember_id());//通过member id从v_ass查找ass
List<Assall> AssallList = new ArrayList<>();
Assall all;
for (int i=0;i<associationList.size();i++) {
all = new Assall();
all.setXiehui_people(associationService.findAllAssociationMember(associationList.get(i).getAss_id()));//通过ass id从v member查找出该协会成员
/* 遍历设置协会信息 */
all.setAss_id(associationList.get(i).getAss_id());
all.setAss_name(associationList.get(i).getAss_name());
String leader=associationList.get(i).getLeader();//获得会长ID
all.setMember_id(leader);
all.setLeadername(associationService.findhuizhangById(leader).getMember_name());//根据id查询出会长名
all.setAss_state(associationList.get(i).getAss_state());
all.setAss_qqgroup(associationList.get(i).getAss_qqgroup());
all.setAss_email(associationList.get(i).getAss_email());
all.setAss_asset(associationList.get(i).getAss_asset());
all.setAss_introduce(associationList.get(i).getAss_introduce());
all.setAss_img(associationList.get(i).getAss_img());
AssallList.add(all);
}
model.addAttribute("ass",AssallList);
return "web/myAssociation";
}
// 显示前端优秀协会代表
@RequestMapping("/AssShow")
@ResponseBody
public List<Association> AssShow(Model model) {
List<Association> assShow = null;
try {
assShow = associationService.findAllAssociationToShow();
} catch (Exception e) {
e.printStackTrace();
}
return assShow;
}
// 会长修改协会信息前端
@RequestMapping("/toUpdateAssociationWeb")
public String toUpdateAssociationWeb(Model model, HttpServletRequest request) {
String id = request.getParameter("ass_id");
Association association = associationService.findAssociationByById(id);
model.addAttribute("ass", association);
return "web/association-edit-web";
}
// 退会
@RequestMapping("/delMemberass")
@ResponseBody
public int delMemberass(HttpServletRequest request) {
int i = 0;
String ass_id=request.getParameter("ass_id");
String member_id=request.getParameter("member_id");
int member_state=associationService.findMember(member_id).getMember_state();
String tel=associationService.findMember(member_id).getMember_phone();//获得手机号
Association association =associationService.findAssociationById(ass_id);
String assname=association.getAss_name();//得到协会名
String leader=association.getMember_id();//得到会长id
try {
if (!member_id.equals(leader)) {//不为会长
i=associationService.deleteMemberass(member_id, ass_id);//删掉member_ass
associationService.updateMemberState(member_id,member_state);//member_state - 1
if(tel!=null) {
Inform inform = new Inform();
int mid=Integer.parseInt(member_id); //转换member_id
inform.setAdmin_id(1);
inform.setMember_id(mid);
inform.setInform_title("退会通知");
inform.setInform_content("你好,你已被" + assname + "退会。如有疑问,请联系会长。");
associationService.addInform(inform);
sendMessagetuihui(tel,assname);
}
}
else i=0;
}
catch (Exception e) {
e.printStackTrace();
i=0;
}
return i;
}
}