SSM框架的搭建可以参考前一篇博文,里面有详细步骤。---传送门---
下面开始上源码
applicationContext:
springmvcConfig:
web.xml
body
login.jsp
404
/errorpage/404.jsp
500
/errorpage/500.jsp
CharacterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
utf-8
CharacterEncodingFilter
/*
contextConfigLocation
WEB-INF/applicationContext.xml
log4jConfigLocation
classpass:log4j.properties
org.springframework.web.context.ContextLoaderListener
springmvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
WEB-INF/springmvcConfig.xml
1
springmvc
/
default
*.js
default
*.css
jdbc:
url=jdbc:mysql://localhost:3306/bodybuilding?useUnicode=true&characterEncoding=utf-8
username=root
password=root
classDriverName=com.mysql.jdbc.Driver
minPoolSize=1
maxPoolSize=300
maxIdleTime=60
acquireIncrement=5
initialPoolSize=1
idleConnectionTestPeriod=60U
UserController
package com.cn.controller;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
import com.cn.pojo.User;
import com.cn.service.IUserService;
@Controller
@RequestMapping("/user")
public class UserController {
@Resource
private IUserService userService;
/**
* 登录
* @return
*/
@ResponseBody
@RequestMapping("/login")
public String toIndex(User user,HttpSession session){
String account=user.getAccount();
user=userService.userLogin(user.getAccount(),user.getPwd());
if(user!=null){
List
SysController
package com.cn.controller;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.cn.pojo.Admin;
import com.cn.pojo.Teach;
import com.cn.pojo.User;
import com.cn.service.IUserService;
@Controller
@RequestMapping("/sys")
public class SysController {
@Resource
private IUserService userService;
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* 管理员登录
* @param admin
* @param session
* @return
*/
@ResponseBody
@RequestMapping("/loginAdmin")
public String toIndex(Admin admin,HttpSession session){
admin=userService.adminLogin(admin.getName(),admin.getPwd());
if(admin!=null){
session.setAttribute("lastLoginTime", admin.getLastlogintime());
session.setAttribute("account", "123");
userService.setTime(df.format(new Date()));
return "true";
}else{
return "false";
}
}
/**
* 管理员登录跳转
* @param session
* @return
*/
@RequestMapping("/ForwardAdmin")
public String loginForward(HttpSession session){
List> countUserList=userService.countUser();
session.setAttribute("countUser",countUserList);
List> countTeachList=userService.countTeach();
session.setAttribute("countTeach",countTeachList);
List> countApparatusList=userService.countApparatus();
session.setAttribute("countApparatus",countApparatusList);
return "sys/main";
}
/**
* 用户列表
* @param session
* @return
*/
@RequestMapping("/userTable")
public String userTable(HttpSession session){
List> findUserList=userService.findUser();
session.setAttribute("findUserList",findUserList);
return "sys/userTable";
}
/**
* 教练列表
* @param session
* @return
*/
@RequestMapping("/teachTable")
public String teachTable(HttpSession session){
List> findUserList=userService.teachTable();
session.setAttribute("findTeachList",findUserList);
return "sys/teachTable";
}
/**
* 器材列表
* @param session
* @return
*/
@RequestMapping("/apparatusTable")
public String apparatusTable(HttpSession session){
List> findUserList=userService.apparatusTable();
session.setAttribute("findApparatusList",findUserList);
return "sys/apparatusTable";
}
/**
* 退出
* @return
*/
@RequestMapping("/exit")
public String exit(HttpSession session){
session.invalidate();
return "login";
}
/**
* 统计性别比例
* @return
*/
@ResponseBody
@RequestMapping("/getSex")
public List getSex(){
List list=userService.getSex();
return list;
}
/**
* 删除用户
* @return
*/
@ResponseBody
@RequestMapping("/delUser")
public String delUser(Integer id){
userService.delUser(id);
return "true";
}
/**
* 删除教练
* @return
*/
@ResponseBody
@RequestMapping("/delTeach")
public String delTeach(Integer id){
userService.delTeach(id);
return "true";
}
/**
* 删除器材
* @return
*/
@ResponseBody
@RequestMapping("/delApp")
public String delApp(Integer id){
userService.delApp(id);
return "true";
}
/**
* 更新用户信息
* @return
*/
@RequestMapping("/upUser")
public String upUser(Integer id,String account,Integer sex,Integer age,String name,String pwd,String tel,String address,HttpSession session){
List list=new ArrayList();
list.add(id);
list.add(account);
list.add(sex);
list.add(age);
list.add(name);
list.add(pwd);
list.add(tel);
list.add(address);
session.setAttribute("upList", list);
return "sys/upUser";
}
/**
* 更新教练信息
* @return
*/
@RequestMapping("/upTeach")
public String upTeach(Integer id,String tname,Integer cid,String ttel,String taddress,HttpSession session){
List list=new ArrayList();
list.add(id);
list.add(tname);
list.add(cid);
list.add(ttel);
list.add(taddress);
session.setAttribute("upTeachList", list);
return "sys/upTeach";
}
/**
* 添加用户
* @param user
* @return
*/
@ResponseBody
@RequestMapping("/registerUser")
public String registerUser(User user){
List id=userService.findAccount(user.getAccount());
if(id.size()!=0){
return "false";
}
userService.registerUser(user);
return "true";
}
@RequestMapping("/addUser")
public String addUser(){
return "sys/addUser";
}
/**
* 添加教练
* @return
*/
@RequestMapping("/addTeach")
public String addTeach(){
return "sys/addTeach";
}
/**
* 添加器材
* @return
*/
@RequestMapping("/addApp")
public String addApp(){
return "sys/addApp";
}
/**
* 更新用户信息
* @return
*/
@ResponseBody
@RequestMapping("/upUserInfo")
public String upUserInfo(Integer id,String account,Integer sex,Integer age,String name,String pwd,String tel,String address){
userService.updateUserInfo(id,account,sex,age,name,pwd,tel,address);
return "true";
}
/**
* 更新教练信息
* @return
*/
@ResponseBody
@RequestMapping(value="/upTeachInfo",method=RequestMethod.POST)
public String upTeach(Integer id,String tname,Integer cid,String ttel,String taddress){
userService.upTeach(id,tname,cid,ttel,taddress);
return "true";
}
@ResponseBody
@RequestMapping("/addTeachInfo")
public String addTeachInfo(Teach teach){
userService.addTeachInfo(teach);
return "true";
}
@ResponseBody
@RequestMapping("/addAppInfo")
public String addAppInfo(String aname){
userService.addAppInfo(aname);
return "true";
}
}
UserMapper.xml
update user
uteach=#{0},uclass=#{1}
where id=#{2}
update user
account=#{account},
sex = ${sex},
age = ${age},
name = #{name},
pwd = #{pwd},
tel = #{tel},
address = #{address},
where id=#{id}
update teach
cid=${cid},
tname = #{tname},
ttel = #{ttel},
taddress = #{taddress},
where id=#{id}
update admin
lastlogintime=#{format}
where name='admin'
update apparatus
astate=1
where id=#{id}
insert into user(id,name, pwd,account,age,sex,tel,address) values(null, #{name}, #{pwd}, #{account}, ${age},${sex},#{tel},#{address})
insert into teach(id,tname,cid,ttel,taddress) values(null, #{tname}, #{cid}, #{ttel}, #{taddress})
insert into apparatus(id,aname,astate) values(null, #{aname}, 0)
DELETE FROM user where id=#{id}
DELETE FROM teach where id=#{id}
项目DEMO地址
项目演示连接 账号密码详见