基于javaweb+mysql的ssm流浪动物收养系统(java+ssm+jsp+jquery+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM流浪动物收养系统(java+ssm+jsp+jquery+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.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 5.7/8.0等版本均可;
技术栈
-
后端:Spring+springmvc+mybatis
-
前端:JSP+css+javascript+jQuery
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应sql文件名称的数据库,并导入项目的sql文件;
2.使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat
-
将项目中springmvc-servlet.xml配置文件中的数据库配置改为自己的配置;
-
运行项目,在浏览器中输入http://localhost:8080/ 登录
用户账号/密码: user/123456
管理员账号/密码:admin/admin
this.front();
List<Article> articleList = new ArrayList<Article>();
List<Article> tempList = this.articleService.getAllArticle();
int pageNumber = tempList.size();
int maxPage = pageNumber;
if (maxPage % 12 == 0) {
maxPage = maxPage / 12;
} else {
maxPage = maxPage / 12 + 1;
}
if (number == null) {
number = "0";
}
int start = Integer.parseInt(number) * 12;
int over = (Integer.parseInt(number) + 1) * 12;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
for (int i = start; i < over; i++) {
Article x = tempList.get(i);
articleList.add(x);
}
String html = "";
StringBuffer buffer = new StringBuffer();
buffer.append(" 共为");
buffer.append(maxPage);
buffer.append("页 共有");
buffer.append(pageNumber);
buffer.append("条 当前为第");
buffer.append((Integer.parseInt(number) + 1));
buffer.append("页 ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("首页");
} else {
buffer.append("<a href=\"index/article.action?number=0\">首页</a>");
}
buffer.append(" ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("上一页");
} else {
buffer.append("<a href=\"index/article.action?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
}
String userid = (String) this.getSession().getAttribute("userid");
Orders orders = new Orders();
orders.setUsersid(userid);
List<Orders> ordersList = new ArrayList<Orders>();
List<Orders> tempList = this.ordersService.getOrdersByCond(orders);
int pageNumber = tempList.size();
int maxPage = pageNumber;
if (maxPage % 12 == 0) {
maxPage = maxPage / 12;
} else {
maxPage = maxPage / 12 + 1;
}
if (number == null) {
number = "0";
}
int start = Integer.parseInt(number) * 12;
int over = (Integer.parseInt(number) + 1) * 12;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
for (int i = start; i < over; i++) {
Orders o = tempList.get(i);
ordersList.add(o);
}
String html = "";
StringBuffer buffer = new StringBuffer();
buffer.append(" 共为");
buffer.append(maxPage);
buffer.append("页 共有");
buffer.append(pageNumber);
buffer.append("条 当前为第");
buffer.append((Integer.parseInt(number) + 1));
buffer.append("页 ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("首页");
} else {
buffer.append("<a href=\"index/showOrders.action?number=0\">首页</a>");
}
buffer.append(" ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("上一页");
} else {
buffer.append("<a href=\"index/showOrders.action?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
}
// 添加数据
@RequestMapping("addArticle.action")
public String addArticle(Article article) {
article.setAddtime(VeDate.getStringDateShort());
article.setHits("0");
this.articleService.insertArticle(article);
return "redirect:/article/createArticle.action";
}
// 通过主键删除数据
@RequestMapping("deleteArticle.action")
public String deleteArticle(String id) {
this.articleService.deleteArticle(id);
return "redirect:/article/getAllArticle.action";
}
// 批量删除数据
@RequestMapping("deleteArticleByIds.action")
public String deleteArticleByIds() {
String[] ids = this.getRequest().getParameterValues("articleid");
for (String articleid : ids) {
this.articleService.deleteArticle(articleid);
}
return "redirect:/article/getAllArticle.action";
}
// 更新数据
@RequestMapping("updateArticle.action")
public String updateArticle(Article article) {
this.articleService.updateArticle(article);
return "redirect:/article/getAllArticle.action";
}
// 显示全部数据
@RequestMapping("getAllArticle.action")
public String getAllArticle(String number) {
List<Article> articleList = this.articleService.getAllArticle();
PageHelper.getPage(articleList, "article", null, null, 10, number, this.getRequest(), null);
return "admin/listarticle";
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.adminService.getAdminByLike(admin), "admin", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/queryadmin";
}
// 按主键查询数据
@RequestMapping("getAdminById.action")
public String getAdminById(String id) {
Admin admin = this.adminService.getAdminById(id);
this.getRequest().setAttribute("admin", admin);
return "admin/editadmin";
}
public AdminService getAdminService() {
return adminService;
}
public void setAdminService(AdminService adminService) {
this.adminService = adminService;
}
}
public HttpServletRequest getRequest() {
ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
return attrs.getRequest();
}
public HttpSession getSession() {
HttpSession session = null;
try {
session = this.getRequest().getSession();
} catch (Exception e) {
}
return session;
}
/* 向客户端输出操作成功或失败信息 */
public void writeJsonResponse(String success) throws IOException, JSONException {
ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletResponse response = attrs.getResponse();
response.setContentType("text/json;charset=UTF-8");
PrintWriter out = response.getWriter();
// 将要被返回到客户端的对象
JSONObject json = new JSONObject();
json.accumulate("result", success);
System.out.println(json.toString());
out.println(json.toString());
out.flush();
out.close();
}
}
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/ajax", produces = "text/plain;charset=utf-8")
public class AjaxAction extends BaseAction {
@Autowired
// 公告
@RequestMapping("article.action")
public String article(String number) {
this.front();
List<Article> articleList = new ArrayList<Article>();
List<Article> tempList = this.articleService.getAllArticle();
int pageNumber = tempList.size();
int maxPage = pageNumber;
if (maxPage % 12 == 0) {
maxPage = maxPage / 12;
} else {
maxPage = maxPage / 12 + 1;
}
if (number == null) {
number = "0";
}
int start = Integer.parseInt(number) * 12;
int over = (Integer.parseInt(number) + 1) * 12;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
for (int i = start; i < over; i++) {
Article x = tempList.get(i);
articleList.add(x);
}
String html = "";
StringBuffer buffer = new StringBuffer();
buffer.append(" 共为");
buffer.append(maxPage);
buffer.append("页 共有");
buffer.append(pageNumber);
buffer.append("条 当前为第");
buffer.append((Integer.parseInt(number) + 1));
buffer.append("页 ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("首页");
} else {
buffer.append("<a href=\"index/article.action?number=0\">首页</a>");
}
buffer.append(" ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("上一页");
} else {
buffer.append("<a href=\"index/article.action?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
buffer.append("页 ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("首页");
} else {
buffer.append("<a href=\"index/all.action?number=0\">首页</a>");
}
buffer.append(" ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("上一页");
} else {
buffer.append("<a href=\"index/all.action?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("下一页");
} else {
buffer.append("<a href=\"index/all.action?number=" + (Integer.parseInt(number) + 1) + "\">下一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("尾页");
} else {
buffer.append("<a href=\"index/all.action?number=" + (maxPage - 1) + "\">尾页</a>");
}
html = buffer.toString();
this.getRequest().setAttribute("html", html);
this.getRequest().setAttribute("flimList", flimList);
return "users/list";
}
// 查询演唱会
@RequestMapping("query.action")
public String query(String name) {
this.front();
Jiancai goods = new Jiancai();
goods.setJiancainame(name);
List<Jiancai> flimList = this.jiancaiService.getJiancaiByLike(goods);
this.getRequest().setAttribute("flimList", flimList);
return "users/list";
}
// 演唱会详情
return "users/editpwd";
}
// 修改密码
@RequestMapping("editpwd.action")
public String editpwd() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
String password = this.getRequest().getParameter("password");
String repassword = this.getRequest().getParameter("repassword");
Users users = this.usersService.getUsersById(userid);
if (password.equals(users.getPassword())) {
users.setPassword(repassword);
this.usersService.updateUsers(users);
} else {
this.getSession().setAttribute("message", "旧密码错误");
return "redirect:/index/prePwd.action";
}
return "redirect:/index/prePwd.action";
}
@RequestMapping("usercenter.action")
public String usercenter() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
return "users/usercenter";
}
@RequestMapping("userinfo.action")
public String userinfo() {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
String userid = (String) this.getSession().getAttribute("userid");
this.getSession().setAttribute("users", this.usersService.getUsersById(userid));
return "users/userinfo";
}
@RequestMapping("personal.action")
public String personal(Users users) {
this.front();
if (this.getSession().getAttribute("userid") == null) {
return "redirect:/index/preLogin.action";
}
this.getRequest().setAttribute("cityList", cityList);
List<Peihuo> peihuoList = this.peihuoService.getAllPeihuo();
this.getRequest().setAttribute("peihuoList", peihuoList);
return "admin/editdetails";
}
public DetailsService getDetailsService() {
return detailsService;
}
public void setDetailsService(DetailsService detailsService) {
this.detailsService = detailsService;
}
}
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/jiancai", produces = "text/plain;charset=utf-8")
public class JiancaiAction extends BaseAction {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private JiancaiService jiancaiService;
@Autowired
@Resource
private CateService cateService;
// 准备添加数据
@RequestMapping("createJiancai.action")
public String createJiancai() {
List<Cate> cateList = this.cateService.getAllCate();
this.getRequest().setAttribute("cateList", cateList);
return "admin/addjiancai";
}
// 添加数据
@RequestMapping("addJiancai.action")
public String addJiancai(Jiancai jiancai) {
@RequestMapping("network.action")
public String network() {
this.front();
List<Cate> cateList = this.cateService.getCateFront();
List<Cate> frontList = new ArrayList<Cate>();
for (Cate cate : cateList) {
List<Jiancai> flimList = this.jiancaiService.getJiancaiByCate(cate.getCateid());
cate.setFlimList(flimList);
frontList.add(cate);
}
this.getRequest().setAttribute("frontList", frontList);
return "users/network";
}
// 公告
@RequestMapping("article.action")
public String article(String number) {
this.front();
List<Article> articleList = new ArrayList<Article>();
List<Article> tempList = this.articleService.getAllArticle();
int pageNumber = tempList.size();
int maxPage = pageNumber;
if (maxPage % 12 == 0) {
maxPage = maxPage / 12;
} else {
maxPage = maxPage / 12 + 1;
}
if (number == null) {
number = "0";
}
int start = Integer.parseInt(number) * 12;
int over = (Integer.parseInt(number) + 1) * 12;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
for (int i = start; i < over; i++) {
Article x = tempList.get(i);
articleList.add(x);
}
String html = "";
StringBuffer buffer = new StringBuffer();
buffer.append(" 共为");
buffer.append(maxPage);
buffer.append("页 共有");
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.peihuoService.getPeihuoByLike(peihuo), "peihuo", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/querypeihuo";
}
// 按主键查询数据
@RequestMapping("getPeihuoById.action")
public String getPeihuoById(String id) {
Peihuo peihuo = this.peihuoService.getPeihuoById(id);
this.getRequest().setAttribute("peihuo", peihuo);
List<City> cityList = this.cityService.getAllCity();
this.getRequest().setAttribute("cityList", cityList);
return "admin/editpeihuo";
}
public PeihuoService getPeihuoService() {
return peihuoService;
}
public void setPeihuoService(PeihuoService peihuoService) {
this.peihuoService = peihuoService;
}
}
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("首页");
} else {
buffer.append("<a href=\"index/recommend.action?number=0\">首页</a>");
}
buffer.append(" ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("上一页");
} else {
buffer.append("<a href=\"index/recommend.action?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("下一页");
} else {
buffer.append("<a href=\"index/recommend.action?number=" + (Integer.parseInt(number) + 1) + "\">下一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("尾页");
} else {
buffer.append("<a href=\"index/recommend.action?number=" + (maxPage - 1) + "\">尾页</a>");
}
html = buffer.toString();
this.getRequest().setAttribute("html", html);
this.getRequest().setAttribute("flimList", flimList);
return "users/list";
}
// 推荐产品
@RequestMapping("hot.action")
public String getHost(String number) {
this.front();
Jiancai goods = new Jiancai();
goods.setRecommend("是");
List<Jiancai> flimList = new ArrayList<Jiancai>();
List<Jiancai> tempList = this.jiancaiService.getJiancaiByHot();
int pageNumber = tempList.size();
int maxPage = pageNumber;
if (maxPage % 12 == 0) {
maxPage = maxPage / 12;
} else {
maxPage = maxPage / 12 + 1;
}
if (number == null) {
String html = "";
StringBuffer buffer = new StringBuffer();
buffer.append(" 共为");
buffer.append(maxPage);
buffer.append("页 共有");
buffer.append(pageNumber);
buffer.append("条 当前为第");
buffer.append((Integer.parseInt(number) + 1));
buffer.append("页 ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("首页");
} else {
buffer.append("<a href=\"index/hot.action?number=0\">首页</a>");
}
buffer.append(" ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("上一页");
} else {
buffer.append("<a href=\"index/hot.action?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("下一页");
} else {
buffer.append("<a href=\"index/hot.action?number=" + (Integer.parseInt(number) + 1) + "\">下一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("尾页");
} else {
buffer.append("<a href=\"index/hot.action?number=" + (maxPage - 1) + "\">尾页</a>");
}
html = buffer.toString();
this.getRequest().setAttribute("html", html);
this.getRequest().setAttribute("flimList", flimList);
return "users/list";
}
// 全部产品
@RequestMapping("all.action")
public String all(String number) {
this.front();
List<Jiancai> flimList = new ArrayList<Jiancai>();
List<Jiancai> tempList = this.jiancaiService.getAllJiancai();
peihuo.setAddress(name);
}
if ("contact".equals(cond)) {
peihuo.setContact(name);
}
if ("memo".equals(cond)) {
peihuo.setMemo(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.peihuoService.getPeihuoByLike(peihuo), "peihuo", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/querypeihuo";
}
// 按主键查询数据
@RequestMapping("getPeihuoById.action")
public String getPeihuoById(String id) {
Peihuo peihuo = this.peihuoService.getPeihuoById(id);
this.getRequest().setAttribute("peihuo", peihuo);
List<City> cityList = this.cityService.getAllCity();
this.getRequest().setAttribute("cityList", cityList);
return "admin/editpeihuo";
}
public PeihuoService getPeihuoService() {
return peihuoService;
}
public void setPeihuoService(PeihuoService peihuoService) {
this.peihuoService = peihuoService;
}
}
}
int start = Integer.parseInt(number) * 12;
int over = (Integer.parseInt(number) + 1) * 12;
int count = pageNumber - over;
if (count <= 0) {
over = pageNumber;
}
for (int i = start; i < over; i++) {
Jiancai x = tempList.get(i);
flimList.add(x);
}
String html = "";
StringBuffer buffer = new StringBuffer();
buffer.append(" 共为");
buffer.append(maxPage);
buffer.append("页 共有");
buffer.append(pageNumber);
buffer.append("条 当前为第");
buffer.append((Integer.parseInt(number) + 1));
buffer.append("页 ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("首页");
} else {
buffer.append("<a href=\"index/all.action?number=0\">首页</a>");
}
buffer.append(" ");
if ((Integer.parseInt(number) + 1) == 1) {
buffer.append("上一页");
} else {
buffer.append("<a href=\"index/all.action?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("下一页");
} else {
buffer.append("<a href=\"index/all.action?number=" + (Integer.parseInt(number) + 1) + "\">下一页</a>");
}
buffer.append(" ");
if (maxPage <= (Integer.parseInt(number) + 1)) {
buffer.append("尾页");
} else {
// 准备添加数据
@RequestMapping("createUsers.action")
public String createUsers() {
return "admin/addusers";
}
// 添加数据
@RequestMapping("addUsers.action")
public String addUsers(Users users) {
users.setRegdate(VeDate.getStringDateShort());
this.usersService.insertUsers(users);
return "redirect:/users/createUsers.action";
}
// 通过主键删除数据
@RequestMapping("deleteUsers.action")
public String deleteUsers(String id) {
this.usersService.deleteUsers(id);
return "redirect:/users/getAllUsers.action";
}
// 批量删除数据
@RequestMapping("deleteUsersByIds.action")
public String deleteUsersByIds() {
String[] ids = this.getRequest().getParameterValues("usersid");
for (String usersid : ids) {
this.usersService.deleteUsers(usersid);
}
return "redirect:/users/getAllUsers.action";
}
// 更新数据
@RequestMapping("updateUsers.action")
public String updateUsers(Users users) {
this.usersService.updateUsers(users);
return "redirect:/users/getAllUsers.action";
}
// 显示全部数据
@RequestMapping("getAllUsers.action")
public String getAllUsers(String number) {
List<Users> usersList = this.usersService.getAllUsers();
PageHelper.getPage(usersList, "users", null, null, 10, number, this.getRequest(), null);
return "admin/listusers";
}
// 按条件查询数据 (模糊查询)
@RequestMapping("queryUsersByCond.action")
public String queryUsersByCond(String cond, String name, String number) {
Users users = new Users();
if(cond != null){
if ("username".equals(cond)) {
users.setUsername(name);
}
if ("password".equals(cond)) {
users.setPassword(name);
// 按条件查询数据 (模糊查询)
@RequestMapping("queryCartByCond.action")
public String queryCartByCond(String cond, String name, String number) {
Cart cart = new Cart();
if (cond != null) {
if ("username".equals(cond)) {
cart.setUsername(name);
}
if ("jiancainame".equals(cond)) {
cart.setJiancainame(name);
}
if ("num".equals(cond)) {
cart.setNum(name);
}
if ("price".equals(cond)) {
cart.setPrice(name);
}
}
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.cartService.getCartByLike(cart), "cart", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/querycart";
}
// 按主键查询数据
@RequestMapping("getCartById.action")
public String getCartById(String id) {
Cart cart = this.cartService.getCartById(id);
this.getRequest().setAttribute("cart", cart);
List<Users> usersList = this.usersService.getAllUsers();
this.getRequest().setAttribute("usersList", usersList);
List<Jiancai> jiancaiList = this.jiancaiService.getAllJiancai();
this.getRequest().setAttribute("jiancaiList", jiancaiList);
return "admin/editcart";
}
public CartService getCartService() {
List<String> nameList = new ArrayList<String>();
List<String> valueList = new ArrayList<String>();
nameList.add(cond);
valueList.add(name);
PageHelper.getPage(this.peihuoService.getPeihuoByLike(peihuo), "peihuo", nameList, valueList, 10, number, this.getRequest(), "query");
name = null;
cond = null;
return "admin/querypeihuo";
}
// 按主键查询数据
@RequestMapping("getPeihuoById.action")
public String getPeihuoById(String id) {
Peihuo peihuo = this.peihuoService.getPeihuoById(id);
this.getRequest().setAttribute("peihuo", peihuo);
List<City> cityList = this.cityService.getAllCity();
this.getRequest().setAttribute("cityList", cityList);
return "admin/editpeihuo";
}
public PeihuoService getPeihuoService() {
return peihuoService;
}
public void setPeihuoService(PeihuoService peihuoService) {
this.peihuoService = peihuoService;
}
}