基于javaweb+mysql的ssm+maven个人博客系统(java+ssm+mysql+servlet+jsp)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM+Maven个人博客系统(java+ssm+mysql+servlet+jsp)
一、项目简述
项目内容包括:首页,登陆,新建文章,搜索,登陆日志,登录次数,评论统计,相关信息,文章列表等其他相关功能
另外:系统采用MVC架构思想
二、项目运行
1.运行环境 jdk8+tomcat8+mysql+Eclispe( IntelliJ IDEA , MyEclispe ,Sts 都支持,代码与开发环境运行无关啦,只需要调整环境即可)
SpringMVC+Spring+Mybatis+JavaWeb+MySQL+Servlert+Ajax+HTML+JavaScript+CSS+Jsp等等。
@Controller
public class ArticleController {
@Autowired
ArticleServiceImpl articleService;
@Autowired
public CommentServiceImpl commentService;
@RequestMapping("/article")
public ModelAndView detail(HttpServletRequest request){
int id=Integer.parseInt(request.getParameter("id"));
List<Comment> comments=commentService.allComments(id,0,10);
Article article=articleService.selectById(id);
Article lastArticle=articleService.selectLastArticle(id);
Article nextArticle=articleService.selectNextArticle(id);
Integer clickNum=article.getClick();
article.setClick(clickNum+1);
articleService.updateArticle(article);
ModelAndView modelAndView=new ModelAndView("detail");
modelAndView.addObject("article",article);
modelAndView.addObject("comments",comments);
modelAndView.addObject("lastArticle",lastArticle);
modelAndView.addObject("nextArticle",nextArticle);
return modelAndView;
}
@RequestMapping("/admin/article/detail")
public ModelAndView adminArticleDetail(HttpServletRequest request){
int id=Integer.parseInt(request.getParameter("id"));
Article article=articleService.selectById(id);
ModelAndView modelAndView=new ModelAndView("/admin/article_detail");
modelAndView.addObject("article",article);
return modelAndView;
}
@RequestMapping("/admin/article/comment")
public ModelAndView adminArticleComment(HttpServletRequest request){
try {
Article article=new Article();
article.setTitle(request.getParameter("title"));
article.setCatalogId(Integer.parseInt(request.getParameter("catalogId")));
article.setKeywords(request.getParameter("keywords"));
article.setdesci(request.getParameter("desci"));
article.setContent(request.getParameter("content"));
article.setTime(new Date());
if (articleService.insert(article)){
redirectAttributes.addFlashAttribute("succ", "发表文章成功!");
return "redirect:/admin/article/add";
}else {
redirectAttributes.addFlashAttribute("error", "发表文章失败!");
return "redirect:/admin/article/add";
}
}
@RequestMapping(value = "/admin/article/search")
public ModelAndView articleSearch(HttpServletRequest request){
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String word=request.getParameter("word");
List<Article> articles=articleService.selectByWord(word);
ModelAndView modelAndView=new ModelAndView("/admin/article_list");
modelAndView.addObject("articles",articles);
return modelAndView;
}
@RequestMapping(value = "/admin/article/edit")
public ModelAndView articleEdit(HttpServletRequest request){
int id=Integer.parseInt(request.getParameter("id"));
Article article=articleService.selectById(id);
ModelAndView modelAndView=new ModelAndView("/admin/article_edit");
modelAndView.addObject("article",article);
return modelAndView;
}
@RequestMapping(value = "/admin/article/edit/do")
public ModelAndView articleEditDo(HttpServletRequest request){
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Article article=new Article();
article.setId(Integer.parseInt(request.getParameter("id")));
@Controller
public class LoginController {
@Autowired
AdminServiceImpl adminService;
@Autowired
AdminLoginLogServiceImpl adminLoginLogService;
@RequestMapping(value = {"/admin/index","/admin","/admin/login"})
public String toIndex(HttpServletRequest request) {
return "admin/login";
}
// 0:用户不存在 1:密码错误 2:登陆成功
@RequestMapping(value = "/api/loginCheck", method = RequestMethod.POST)
public @ResponseBody Object loginCheck(HttpServletRequest request,HttpServletResponse httpServletResponse) {
int id=Integer.parseInt(request.getParameter("id"));
String passwd = request.getParameter("password");
HashMap<String, String> res = new HashMap<String, String>();
if(adminService.getById(id)==null){
res.put("stateCode", "0");
}
else if(!adminService.getById(id).getPassword().equals(passwd)){
res.put("stateCode", "1");
}else {
String ip=request.getRemoteAddr();
AdminLoginLog adminLoginLog=new AdminLoginLog();
adminLoginLog.setAdminId(id);
adminLoginLog.setDate(new Date());
adminLoginLog.setIp(ip);
int log=adminLoginLogService.insert(adminLoginLog);
Cookie cookie = new Cookie("userId",""+id);
cookie.setMaxAge(3600*24);
httpServletResponse.addCookie(cookie);
request.getSession().setAttribute("admin",adminService.getById(id));
res.put("stateCode", "2");
}
return res;
}
@RequestMapping(value = {"/admin/logout"})
public String logout(HttpServletRequest request,HttpServletResponse response) {
request.getSession().removeAttribute("admin");
return "redirect:/admin";
@RequestMapping("/article")
public ModelAndView detail(HttpServletRequest request){
int id=Integer.parseInt(request.getParameter("id"));
List<Comment> comments=commentService.allComments(id,0,10);
Article article=articleService.selectById(id);
Article lastArticle=articleService.selectLastArticle(id);
Article nextArticle=articleService.selectNextArticle(id);
Integer clickNum=article.getClick();
article.setClick(clickNum+1);
articleService.updateArticle(article);
ModelAndView modelAndView=new ModelAndView("detail");
modelAndView.addObject("article",article);
modelAndView.addObject("comments",comments);
modelAndView.addObject("lastArticle",lastArticle);
modelAndView.addObject("nextArticle",nextArticle);
return modelAndView;
}
@RequestMapping("/admin/article/detail")
public ModelAndView adminArticleDetail(HttpServletRequest request){
int id=Integer.parseInt(request.getParameter("id"));
Article article=articleService.selectById(id);
ModelAndView modelAndView=new ModelAndView("/admin/article_detail");
modelAndView.addObject("article",article);
return modelAndView;
}
@RequestMapping("/admin/article/comment")
public ModelAndView adminArticleComment(HttpServletRequest request){
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int id=Integer.parseInt(request.getParameter("id"));
List<Comment> comments=commentService.allComments(id,0,10);
ModelAndView modelAndView=new ModelAndView("/admin/comment_list");
modelAndView.addObject("comments",comments);
return modelAndView;
}
@RequestMapping("/admin/article/list")
public ModelAndView articleList(@RequestParam(required=true,defaultValue="1") Integer page, @RequestParam(required=false,defaultValue="10") Integer pageSize){
PageHelper.startPage(page, pageSize);
List<Article> articles=articleService.queryAll();
PageInfo<Article> pageInfo=new PageInfo<Article>(articles);
modelAndView.addObject("articles",articles);
return modelAndView;
}
@RequestMapping(value = "/admin/article/edit")
public ModelAndView articleEdit(HttpServletRequest request){
int id=Integer.parseInt(request.getParameter("id"));
Article article=articleService.selectById(id);
ModelAndView modelAndView=new ModelAndView("/admin/article_edit");
modelAndView.addObject("article",article);
return modelAndView;
}
@RequestMapping(value = "/admin/article/edit/do")
public ModelAndView articleEditDo(HttpServletRequest request){
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Article article=new Article();
article.setId(Integer.parseInt(request.getParameter("id")));
article.setTitle(request.getParameter("title"));
article.setCatalogId(Integer.parseInt(request.getParameter("catalogId")));
article.setKeywords(request.getParameter("keywords"));
article.setdesci(request.getParameter("desci"));
article.setContent(request.getParameter("content"));
ModelAndView modelAndView=new ModelAndView("/admin/article_edit");
if (articleService.updateArticle(article)){
modelAndView.addObject("succ", "修改文章成功!");
}else {
modelAndView.addObject("error", "修改文章失败!");
}
return modelAndView;
}
@RequestMapping(value = "/api/article/del", method = RequestMethod.POST)
public @ResponseBody Object loginCheck(HttpServletRequest request) {
int id=Integer.parseInt(request.getParameter("id"));
int result=articleService.deleteById(id);
HashMap<String, String> res = new HashMap<String, String>();
return modelAndView;
}
@RequestMapping(value = "/admin/article/edit")
public ModelAndView articleEdit(HttpServletRequest request){
int id=Integer.parseInt(request.getParameter("id"));
Article article=articleService.selectById(id);
ModelAndView modelAndView=new ModelAndView("/admin/article_edit");
modelAndView.addObject("article",article);
return modelAndView;
}
@RequestMapping(value = "/admin/article/edit/do")
public ModelAndView articleEditDo(HttpServletRequest request){
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Article article=new Article();
article.setId(Integer.parseInt(request.getParameter("id")));
article.setTitle(request.getParameter("title"));
article.setCatalogId(Integer.parseInt(request.getParameter("catalogId")));
article.setKeywords(request.getParameter("keywords"));
article.setdesci(request.getParameter("desci"));
article.setContent(request.getParameter("content"));
ModelAndView modelAndView=new ModelAndView("/admin/article_edit");
if (articleService.updateArticle(article)){
modelAndView.addObject("succ", "修改文章成功!");
}else {
modelAndView.addObject("error", "修改文章失败!");
}
return modelAndView;
}
@RequestMapping(value = "/api/article/del", method = RequestMethod.POST)
public @ResponseBody Object loginCheck(HttpServletRequest request) {
int id=Integer.parseInt(request.getParameter("id"));
int result=articleService.deleteById(id);
HashMap<String, String> res = new HashMap<String, String>();
if (result==1){
res.put("stateCode", "1");
}else {
res.put("stateCode", "0");
}
return res;
}
}
e.printStackTrace();
}
Article article=new Article();
article.setTitle(request.getParameter("title"));
article.setCatalogId(Integer.parseInt(request.getParameter("catalogId")));
article.setKeywords(request.getParameter("keywords"));
article.setdesci(request.getParameter("desci"));
article.setContent(request.getParameter("content"));
article.setTime(new Date());
if (articleService.insert(article)){
redirectAttributes.addFlashAttribute("succ", "发表文章成功!");
return "redirect:/admin/article/add";
}else {
redirectAttributes.addFlashAttribute("error", "发表文章失败!");
return "redirect:/admin/article/add";
}
}
@RequestMapping(value = "/admin/article/search")
public ModelAndView articleSearch(HttpServletRequest request){
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String word=request.getParameter("word");
List<Article> articles=articleService.selectByWord(word);
ModelAndView modelAndView=new ModelAndView("/admin/article_list");
modelAndView.addObject("articles",articles);
return modelAndView;
}
@RequestMapping(value = "/admin/article/edit")
public ModelAndView articleEdit(HttpServletRequest request){
int id=Integer.parseInt(request.getParameter("id"));
Article article=articleService.selectById(id);
ModelAndView modelAndView=new ModelAndView("/admin/article_edit");
modelAndView.addObject("article",article);
return modelAndView;
}
@RequestMapping(value = "/admin/article/edit/do")
public ModelAndView articleEditDo(HttpServletRequest request){
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
@Controller
public class LoginController {
@Autowired
AdminServiceImpl adminService;
@Autowired
AdminLoginLogServiceImpl adminLoginLogService;
@RequestMapping(value = {"/admin/index","/admin","/admin/login"})
public String toIndex(HttpServletRequest request) {
return "admin/login";
}
// 0:用户不存在 1:密码错误 2:登陆成功
@RequestMapping(value = "/api/loginCheck", method = RequestMethod.POST)
public @ResponseBody Object loginCheck(HttpServletRequest request,HttpServletResponse httpServletResponse) {
int id=Integer.parseInt(request.getParameter("id"));
String passwd = request.getParameter("password");
HashMap<String, String> res = new HashMap<String, String>();
if(adminService.getById(id)==null){
res.put("stateCode", "0");
}
else if(!adminService.getById(id).getPassword().equals(passwd)){
res.put("stateCode", "1");
}else {
String ip=request.getRemoteAddr();
AdminLoginLog adminLoginLog=new AdminLoginLog();
adminLoginLog.setAdminId(id);
adminLoginLog.setDate(new Date());
adminLoginLog.setIp(ip);
int log=adminLoginLogService.insert(adminLoginLog);
Cookie cookie = new Cookie("userId",""+id);
cookie.setMaxAge(3600*24);
httpServletResponse.addCookie(cookie);
request.getSession().setAttribute("admin",adminService.getById(id));
res.put("stateCode", "2");
}
return res;
}
@RequestMapping(value = {"/admin/logout"})
public String logout(HttpServletRequest request,HttpServletResponse response) {
request.getSession().removeAttribute("admin");
return "redirect:/admin";
@Controller
public class ArticleController {
@Autowired
ArticleServiceImpl articleService;
@Autowired
public CommentServiceImpl commentService;
@RequestMapping("/article")
public ModelAndView detail(HttpServletRequest request){
int id=Integer.parseInt(request.getParameter("id"));
List<Comment> comments=commentService.allComments(id,0,10);
Article article=articleService.selectById(id);
Article lastArticle=articleService.selectLastArticle(id);
Article nextArticle=articleService.selectNextArticle(id);
Integer clickNum=article.getClick();
article.setClick(clickNum+1);
articleService.updateArticle(article);
ModelAndView modelAndView=new ModelAndView("detail");
modelAndView.addObject("article",article);
modelAndView.addObject("comments",comments);
modelAndView.addObject("lastArticle",lastArticle);
modelAndView.addObject("nextArticle",nextArticle);
return modelAndView;
}
@RequestMapping("/admin/article/detail")
public ModelAndView adminArticleDetail(HttpServletRequest request){
int id=Integer.parseInt(request.getParameter("id"));
Article article=articleService.selectById(id);
ModelAndView modelAndView=new ModelAndView("/admin/article_detail");
modelAndView.addObject("article",article);
return modelAndView;
}
@RequestMapping("/admin/article/comment")
@Controller
public class CommentController {
@Autowired
public CommentServiceImpl commentService;
@RequestMapping(value = "/api/comment/add", method = RequestMethod.POST)
public @ResponseBody Object commentAdd(HttpServletRequest request) {
Comment comment=new Comment();
comment.setArticleId(Long.parseLong(request.getParameter("articleId")));
comment.setContent(request.getParameter("content"));
comment.setDate(new Date());
comment.setName(request.getParameter("name"));
comment.setEmail(request.getParameter("email"));
HashMap<String, String> res = new HashMap<String, String>();
if(commentService.insertComment(comment)>0){
res.put("stateCode", "1");
}else {
res.put("stateCode", "0");
}
return res;
}
@RequestMapping(value = "/api/comment/del", method = RequestMethod.POST)
public @ResponseBody Object commentDel(HttpServletRequest request) {
long id=Long.parseLong(request.getParameter("id"));
HashMap<String, String> res = new HashMap<String, String>();
if (commentService.delById(id)){
res.put("stateCode", "1");
}else {
res.put("stateCode", "0");
}
@Repository
@RequestMapping("/admin")
public class AdminController {
@Autowired
public AdminLoginLogServiceImpl adminLoginLogService;
@Autowired
public ArticleServiceImpl articleService;
@Autowired
public CommentServiceImpl commentService;
@RequestMapping("/main")
public ModelAndView toMain(HttpServletRequest request){
ModelAndView modelAndView=new ModelAndView("admin/main");
String clientIp=request.getRemoteAddr(); //获取客户端IP,如:127.0.0.1
String hostIp=request.getLocalAddr();
int hostPort=request.getLocalPort();
Date date = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm");//设置日期格式
String dates = df.format(date);
Admin admin=(Admin) request.getSession().getAttribute("admin");
AdminLoginLog lastLoginLog=null;
try {
if (adminLoginLogService.selectRencent(admin.getId())!=null && adminLoginLogService.selectRencent(admin.getId()).size()==2){
List<AdminLoginLog> adminLoginLogs=adminLoginLogService.selectRencent(admin.getId());
lastLoginLog=adminLoginLogs.get(1);
}
}catch (Exception e){
e.printStackTrace();
}finally {
int articleCount=articleService.selectCount();
int commentCount=commentService.countAllNum();
int loginNum=adminLoginLogService.selectCountByAdminId(admin.getId());
modelAndView.addObject("clientIp",clientIp);
modelAndView.addObject("hostIp",hostIp);
modelAndView.addObject("hostPort",hostPort);
modelAndView.addObject("date",dates);
if (lastLoginLog!=null){
modelAndView.addObject("loginLog",lastLoginLog);
}
modelAndView.addObject("articleCount",articleCount);
modelAndView.addObject("commentCount",commentCount);
modelAndView.addObject("loginNum",loginNum);
return modelAndView;
}
}
}
ModelAndView modelAndView=new ModelAndView("/admin/article_edit");
modelAndView.addObject("article",article);
return modelAndView;
}
@RequestMapping(value = "/admin/article/edit/do")
public ModelAndView articleEditDo(HttpServletRequest request){
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Article article=new Article();
article.setId(Integer.parseInt(request.getParameter("id")));
article.setTitle(request.getParameter("title"));
article.setCatalogId(Integer.parseInt(request.getParameter("catalogId")));
article.setKeywords(request.getParameter("keywords"));
article.setdesci(request.getParameter("desci"));
article.setContent(request.getParameter("content"));
ModelAndView modelAndView=new ModelAndView("/admin/article_edit");
if (articleService.updateArticle(article)){
modelAndView.addObject("succ", "修改文章成功!");
}else {
modelAndView.addObject("error", "修改文章失败!");
}
return modelAndView;
}
@RequestMapping(value = "/api/article/del", method = RequestMethod.POST)
public @ResponseBody Object loginCheck(HttpServletRequest request) {
int id=Integer.parseInt(request.getParameter("id"));
int result=articleService.deleteById(id);
HashMap<String, String> res = new HashMap<String, String>();
if (result==1){
res.put("stateCode", "1");
}else {
res.put("stateCode", "0");
}
return res;
}
}
List<Comment> comments=commentService.allComments(id,0,10);
ModelAndView modelAndView=new ModelAndView("/admin/comment_list");
modelAndView.addObject("comments",comments);
return modelAndView;
}
@RequestMapping("/admin/article/list")
public ModelAndView articleList(@RequestParam(required=true,defaultValue="1") Integer page, @RequestParam(required=false,defaultValue="10") Integer pageSize){
PageHelper.startPage(page, pageSize);
List<Article> articles=articleService.queryAll();
PageInfo<Article> pageInfo=new PageInfo<Article>(articles);
ModelAndView modelAndView=new ModelAndView("/admin/article_list");
modelAndView.addObject("articles",articles);
modelAndView.addObject("pageInfo",pageInfo);
return modelAndView;
}
@RequestMapping("/admin/article/add")
public ModelAndView articleAdd(){
ModelAndView modelAndView=new ModelAndView("/admin/article_add");
return modelAndView;
}
@RequestMapping("/admin/article/add/do")
public String articleAddDo(HttpServletRequest request,RedirectAttributes redirectAttributes){
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Article article=new Article();
article.setTitle(request.getParameter("title"));
article.setCatalogId(Integer.parseInt(request.getParameter("catalogId")));
article.setKeywords(request.getParameter("keywords"));
article.setdesci(request.getParameter("desci"));
article.setContent(request.getParameter("content"));
article.setTime(new Date());
if (articleService.insert(article)){
redirectAttributes.addFlashAttribute("succ", "发表文章成功!");
return "redirect:/admin/article/add";
}else {
redirectAttributes.addFlashAttribute("error", "发表文章失败!");
comment.setDate(new Date());
comment.setName(request.getParameter("name"));
comment.setEmail(request.getParameter("email"));
HashMap<String, String> res = new HashMap<String, String>();
if(commentService.insertComment(comment)>0){
res.put("stateCode", "1");
}else {
res.put("stateCode", "0");
}
return res;
}
@RequestMapping(value = "/api/comment/del", method = RequestMethod.POST)
public @ResponseBody Object commentDel(HttpServletRequest request) {
long id=Long.parseLong(request.getParameter("id"));
HashMap<String, String> res = new HashMap<String, String>();
if (commentService.delById(id)){
res.put("stateCode", "1");
}else {
res.put("stateCode", "0");
}
return res;
}
}
@Controller
public class LoginController {
@Autowired
AdminServiceImpl adminService;
@Autowired
AdminLoginLogServiceImpl adminLoginLogService;
@RequestMapping(value = {"/admin/index","/admin","/admin/login"})
public String toIndex(HttpServletRequest request) {
return "admin/login";
}
// 0:用户不存在 1:密码错误 2:登陆成功
@RequestMapping(value = "/api/loginCheck", method = RequestMethod.POST)
public @ResponseBody Object loginCheck(HttpServletRequest request,HttpServletResponse httpServletResponse) {
int id=Integer.parseInt(request.getParameter("id"));
String passwd = request.getParameter("password");
HashMap<String, String> res = new HashMap<String, String>();
if(adminService.getById(id)==null){
res.put("stateCode", "0");
}
else if(!adminService.getById(id).getPassword().equals(passwd)){
res.put("stateCode", "1");
}else {
String ip=request.getRemoteAddr();
AdminLoginLog adminLoginLog=new AdminLoginLog();
adminLoginLog.setAdminId(id);
adminLoginLog.setDate(new Date());
adminLoginLog.setIp(ip);
int log=adminLoginLogService.insert(adminLoginLog);
Cookie cookie = new Cookie("userId",""+id);
}
@RequestMapping("/admin/article/comment")
public ModelAndView adminArticleComment(HttpServletRequest request){
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int id=Integer.parseInt(request.getParameter("id"));
List<Comment> comments=commentService.allComments(id,0,10);
ModelAndView modelAndView=new ModelAndView("/admin/comment_list");
modelAndView.addObject("comments",comments);
return modelAndView;
}
@RequestMapping("/admin/article/list")
public ModelAndView articleList(@RequestParam(required=true,defaultValue="1") Integer page, @RequestParam(required=false,defaultValue="10") Integer pageSize){
PageHelper.startPage(page, pageSize);
List<Article> articles=articleService.queryAll();
PageInfo<Article> pageInfo=new PageInfo<Article>(articles);
ModelAndView modelAndView=new ModelAndView("/admin/article_list");
modelAndView.addObject("articles",articles);
modelAndView.addObject("pageInfo",pageInfo);
return modelAndView;
}
@RequestMapping("/admin/article/add")
public ModelAndView articleAdd(){
ModelAndView modelAndView=new ModelAndView("/admin/article_add");
return modelAndView;
}
@RequestMapping("/admin/article/add/do")
public String articleAddDo(HttpServletRequest request,RedirectAttributes redirectAttributes){
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Article article=new Article();
article.setTitle(request.getParameter("title"));
article.setCatalogId(Integer.parseInt(request.getParameter("catalogId")));
article.setKeywords(request.getParameter("keywords"));
article.setdesci(request.getParameter("desci"));
article.setContent(request.getParameter("content"));
public ModelAndView articleEditDo(HttpServletRequest request){
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Article article=new Article();
article.setId(Integer.parseInt(request.getParameter("id")));
article.setTitle(request.getParameter("title"));
article.setCatalogId(Integer.parseInt(request.getParameter("catalogId")));
article.setKeywords(request.getParameter("keywords"));
article.setdesci(request.getParameter("desci"));
article.setContent(request.getParameter("content"));
ModelAndView modelAndView=new ModelAndView("/admin/article_edit");
if (articleService.updateArticle(article)){
modelAndView.addObject("succ", "修改文章成功!");
}else {
modelAndView.addObject("error", "修改文章失败!");
}
return modelAndView;
}
@RequestMapping(value = "/api/article/del", method = RequestMethod.POST)
public @ResponseBody Object loginCheck(HttpServletRequest request) {
int id=Integer.parseInt(request.getParameter("id"));
int result=articleService.deleteById(id);
HashMap<String, String> res = new HashMap<String, String>();
if (result==1){
res.put("stateCode", "1");
}else {
res.put("stateCode", "0");
}
return res;
}
}
return res;
}
}
@Repository
@RequestMapping("/admin")
public class AdminController {
@Autowired
public AdminLoginLogServiceImpl adminLoginLogService;
@Autowired
public ArticleServiceImpl articleService;
@Autowired
public CommentServiceImpl commentService;
@RequestMapping("/main")
public ModelAndView toMain(HttpServletRequest request){
ModelAndView modelAndView=new ModelAndView("admin/main");
String clientIp=request.getRemoteAddr(); //获取客户端IP,如:127.0.0.1
String hostIp=request.getLocalAddr();
int hostPort=request.getLocalPort();
Date date = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm");//设置日期格式
String dates = df.format(date);
Admin admin=(Admin) request.getSession().getAttribute("admin");
AdminLoginLog lastLoginLog=null;
try {
if (adminLoginLogService.selectRencent(admin.getId())!=null && adminLoginLogService.selectRencent(admin.getId()).size()==2){
List<AdminLoginLog> adminLoginLogs=adminLoginLogService.selectRencent(admin.getId());
lastLoginLog=adminLoginLogs.get(1);
}
}catch (Exception e){
e.printStackTrace();
}finally {
int articleCount=articleService.selectCount();