基于javaweb+mysql的ssm+maven学生会管理系统(java+ssm+javascript+jsp+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM+Maven学生会管理系统(java+ssm+javascript+jsp+mysql)
项目介绍
本项目分为管理员、学生两种角色, 管理员角色包含以下功能: 管理员登陆,管理学生,管理机构,活动信息发布,部门管理,职位申请,我的申请,申请审核等功能。 普通学生角色包含以下功能: 登陆页面,查看各个部门的最新消息,职位申请,查看自己提交的申请等功能。
环境需要
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版本;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:HTML+CSS+JavaScript+jsp
} else {
// 如果uri中不包含/,则继续
filterChain.doFilter(request, response);
}
}
}
/**
* 获取ip地址
* ***/
public class IpUtil {
/***
* 获取ip地址
* ***/
public static String getIpStr(HttpServletRequest request)
{
String ipAddress = null;
//ipAddress = this.getRequest().getRemoteAddr();
ipAddress = request.getHeader("x-forwarded-for");
if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("Proxy-Client-IP");
}
if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("WL-Proxy-Client-IP");
}
if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getRemoteAddr();
if(ipAddress.equals("127.0.0.1")|| ipAddress.equals("0:0:0:0:0:0:0:1")){
//根据网卡取本机配置的IP
InetAddress inet=null;
try {
inet = InetAddress.getLocalHost();
} catch (Exception e) {
e.printStackTrace();
return;
}
Department department = departmentService.findDepartmentById(departmentId);
ResultUtil.success(department, response);
}
@RequestMapping(value = "delete")
public void delete(HttpServletRequest request, HttpServletResponse response){
Long departmentId = ParamUtils.getLongParameter(request, "department_id", 0L);
if(departmentId == 0L){
ResultUtil.fail(LocalizationUtil.getClientString("Account_22", request), response);
return;
}
departmentService.deleteById(departmentId);
ResultUtil.success(response);
}
@RequestMapping("add")
public void add(HttpServletRequest request, HttpServletResponse response){
Account account = (Account) request.getSession().getAttribute("currentAccount");
if (account == null) {
ResultUtil.fail(response);
return;
}
Long departmentId = ParamUtils.getLongParameter(request, "department_id", 0L);
String departmentName = ParamUtils.getParameter(request, "department_name");
String departmentFunction = ParamUtils.getParameter(request, "department_function");
String departmentDescription = ParamUtils.getParameter(request, "department_description");
Organization organization = organizationService.findOrganizationByAccountId(account.getId());
Department department = new Department();
department.setOrgId(organization.getId());
department.setName(departmentName);
department.setFunction(departmentFunction);
department.setDescription(departmentDescription);
department.setCreateTime(new Date());
departmentService.save(department);
ResultUtil.success(response);
}
}
@Controller
@RequestMapping("account")
public class AccountController{
@Autowired
private IAccountService accountService;
@RequestMapping(value = "list")
public ModelAndView list(HttpServletRequest request, HttpServletResponse response){
Account account = (Account) request.getSession().getAttribute("currentAccount");
int start = ParamUtils.getIntParameter(request, "page", 1);
int limit = ParamUtils.getIntParameter(request, "limit", 10);
String userName = ParamUtils.getParameter(request, "s_userName");
if(StringUtils.isBlank(userName) || "null".equals(userName)){
userName = null;
}
int totalCount = accountService.getTotalCount(Arrays.asList(Account.ACCOUNT_MANAGER, Account.ACCOUNT_STUDENT), userName);
List<Account> accountList = accountService.findAccountList(Arrays.asList(Account.ACCOUNT_MANAGER, Account.ACCOUNT_STUDENT), userName, start, limit);
String pagation = PageUtil.getPagation("/account/list&s_userName=" + userName, totalCount, start, limit);
ModelAndView mav = new ModelAndView("account/list");
mav.getModel().put("accountList", accountList);
mav.getModel().put("pageCode", pagation);
return mav;
}
@RequestMapping(value = "add")
public void add(HttpServletRequest request, HttpServletResponse response){
Long account_id = ParamUtils.getLongParameter(request, "account_id", 0L);
String username = ParamUtils.getParameter(request, "username");
int sex = ParamUtils.getIntParameter(request, "sex", 1);
String mobile = ParamUtils.getParameter(request, "mobile");
String email = ParamUtils.getParameter(request, "email", "");
String screenName = ParamUtils.getParameter(request, "screenName", "");
String pagation = PageUtil.getPagation("/department/list", totalCount, start, limit);
ModelAndView mav = new ModelAndView("department/list");
mav.getModel().put("departmentList", list);
mav.getModel().put("pageCode", pagation);
return mav;
}
@RequestMapping(value = "detail")
public void detail(HttpServletRequest request, HttpServletResponse response){
Long departmentId = ParamUtils.getLongParameter(request, "department_id", 0L);
if(departmentId == 0L){
ResultUtil.fail(LocalizationUtil.getClientString("Account_22", request), response);
return;
}
Department department = departmentService.findDepartmentById(departmentId);
ResultUtil.success(department, response);
}
@RequestMapping(value = "delete")
public void delete(HttpServletRequest request, HttpServletResponse response){
Long departmentId = ParamUtils.getLongParameter(request, "department_id", 0L);
if(departmentId == 0L){
ResultUtil.fail(LocalizationUtil.getClientString("Account_22", request), response);
return;
}
departmentService.deleteById(departmentId);
ResultUtil.success(response);
}
@RequestMapping("add")
public void add(HttpServletRequest request, HttpServletResponse response){
Account account = (Account) request.getSession().getAttribute("currentAccount");
if (account == null) {
ResultUtil.fail(response);
return;
}
Long departmentId = ParamUtils.getLongParameter(request, "department_id", 0L);
String departmentName = ParamUtils.getParameter(request, "department_name");
String departmentFunction = ParamUtils.getParameter(request, "department_function");
String departmentDescription = ParamUtils.getParameter(request, "department_description");
Organization organization = organizationService.findOrganizationByAccountId(account.getId());
Department department = new Department();
department.setOrgId(organization.getId());
}
return num;
} else {
return defaultNum;
}
}
/**
* Gets an attribute as a long.
*
* @param request The HttpServletRequest object, known as "request" in a JSP
* page.
* @param name The name of the attribute you want to get
* @return The long value of the attribute or the default value if the
* attribute is not found or is a zero length string.
*/
public static long getLongAttribute(HttpServletRequest request, String name, long defaultNum) {
String temp = (String) request.getAttribute(name);
if (temp != null && !temp.equals("")) {
long num = defaultNum;
try {
num = Long.parseLong(temp);
} catch (Exception ignored) {
}
return num;
} else {
return defaultNum;
}
}
/**
* @param request
* @param names
* @return
*/
public static String getOptinalParameter(HttpServletRequest request, String... names) {
return getOptinalParameter(request, false, false, names);
}
public static String getOptinalParameter(HttpServletRequest request, boolean emptyStringsOK, boolean needFilter, String... names) {
if (names == null || names.length == 0)
*/
public static <T> void success(T obj, String message, HttpServletResponse response) {
addP3P(response);
ResultBean<T> resultBean = new ResultBean(true, message, obj);
String jsonString = JSON.toJSONString(resultBean, features);
byte[] bout = null;
try {
bout = jsonString.getBytes("UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
outputData(bout, response);
}
/**
* 调用成功,没有数据返回
*
* @param response
*/
public static void fail(HttpServletResponse response) {
fail("请求失败!", response);
}
public static void fail(String message, HttpServletResponse response) {
addP3P(response);
ResultBean resultBean = new ResultBean(false, message);
String jsonString = JSON.toJSONString(resultBean, features);
byte[] bout = null;
try {
bout = jsonString.getBytes("UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
outputData(bout, response);
}
public static void outputData(byte[] bout, HttpServletResponse response) {
response.setContentType("text/html;charset=utf-8");
try {
OutputStream out = response.getOutputStream();
out.write(bout);
cookie.setMaxAge(maxAge);
response.addCookie(cookie);
}
/**
* 将cookie封装到Map里面
* @param request
* @return
*/
private static Map<String,Cookie> readCookieMap(HttpServletRequest request){
Map<String,Cookie> cookieMap = new HashMap<String,Cookie>();
Cookie[] cookies = request.getCookies();
if(null!=cookies){
for(Cookie cookie : cookies){
cookieMap.put(cookie.getName(), cookie);
}
}
return cookieMap;
}
/**
* 根据名字获取cookie
* @param request
* @param name cookie名字
* @return
*/
public static Cookie getCookieByName(HttpServletRequest request,String name){
if (name == null) {
return null;
}
Cookie[] cookies = request.getCookies();
if (null != cookies) {
for (Cookie cookie : cookies) {
if (name.equals(cookie.getName())) {
return cookie;
}
}
}
return null;
}
}
ModelAndView mav = new ModelAndView("departmentApply/list");
mav.getModel().put("pageCode", pagation);
mav.getModel().put("applyList", list);
return mav;
}
@RequestMapping("getDepartmentList")
public void getDepartmentList(HttpServletRequest request, HttpServletResponse response){
Account account = (Account) request.getSession().getAttribute("currentAccount");
if (account == null) {
ResultUtil.fail(LocalizationUtil.getClientString("Account_22", request), response);
return;
}
List<Department> departmentList = departmentService.findList(0, 1, 0);
ResultUtil.success(departmentList, response);
}
/**
* 提交申请
*
* @param request
* @param response
*/
@RequestMapping("apply")
public void apply(HttpServletRequest request, HttpServletResponse response) {
Account account = (Account) request.getSession().getAttribute("currentAccount");
if (account == null) {
ResultUtil.fail("请登录", response);
}
long departmentId = ParamUtils.getLongParameter(request, "departmentId", 0L);
Department department = departmentService.findDepartmentById(departmentId);
if (department == null) {
ResultUtil.fail(LocalizationUtil.getClientString("Account_22", request), response);
return;
}
int type = ParamUtils.getIntParameter(request, "type", 0);
String content = ParamUtils.getParameter(request, "content", "");
content = sensitiveService.filter(content);
DepartmentApply apply = new DepartmentApply();
apply.setAccountId(account.getId());
apply.setContent(content);
apply.setCreateTime(new Date());
} else {
return null;
}
} catch (Exception e) {
log.error(e.getMessage());
return null;
}
}
public static String getParameter(HttpServletRequest request, String name, String defaultVal) {
try {
String temp = request.getParameter(name);
if (temp == null || "".equals(temp)) {
return defaultVal;
} else {
//过滤请求中的敏感词
// temp = JunkWordsUtil.filterSensitiveWord(temp);
return temp;
}
} catch (Exception e) {
log.error(e.getMessage());
return defaultVal;
}
}
/**
* Gets a parameter as a boolean.
*
* @param request The HttpServletRequest object, known as "request" in a JSP
* page.
* @param name The name of the parameter you want to get
* @return True if the value of the parameter was "true", false otherwise.
*/
public static boolean getBooleanParameter(HttpServletRequest request, String name) {
return getBooleanParameter(request, name, false);
}
/**
* Gets a parameter as a boolean.
*
* @param request The HttpServletRequest object, known as "request" in a JSP
* page.
* @param name The name of the parameter you want to get
* @return True if the value of the parameter was "true", false otherwise.
*/
public static Boolean getBooleanParameter(HttpServletRequest request, String name, Boolean defaultVal) {
String temp = request.getParameter(name);
if ("true".equals(temp) || "on".equals(temp)) {
return true;
} else if ("false".equals(temp) || "off".equals(temp)) {
return false;
* @param request The HttpServletRequest object, known as "request" in a JSP
* page.
* @param name The name of the parameter you want to get
* @param defaultNum The default value of a parameter, if the parameter can't be
* converted into an int.
*/
public static int[] getIntParameters(HttpServletRequest request, String name, int defaultNum) {
try {
String[] paramValues = request.getParameterValues(name);
if (paramValues == null) {
return null;
}
if (paramValues.length < 1) {
return new int[0];
}
int[] values = new int[paramValues.length];
for (int i = 0; i < paramValues.length; i++) {
try {
values[i] = Integer.parseInt(paramValues[i]);
} catch (Exception e) {
values[i] = defaultNum;
}
}
return values;
} catch (Exception e) {
log.error(e.getMessage());
return new int[0];
}
}
/**
* Gets a parameter as a double.
*
* @param request The HttpServletRequest object, known as "request" in a JSP
* page.
* @param name The name of the parameter you want to get
* @return The double value of the parameter specified or the default value
* if the parameter is not found.
*/
public static double getDoubleParameter(HttpServletRequest request, String name, double defaultNum) {
try {
String temp = request.getParameter(name);
if (temp != null && !temp.equals("")) {
double num = defaultNum;
String title = ParamUtils.getParameter(request, "title");
String subTitle = ParamUtils.getParameter(request, "subTitle");
int limitNum = ParamUtils.getIntParameter(request, "limitNum", 0);
String startTime = ParamUtils.getParameter(request, "startTime");
String endTime = ParamUtils.getParameter(request, "endTime");
String content = ParamUtils.getParameter(request, "content");
// 初始化时设置 日期和时间模式
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date start = sdf.parse(startTime);
Date end = sdf.parse(endTime);
DepartmentMember member = departmentMemberService.findMemberByAccountId(account.getId());
if(member == null){
ResultUtil.fail(response);
return;
}
Activity activity = new Activity();
activity.setTitle(title);
activity.setSubTitle(subTitle);
activity.setContent(content);
activity.setLimitNum(limitNum);
activity.setStartTime(start);
activity.setEndTime(end);
activity.setDepartmentMemberId(member.getDepartmentId());
activity.setDepartmentId(member.getDepartmentId());
activity.setType(Activity.ACTIVITY);
activityService.add(activity);
ResultUtil.success(response);
}
@RequestMapping("detail")
public ModelAndView detail(HttpServletRequest request, HttpServletResponse response){
Long activityId = ParamUtils.getLongParameter(request, "activityId");
Activity activity = activityService.findById(activityId);
ModelAndView mav = new ModelAndView("activity/detail");
mav.getModel().put("activity",activity);
return mav;
}
@RequestMapping("delete")
public void delete(HttpServletRequest request, HttpServletResponse response){
try {
values[i] = Integer.parseInt(paramValues[i]);
} catch (Exception e) {
values[i] = defaultNum;
}
}
return values;
} catch (Exception e) {
log.error(e.getMessage());
return new int[0];
}
}
/**
* Gets a parameter as a double.
*
* @param request The HttpServletRequest object, known as "request" in a JSP
* page.
* @param name The name of the parameter you want to get
* @return The double value of the parameter specified or the default value
* if the parameter is not found.
*/
public static double getDoubleParameter(HttpServletRequest request, String name, double defaultNum) {
try {
String temp = request.getParameter(name);
if (temp != null && !temp.equals("")) {
double num = defaultNum;
try {
num = Double.parseDouble(temp);
} catch (Exception ignored) {
}
return num;
} else {
return defaultNum;
}
} catch (Exception e) {
log.error(e.getMessage());
return defaultNum;
}
}
/**
* Gets a parameter as a long.
*
* @param request The HttpServletRequest object, known as "request" in a JSP
* page.
* @param name The name of the parameter you want to get
* @return The long value of the parameter specified or the default value if
}
return num;
} else {
return defaultNum;
}
} catch (Exception e) {
log.error(e.getMessage());
return defaultNum;
}
}
public static Long getLongParameter(HttpServletRequest request, String name) {
Long num = null;
try {
String temp = request.getParameter(name);
if (StringUtils.isNoneBlank(temp)) {
num = Long.parseLong(temp.trim());
}
return num;
} catch (Exception ignore) {
return num;
}
}
/**
* Gets a list of long parameters.
*
* @param request The HttpServletRequest object, known as "request" in a JSP
* page.
* @param name The name of the parameter you want to get
* @param defaultNum The default value of a parameter, if the parameter can't be
* converted into a long.
*/
public static long[] getLongParameters(HttpServletRequest request, String name, long defaultNum) {
String[] paramValues = request.getParameterValues(name);
if (paramValues == null) {
return null;
}
if (paramValues.length < 1) {
return new long[0];
}
*
* @param obj 返回的数据
* @param message 消息
* @param response
* @param <T>
*/
public static <T> void success(T obj, String message, HttpServletResponse response) {
addP3P(response);
ResultBean<T> resultBean = new ResultBean(true, message, obj);
String jsonString = JSON.toJSONString(resultBean, features);
byte[] bout = null;
try {
bout = jsonString.getBytes("UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
outputData(bout, response);
}
/**
* 调用成功,没有数据返回
*
* @param response
*/
public static void fail(HttpServletResponse response) {
fail("请求失败!", response);
}
public static void fail(String message, HttpServletResponse response) {
addP3P(response);
ResultBean resultBean = new ResultBean(false, message);
String jsonString = JSON.toJSONString(resultBean, features);
byte[] bout = null;
try {
bout = jsonString.getBytes("UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
outputData(bout, response);
}
departmentApply.setStatusName("通过");
}else if(departmentApply.getStatus() == DepartmentApply.REJECT){
departmentApply.setStatusName("拒绝");
}
}
}
int totalCount = departmentApplyService.getTotalCount(0);
String pagation = PageUtil.getPagation("/departmentApply/applyList", totalCount, start, limit);
ModelAndView mav = new ModelAndView("departmentApply/pendList");
mav.getModel().put("pageCode", pagation);
mav.getModel().put("applyList", list);
return mav;
}
@RequestMapping("pend")
public void pend(HttpServletRequest request, HttpServletResponse response){
Account account = (Account) request.getSession().getAttribute("currentAccount");
if (account == null) {
ResultUtil.fail(LocalizationUtil.getClientString("Account_22", request), response);
return;
}
long applyId = ParamUtils.getLongParameter(request, "applyId", 0L);
DepartmentApply departmentApply = departmentApplyService.findById(applyId);
if(departmentApply == null){
ResultUtil.fail(LocalizationUtil.getClientString("Account_22", request), response);
return;
}
int status = ParamUtils.getIntParameter(request, "status", 0);
if(status == 0){
ResultUtil.fail(LocalizationUtil.getClientString("Account_22", request), response);
return;
}
if(status == DepartmentApply.PASS){
DepartmentMember member = new DepartmentMember();
member.setAccountId(departmentApply.getAccountId());
member.setCreateTime(new Date());
member.setDepartmentId(departmentApply.getDepartmentId());
member.setRemark("");
member.setRole(departmentApply.getType());
member.setStatus(1);
DepartmentMember dbDepartmentMember = departmentMemberService.findMemberByAccountId(departmentApply.getAccountId());
if(dbDepartmentMember == null) {
departmentMemberService.insert(member);
}else {
departmentMemberService.update(member);
}
Account applyAccount = accountService.findAccountById(departmentApply.getAccountId());
applyAccount.setType(departmentApply.getType());
// 更改用户状态
public class LocalizationUtil {
private static final String BUNDLE_NAME = "messages"; //$NON-NLS-1$
private static final String MISSING_BUNDLE = "!Missing bundle {0}!"; //$NON-NLS-1$
private static final String MISSING_KEY = "!{0}!"; //$NON-NLS-1$
private static ClassLoader classLoader = LocalizationUtil.class.getClassLoader();
private LocalizationUtil() {
}
public static String getClientString(String key, HttpServletRequest request) {
try {
if (request == null) {
return getString(BUNDLE_NAME, key, null);
}
return getString(BUNDLE_NAME, key, getLocale(request));
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}
public static String getClientString(String key, Locale locale) {
if (locale == null)
locale = Locale.CHINA;
return getString(BUNDLE_NAME, key, locale);
}
public static String getClientString(String key, Object[] params, Locale locale) {
try {
return MessageFormat.format(getString(BUNDLE_NAME, key, locale), params);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}
public static Locale getLocale(HttpServletRequest request) {
if (StringUtils.isNoneBlank(temp)) {
num = Long.parseLong(temp.trim());
}
return num;
} catch (Exception ignore) {
return num;
}
}
/**
* Gets a list of long parameters.
*
* @param request The HttpServletRequest object, known as "request" in a JSP
* page.
* @param name The name of the parameter you want to get
* @param defaultNum The default value of a parameter, if the parameter can't be
* converted into a long.
*/
public static long[] getLongParameters(HttpServletRequest request, String name, long defaultNum) {
String[] paramValues = request.getParameterValues(name);
if (paramValues == null) {
return null;
}
if (paramValues.length < 1) {
return new long[0];
}
long[] values = new long[paramValues.length];
for (int i = 0; i < paramValues.length; i++) {
try {
values[i] = Long.parseLong(paramValues[i]);
} catch (Exception e) {
values[i] = defaultNum;
}
}
return values;
}
/**
* Gets a parameter as a string.
*
* @param request The HttpServletRequest object, known as "request" in a JSP
* page.
* @param name The name of the parameter you want to get
return mav;
}
@RequestMapping("addActivity")
public void addActivity(HttpServletRequest request, HttpServletResponse response) throws ParseException {
Account account = (Account) request.getSession().getAttribute("currentAccount");
if (account == null) {
ResultUtil.fail(response);
return;
}
String title = ParamUtils.getParameter(request, "title");
String subTitle = ParamUtils.getParameter(request, "subTitle");
int limitNum = ParamUtils.getIntParameter(request, "limitNum", 0);
String startTime = ParamUtils.getParameter(request, "startTime");
String endTime = ParamUtils.getParameter(request, "endTime");
String content = ParamUtils.getParameter(request, "content");
// 初始化时设置 日期和时间模式
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date start = sdf.parse(startTime);
Date end = sdf.parse(endTime);
DepartmentMember member = departmentMemberService.findMemberByAccountId(account.getId());
if(member == null){
ResultUtil.fail(response);
return;
}
Activity activity = new Activity();
activity.setTitle(title);
activity.setSubTitle(subTitle);
activity.setContent(content);
activity.setLimitNum(limitNum);
activity.setStartTime(start);
activity.setEndTime(end);
activity.setDepartmentMemberId(member.getDepartmentId());
activity.setDepartmentId(member.getDepartmentId());
activity.setType(Activity.ACTIVITY);
activityService.add(activity);
ResultUtil.success(response);