源码获取:俺的博客首页 "资源" 里下载!
项目介绍
本项目分为超级管理员、管理员、学生三种角色,
超级管理员角色包含以下功能:
通知管理、用户管理、实验室管理、实验室预约记录、设备管理、设备借用管理、设备维修管理等功能。
管理员角色包含以下功能:
通知管理、用户管理、实验室管理、实验室预约记录、实验室预约、设备管理、设备借用管理、设备维修管理等功能。
普通学生角色包含以下功能:
通知管理、用户管理、实验室管理、设备借用管理等功能。
环境需要
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 8.0版本;
6.是否Maven项目:是;
技术栈
1. 后端:Spring+SpringMVC+Mybatis
2. 前端:freemarker+bootstrap
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中config.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/ 登录
系统用户管理控制层:
@Controller
public class SysuserController {
@Resource
private SysuserServier userService;
@RequestMapping("flogin.do")
public String login() {
return "login";
}
@RequestMapping("admin/showUserInfo.do")
public String showUserInfo(ModelMap map,HttpSession session){
if(session.getAttribute("auser")==null){
return "login";
}
Sysuser u=(Sysuser)session.getAttribute("auser");
map.put("user",userService.getById(u.getUid()));
return "admin/update_user_persion";
}
@RequestMapping("admin/updatePersionUser.do")
public String updateUserInfo(ModelMap map,HttpSession session,Sysuser user){
userService.update(user);
map.put("user", userService.getById(user.getUid()));
session.setAttribute("suc", "cc");
return "redirect:showUserInfo.do";
}
@RequestMapping("admin/login.do")
public String aLogin() {
return "admin/login";
}
// 处理修改个人信息
@RequestMapping("showInfo.do")
public String showInfo(HttpSession session,ModelMap map) {
Sysuser u=(Sysuser)session.getAttribute("user");
if(u==null){
return "fore_login";
}else{
map.put("user", userService.getById(u.getUid()));
return "showUserinfo";
}
}
// 处理修改个人信息
@RequestMapping("addShowInfo.do")
public String addShowInfo(HttpSession session,ModelMap map,Sysuser user) {
userService.update(user);
return "success";
}
// 文件上传
public String fileUpload(@RequestParam(value="file",required=false)MultipartFile file,
HttpServletRequest request,String img){
String path=request.getSession().getServletContext().getRealPath("upload");
System.out.println("path==="+path);
System.out.println("file==="+file);
String fileName=file.getOriginalFilename();
System.out.println("fileName==="+fileName);
File targetFile=new File(path,fileName);
if(!targetFile.exists()){
targetFile.mkdirs();
}
try {
file.transferTo(targetFile);
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String pa=request.getContextPath()+"/upload/"+fileName;
System.out.println("path==="+pa);
if(fileName!=null&&!fileName.equals("")){
img=fileName;
}else{
img=null;
}
return img;
}
// 后台登录
@RequestMapping("admin/alogin.do")
public String checkLogin(ModelMap map,Sysuser user, HttpSession session) {
Map<String,Object> u=new HashMap<String,Object>();
System.out.println("name===" + user.getUname());
System.out.println("pwd===" + user.getPwd());
u.put("uname",user.getUname());
u.put("utype", user.getUtype());
u.put("pwd",user.getPwd());
user = userService.adminLogin(u);
if (user != null) {
session.setAttribute("auser", user);
System.out.println("auser=" + user);
return "admin/index";
} else {
map.put("errorInfo", "用户名或者密码错误!");
return "admin/login";
}
}
// 后台注销登录
@RequestMapping("admin/loginout.do")
public String adminLoginOut(HttpSession session) {
session.removeAttribute("auser");
return "redirect:login.do";
}
// 前台注销登录
@RequestMapping("loginout.do")
public String loginOut(HttpSession session) {
session.removeAttribute("user");
session.removeAttribute("p");
return "fore_login";
}
// 验证用户名是否存在
@RequestMapping("admin/checkUname.do")
public void checkUname(Sysuser user,HttpServletResponse response){
Map<String,Object> map=new HashMap<String,Object>();
map.put("uname", user.getUname());
System.out.println("uname==="+user.getUname());
System.out.println("uname222==="+userService.checkUname(map));
JSONObject obj=new JSONObject();
if(userService.checkUname(map)!=null){
obj.put("info", "ok");
}else{
obj.put("info", "用户名可以用!");
}
response.setContentType("text/html;charset=utf-8");
PrintWriter out=null;
try {
out=response.getWriter();
out.print(obj);
out.flush();
} catch (IOException e) {
e.printStackTrace();
}finally{
out.close();
}
}
@RequestMapping("checkmibao.do")
public void checkMB(Sysuser user,HttpServletResponse response,HttpSession session){
JSONObject obj=new JSONObject();
Sysuser u=userService.getById(user.getUid());
String q=u.getQuestion();
if(u==null||u.equals("")){
obj.put("info", "ng");
}else{
if(q.equals(user.getQuestion())){
obj.put("info", u.getPwd());
}else{
obj.put("info", "ng");
}
}
response.setContentType("text/html;charset=utf-8");
PrintWriter out=null;
try {
out=response.getWriter();
out.print(obj);
out.flush();
} catch (IOException e) {
e.printStackTrace();
}finally{
out.close();
}
}
// 验证用户名是否存在
@RequestMapping("checkUname.do")
public void checkReg(Sysuser user,HttpServletResponse response){
Map map=new HashMap();
map.put("uname", user.getUname());
System.out.println("uname==="+user.getUname());
System.out.println("uname222==="+userService.checkUname(map));
JSONObject obj=new JSONObject();
if(userService.checkUname(map)!=null){
System.out.println("uname233333333333===");
obj.put("info", "ng");
}else{
System.out.println("uname255555555555555===");
obj.put("info", "用户名可以用!");
}
response.setContentType("text/html;charset=utf-8");
PrintWriter out=null;
try {
out=response.getWriter();
out.print(obj);
out.flush();
} catch (IOException e) {
e.printStackTrace();
}finally{
out.close();
}
}
@RequestMapping("checkPass.do")
public void checkPass(Sysuser user,HttpServletResponse response){
Map map=new HashMap();
map.put("uname", user.getUname());
System.out.println("uname==="+user.getUname());
System.out.println("uname222==="+userService.checkUname(map));
JSONObject obj=new JSONObject();
if(userService.checkUname(map)!=null){
obj.put("info", userService.checkUname(map).getPwd());
}else{
obj.put("info", "ng");
}
response.setContentType("text/html;charset=utf-8");
PrintWriter out=null;
try {
out=response.getWriter();
out.print(obj);
out.flush();
} catch (IOException e) {
e.printStackTrace();
}finally{
out.close();
}
}
@RequestMapping("reg.do")
public String addReg(Sysuser user, HttpSession session) {
user.setIsdel("1");
user.setUtype("会员");
Timestamp time=new Timestamp(System.currentTimeMillis());
user.setPubtime(time.toString());
userService.add(user);
return "fore_login";
}
// 添加用户
@RequestMapping("admin/addUser.do")
public String addUser(Sysuser user, HttpSession session) {
user.setIsdel("1");
Timestamp time=new Timestamp(System.currentTimeMillis());
user.setPubtime(time.toString());
userService.add(user);
return "redirect:userList.do";
}
// 管理员注册
@RequestMapping("admin/addUser2.do")
public String addUser2(Sysuser user, HttpSession session) {
user.setIsdel("1");
Timestamp time=new Timestamp(System.currentTimeMillis());
user.setPubtime(time.toString());
userService.add(user);
return "admin/login";
}
// 处理更新用户的信息
@RequestMapping("admin/doUpdateUser.do")
public String doUpdateUser(ModelMap map, int id) {
System.out.println("id=="+id);
map.put("user",userService.getById(id));
return "admin/update_user";
}
// 更新用户的信息
@RequestMapping("admin/updateUser.do")
public String updateUser(Sysuser user) {
userService.update(user);
return "redirect:userList.do";
}
// 查询所有用户的信息
@RequestMapping("admin/userList.do")
public String userList(@RequestParam(value = "page", required = false) String page, HttpSession session,
ModelMap map) {
if (page == null || page.equals("")) {
page = "1";
}
PageBean pageBean = new PageBean(Integer.parseInt(page), PageBean.PAGESIZE);
Map<String, Object> pmap = new HashMap<String, Object>();
pmap.put("pageno", pageBean.getStart());
pmap.put("pageSize", pageBean.getPageSize());
Map cmap=new HashMap();
/*pmap.put("utype", "会员");
cmap.put("utype", "会员");*/
int total = userService.getCount(cmap);
pageBean.setTotal(total);
List<Sysuser> list = userService.getByPage(pmap);
map.put("page", pageBean);
map.put("list", list);
session.setAttribute("p", 1);
return "admin/user_list";
}
// 模糊查询并分页
@RequestMapping("admin/userListQuery.do")
public String useListQuery(@RequestParam(value = "page", required = false) String page, HttpSession session,
ModelMap map,Sysuser user) {
if (page == null || page.equals("")) {
page = "1";
}
PageBean pageBean = new PageBean(Integer.parseInt(page), PageBean.PAGESIZE);
Map<String, Object> pmap = new HashMap<String, Object>();
pmap.put("pageno", pageBean.getStart());
pmap.put("pageSize", pageBean.getPageSize());
pmap.put("uname", user.getUname());
Map cmap=new HashMap();
/* pmap.put("utype", "会员");
cmap.put("utype", "会员");*/
int total = userService.getCount(pmap);
pageBean.setTotal(total);
List<Sysuser> list = userService.getByPage(pmap);
map.put("page", pageBean);
map.put("list", list);
session.setAttribute("p", 2);
return "admin/user_list";
}
@RequestMapping("admin/deleteUser.do")
public String deleteUser(int id){
userService.delete(id);
return "redirect:userList.do";
}
}
实验设备管理控制层:
@Controller
public class ShiYanController {
@Resource
private ShiYanServer ShiYanService;
@Resource
private ForderServer orderService;
@Resource
private SysuserServier userService;
// 文件上传
public String fileUpload(@RequestParam(value="file",required=false)MultipartFile file,
HttpServletRequest request,String img){
String path=request.getSession().getServletContext().getRealPath("upload");
String fileName=file.getOriginalFilename();
File targetFile=new File(path,fileName);
if(!targetFile.exists()){
targetFile.mkdirs();
}
try {
file.transferTo(targetFile);
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String pa=request.getContextPath()+"/upload/"+fileName;
System.out.println("path==="+pa);
if(fileName!=null&&!fileName.equals("")){
img=fileName;
}else{
img="zanwu.jpg";
}
return img;
}
// 实验室管理
@RequestMapping("admin/addShiYan.do")
public String addShiYan(ModelMap map,ShiYan shiYan,HttpServletRequest request){
Timestamp time=new Timestamp(System.currentTimeMillis());
shiYan.setFtype("实验室");
shiYan.setMstatus("空闲中");
shiYan.setIsdel("1");
shiYan.setPubtime(time.toString().substring(0, 19));
ShiYanService.add(shiYan);
return "redirect:ShiYanList.do";
}
@RequestMapping("admin/doUpdateShiYan.do")
public String doUpdateShiYan(ModelMap map,int id){
map.put("sy", ShiYanService.getById(id));
return "admin/update_ShiYan";
}
@RequestMapping("admin/updateShiYan.do")
public String updateShiYan( HttpServletRequest request,ShiYan ShiYan){
ShiYanService.update(ShiYan);
return "redirect:ShiYanList.do";
}
// 分页查询
@RequestMapping("admin/ShiYanList.do")
public String shiYanList(@RequestParam(value="page",required=false)String page,
ModelMap map,HttpSession session){
if(page==null||page.equals("")){
page="1";
}
PageBean pageBean=new PageBean(Integer.parseInt(page), PageBean.PAGESIZE);
Map<String, Object> pmap=new HashMap<String,Object>();
pmap.put("pageno", pageBean.getStart());
pmap.put("pageSize", pageBean.getPageSize());
Map<String, Object> cmap=new HashMap<String, Object>();
pmap.put("name", null);
cmap.put("name", null);
cmap.put("ftype", "实验室");
pmap.put("ftype", "实验室");
int total=ShiYanService.getCount(cmap);
pageBean.setTotal(total);
List<ShiYan> list=ShiYanService.getByPage(pmap);
map.put("page", pageBean);
map.put("list", list);
session.setAttribute("p", 1);
return "admin/list_ShiYan";
}
// 分页模糊查询
@RequestMapping("admin/vagueShiYanList.do")
public String vagueShiYanList(@RequestParam(value="page",required=false)String page,
ModelMap map,HttpSession session,ShiYan cd){
if(page==null||page.equals("")){
page="1";
}
PageBean pageBean=new PageBean(Integer.parseInt(page),PageBean.PAGESIZE);
Map<String, Object> pmap=new HashMap<String,Object>();
pmap.put("pageno", pageBean.getStart());
pmap.put("pageSize", pageBean.getPageSize());
Map<String, Object> cmap=new HashMap<String,Object>();
if(cd.getName()!=null&&!cd.getName().equals("")){
cmap.put("name", cd.getName());
pmap.put("name", cd.getName());
}
cmap.put("ftype", "实验室");
pmap.put("ftype", "实验室");
int total=ShiYanService.getCount(cmap);
pageBean.setTotal(total);
List<ShiYan> list=ShiYanService.getByPage(pmap);
map.put("page", pageBean);
map.put("list", list);
session.setAttribute("p", 2);
return "admin/list_ShiYan";
}
@RequestMapping("admin/deleteShiYan.do")
public String deleteShiYan(int id){
ShiYanService.delete(id);
return "redirect:ShiYanList.do";
}
// 设备管理
@RequestMapping("admin/addSheBei.do")
public String addSheBei(ModelMap map,ShiYan shiYan,HttpServletRequest request){
Timestamp time=new Timestamp(System.currentTimeMillis());
shiYan.setFtype("设备");
shiYan.setMstatus("充足");
shiYan.setIsdel("1");
shiYan.setPubtime(time.toString().substring(0, 19));
ShiYanService.add(shiYan);
return "redirect:SheBeiList.do";
}
@RequestMapping("admin/doUpdateSheBei.do")
public String doUpdateSheBei(ModelMap map,int id){
map.put("sy", ShiYanService.getById(id));
return "admin/update_SheBei";
}
// 处理申请设备
@RequestMapping("admin/doAddForderSheBei.do")
public String doAddForderSheBei(ModelMap map,int id){
map.put("sy", ShiYanService.getById(id));
return "admin/add_order_sheBei";
}
// 处理申请耗材
@RequestMapping("admin/doAddForderHaoCai.do")
public String doAddForderHaoCai(ModelMap map,int id){
map.put("sy", ShiYanService.getById(id));
return "admin/add_order_haoCai";
}
@RequestMapping("admin/updateSheBei.do")
public String updateSheBei(HttpServletRequest request,ShiYan ShiYan){
ShiYanService.update(ShiYan);
return "redirect:SheBeiList.do";
}
// 分页查询
@RequestMapping("admin/SheBeiList.do")
public String sheBeiList(@RequestParam(value="page",required=false)String page,
ModelMap map,HttpSession session){
if(page==null||page.equals("")){
page="1";
}
PageBean pageBean=new PageBean(Integer.parseInt(page), PageBean.PAGESIZE);
Map<String, Object> pmap=new HashMap<String,Object>();
pmap.put("pageno", pageBean.getStart());
pmap.put("pageSize", pageBean.getPageSize());
Map<String, Object> cmap=new HashMap<String, Object>();
cmap.put("ftype", "设备");
pmap.put("ftype", "设备");
int total=ShiYanService.getCount(cmap);
pageBean.setTotal(total);
List<ShiYan> list=ShiYanService.getByPage(pmap);
map.put("page", pageBean);
map.put("list", list);
session.setAttribute("p", 1);
return "admin/list_SheBei";
}
// 分页模糊查询
@RequestMapping("admin/vagueSheBeiList.do")
public String vagueSheBeiList(@RequestParam(value="page",required=false)String page,
ModelMap map,HttpSession session,ShiYan cd){
if(page==null||page.equals("")){
page="1";
}
PageBean pageBean=new PageBean(Integer.parseInt(page),PageBean.PAGESIZE);
Map<String, Object> pmap=new HashMap<String,Object>();
pmap.put("pageno", pageBean.getStart());
pmap.put("pageSize", pageBean.getPageSize());
Map<String, Object> cmap=new HashMap<String,Object>();
if(cd.getName()!=null&&!cd.getName().equals("")){
cmap.put("name", cd.getName());
pmap.put("name", cd.getName());
}
cmap.put("ftype", "设备");
pmap.put("ftype", "设备");
int total=ShiYanService.getCount(cmap);
pageBean.setTotal(total);
List<ShiYan> list=ShiYanService.getByPage(pmap);
map.put("page", pageBean);
map.put("list", list);
session.setAttribute("p", 2);
return "admin/list_SheBei";
}
@RequestMapping("admin/deleteSheBei.do")
public String deleteSheBei(int id){
ShiYanService.delete(id);
return "redirect:SheBeiList.do";
}
// 耗材管理
@RequestMapping("admin/addHaoCai.do")
public String addHaoCai(ModelMap map,ShiYan shiYan,HttpServletRequest request){
Timestamp time=new Timestamp(System.currentTimeMillis());
shiYan.setFtype("耗材");
shiYan.setMstatus("充足");
shiYan.setIsdel("1");
shiYan.setPubtime(time.toString().substring(0, 19));
ShiYanService.add(shiYan);
return "redirect:HaoCaiList.do";
}
@RequestMapping("admin/doUpdateHaoCai.do")
public String doUpdateHaoCai(ModelMap map,int id){
map.put("sy", ShiYanService.getById(id));
return "admin/update_HaoCai";
}
@RequestMapping("admin/updateHaoCai.do")
public String updateHaoCai(HttpServletRequest request,ShiYan ShiYan){
ShiYanService.update(ShiYan);
return "redirect:HaoCaiList.do";
}
// 分页查询
@RequestMapping("admin/HaoCaiList.do")
public String haoCaiList(@RequestParam(value="page",required=false)String page,
ModelMap map,HttpSession session){
if(page==null||page.equals("")){
page="1";
}
PageBean pageBean=new PageBean(Integer.parseInt(page), PageBean.PAGESIZE);
Map<String, Object> pmap=new HashMap<String,Object>();
pmap.put("pageno", pageBean.getStart());
pmap.put("pageSize", pageBean.getPageSize());
Map<String, Object> cmap=new HashMap<String, Object>();
pmap.put("ftype", null);
cmap.put("name", null);
cmap.put("ftype", "耗材");
pmap.put("ftype", "耗材");
int total=ShiYanService.getCount(cmap);
pageBean.setTotal(total);
List<ShiYan> list=ShiYanService.getByPage(pmap);
map.put("page", pageBean);
map.put("list", list);
session.setAttribute("p", 1);
return "admin/list_HaoCai";
}
// 分页模糊查询
@RequestMapping("admin/vagueHaoCaiList.do")
public String vagueHaoCaiList(@RequestParam(value="page",required=false)String page,
ModelMap map,HttpSession session,ShiYan cd){
if(page==null||page.equals("")){
page="1";
}
PageBean pageBean=new PageBean(Integer.parseInt(page),PageBean.PAGESIZE);
Map<String, Object> pmap=new HashMap<String,Object>();
pmap.put("pageno", pageBean.getStart());
pmap.put("pageSize", pageBean.getPageSize());
Map<String, Object> cmap=new HashMap<String,Object>();
if(cd.getName()!=null&&!cd.getName().equals("")){
cmap.put("name", cd.getName());
pmap.put("name", cd.getName());
}
cmap.put("ftype", "耗材");
pmap.put("ftype", "耗材");
int total=ShiYanService.getCount(cmap);
pageBean.setTotal(total);
List<ShiYan> list=ShiYanService.getByPage(pmap);
map.put("page", pageBean);
map.put("list", list);
session.setAttribute("p", 2);
return "admin/list_HaoCai";
}
@RequestMapping("admin/deleteHaoCai.do")
public String deleteHaoCai(int id){
ShiYanService.delete(id);
return "redirect:HaoCaiList.do";
}
}
公告管理控制层:
@Controller
public class NewsController {
@Resource
private NewsServer newsService;
@Resource
private ForderServer ForderService;
@Resource
private SysuserServier userService;
@Resource
private ShiYanServer jzService;
// 首页显示内容
@RequestMapping("showIndex.do")
public String showIndex(ModelMap map){
Map<String, Object> pmap=new HashMap<String,Object>();
Map<String, Object> jzmap=new HashMap<String,Object>();
pmap.put("pageno", 0);
pmap.put("pageSize", 4);
jzmap.put("pageno", 0);
jzmap.put("pageSize", 10);
List<News> list=newsService.getByPage(pmap);
List<Forder> jlist=ForderService.getByPage(pmap);
List<ShiYan> clist=jzService.getAll(jzmap);
List<ShiYan> jzlist=jzService.getAll(null);
List<Forder> yplist=ForderService.showTop10(jzmap);
map.put("nlist", list);
map.put("jslist", jlist);
map.put("jzlist", clist);
map.put("yplist", yplist);
map.put("jlist", jzlist);
return "index";
}
// 首页显示内容
@RequestMapping("admin/showIndex.do")
public String ashowIndex(ModelMap map){
Map<String, Object> pmap=new HashMap<String,Object>();
pmap.put("pageno", 1);
pmap.put("pageSize", 4);
List<News> list=newsService.getByPage(pmap);
List<Forder> jlist=ForderService.getByPage(pmap);
List<ShiYan> clist=jzService.getByPage(pmap);
//List<Forder> jlist=ForderService.getByPage(pmap);
map.put("nlist", list);
map.put("jslist", jlist);
map.put("jzlist", clist);
return "index";
}
@RequestMapping("showNews.do")
public String showNews(ModelMap map,int id){
map.put("news", newsService.getById(id));
return "newsx";
}
@RequestMapping("admin/doAddNews.do")
public String doAddNews(ModelMap map){
map.put("tlist", newsService.getAll(null));
return "admin/add_news";
}
@RequestMapping("admin/addNews.do")
public String addNews(@RequestParam(value="file",required=false)MultipartFile file,
HttpServletRequest request,News news,String img){
img=fileUpload(file, request, img);
news.setGgpic(img);
Timestamp time=new Timestamp(System.currentTimeMillis());
/*news.setSavetime(time.toString());*/
news.setIsdel("1");
newsService.add(news);
return "redirect:newsList.do";
}
@RequestMapping("admin/doUpdateNews.do")
public String doUpdateNews(ModelMap map,int id){
map.put("news", newsService.getById(id));
return "admin/update_news";
}
@RequestMapping("admin/updateNews.do")
public String updateNews(@RequestParam(value="file",required=false)MultipartFile file,
HttpServletRequest request,News news,String img){
img=fileUpload(file, request, img);
news.setGgpic(img);
newsService.update(news);
return "redirect:newsList.do";
}
// 分页
@RequestMapping("fnewsList.do")
public String newsList(@RequestParam(value="page",required=false)String page,
ModelMap map,HttpSession session){
if(page==null||page.equals("")){
page="1";
}
PageBean pageBean=new PageBean(Integer.parseInt(page), PageBean.PAGESIZE);
Map<String, Object> pmap=new HashMap<String,Object>();
pmap.put("pageno", pageBean.getStart());
pmap.put("pageSize", pageBean.getPageSize());
int total=newsService.getCount(null);
System.out.println("total==="+total);
pageBean.setTotal(total);
List<News> list=newsService.getByPage(pmap);
map.put("page", pageBean);
map.put("list", list);
session.setAttribute("p", 1);
return "newlist";
}
// 分页查询
@RequestMapping("admin/newsList.do")
public String goodList(@RequestParam(value="page",required=false)String page,
ModelMap map,HttpSession session){
if(page==null||page.equals("")){
page="1";
}
PageBean pageBean=new PageBean(Integer.parseInt(page), PageBean.PAGESIZE);
Map<String, Object> pmap=new HashMap<String,Object>();
pmap.put("pageno", pageBean.getStart());
pmap.put("pageSize", pageBean.getPageSize());
int total=newsService.getCount(null);
System.out.println("total==="+total);
pageBean.setTotal(total);
List<News> list=newsService.getByPage(pmap);
map.put("page", pageBean);
map.put("list", list);
session.setAttribute("p", 1);
return "admin/list_news";
}
// 分页模糊查询
@RequestMapping("admin/vagueNewsList.do")
public String vagueNewsList(@RequestParam(value="page",required=false)String page,
ModelMap map,HttpSession session){
if(page==null||page.equals("")){
page="1";
}
PageBean pageBean=new PageBean(Integer.parseInt(page),PageBean.PAGESIZE);
Map<String, Object> pmap=new HashMap<String,Object>();
pmap.put("pageno", pageBean.getStart());
pmap.put("pageSize", pageBean.getPageSize());
int total=newsService.getCount(null);
pageBean.setTotal(total);
List<News> list=newsService.getByPage(pmap);
map.put("page", pageBean);
map.put("list", list);
session.setAttribute("p", 2);
return "admin/list_news";
}
@RequestMapping("admin/deleteNews.do")
public String deleteNews(int id){
newsService.delete(id);
return "redirect:newsList.do";
}
// 文件上传
public String fileUpload(@RequestParam(value="file",required=false)MultipartFile file,
HttpServletRequest request,String img){
String path=request.getSession().getServletContext().getRealPath("upload");
System.out.println("path==="+path);
System.out.println("file==="+file);
String fileName=file.getOriginalFilename();
System.out.println("fileName==="+fileName);
File targetFile=new File(path,fileName);
if(!targetFile.exists()){
targetFile.mkdirs();
}
try {
file.transferTo(targetFile);
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String pa=request.getContextPath()+"/upload/"+fileName;
System.out.println("path==="+pa);
if(fileName!=null&&!fileName.equals("")){
img=fileName;
}else{
img=null;
}
return img;
}
}
源码获取:俺的博客首页 "资源" 里下载!