重置
后台:
packagecom.sl.controller;
importcom.sl.model.NewsDetail;
importcom.sl.service.NewsDetailService;
importcom.sl.util.DateUtil;
importorg.codehaus.jackson.map.ObjectMapper;
importorg.springframework.beans.factory.annotation.Autowired;
importorg.springframework.stereotype.Controller;
importorg.springframework.ui.Model;
importorg.springframework.web.bind.annotation.*;
importjavax.servlet.http.HttpSession;
importjava.io.IOException;
importjava.time.format.DateTimeFormatter;
importjava.util.Date;
importjava.util.HashMap;
importjava.util.List;
importjava.util.Map;
@Controller
@RequestMapping("/news")
publicclassNewsDetailController{
/*注入NewsDetailService*/
/**
*
*/
@Autowired
privateNewsDetailServicenewsDetailService;
@RequestMapping("/main")
@ResponseBody
privateMapqueryAll(){
Mapmap=newHashMap<>();
Listlist=newsDetailService.queryAll();
intcount=newsDetailService.queryAllCount();
map.put("data",list);
map.put("code",0);
map.put("count",count);
returnmap;
}
@RequestMapping(value="/delete",method=RequestMethod.POST,produces="application/json")
@ResponseBody
privateMapdeleteById(@RequestBodyHashMapmap2){
Mapmap=newHashMap<>();
intid=Integer.parseInt(map2.get("id"));
introw=newsDetailService.deleteById(id);
if(row==1){
Listlist=newsDetailService.queryAll();
intcount=newsDetailService.queryAllCount();
map.put("data",list);
map.put("returnCode","200");
map.put("count",count);
map.put("code",0);
returnmap;
}else{
map.put("code",1);
returnmap;
}
}
@RequestMapping(value="/mulDelete",method=RequestMethod.POST,produces="application/json")
@ResponseBody
publicMapmulDelete(@RequestBodyHashMapmap2){
Mapmap=newHashMap<>();
Stringids=map2.get("ids");
Stringmulid[]=ids.split(",");
introw=0;
for(inti=0;ilist=newsDetailService.queryAll();
intcount=newsDetailService.queryAllCount();
map.put("code",0);
map.put("data",list);
map.put("count",count);
map.put("returnCode","200");
returnmap;
}else{
map.put("code",-1);
returnmap;
}
}
@RequestMapping(value="/update",method=RequestMethod.POST,produces="application/json")
@ResponseBody
publicMapupdateById(@RequestBodyHashMapmap2)throwsIOException{
Mapmap=newHashMap<>();
intid=Integer.parseInt(map2.get("id"));
Stringtitle=map2.get("newtitle");
Stringsummary=map2.get("newsummary");
Stringauthor=map2.get("newauthor");
/*System.out.println(id+""+title+""+summary+""+author);
System.out.println(1);
System.out.println(newDate());
System.out.println(DateUtil.getCurrentDateString());
System.out.println(2);*/
NewsDetailnewsDetail=newNewsDetail();
newsDetail.setId(id);
newsDetail.setTitle(title);
newsDetail.setSummary(summary);
newsDetail.setAuthor(author);
newsDetail.setCreateDate(DateUtil.formatDate(newDate(),"yyyy-MM-ddHH-mm-ss"));
/*System.out.println(newsDetail.getCreateDate());
System.out.println(DateUtil.formatDate(newDate(),"yyyy-MM-ddHH-mm-ss"));*/
introw=newsDetailService.updateById(newsDetail);
if(row==1){
Listlist=newsDetailService.queryAll();
intcount=newsDetailService.queryAllCount();
map.put("data",list);
map.put("count",count);
map.put("code",0);
map.put("returnCode","200");
returnmap;
}else{
map.put("code",1);
returnmap;
}
}
@RequestMapping("/update2")
@ResponseBody
publicMapupdate2(NewsDetailnewsDetail){
Mapmap=newHashMap<>();
/*newsDetail.setCreateDate(newDate());*/
introw=newsDetailService.updateById(newsDetail);
if(row==1){
Listlist=newsDetailService.queryAll();
intcount=newsDetailService.queryAllCount();
map.put("data",list);
map.put("count",count);
map.put("code",0);
returnmap;
}else{
map.put("code",1);
returnmap;
}
}
@RequestMapping("/add")
@ResponseBody
publicMapadd(@RequestBodyHashMapmap2){
Mapmap=newHashMap<>();
Stringtitle=map2.get("newtitle");
Stringsummary=map2.get("newsummary");
Stringauthor=map2.get("newauthor");
NewsDetailnewsDetail=newNewsDetail();
newsDetail.setTitle(title);
newsDetail.setSummary(summary);
newsDetail.setAuthor(author);
newsDetail.setCreateDate(DateUtil.formatDate(newDate(),"yyyy-MM-ddHH-mm-ss"));
booleanrow=newsDetailService.addNews(newsDetail);
if(row){
Listlist=newsDetailService.queryAll();
intcount=newsDetailService.queryAllCount();
map.put("data",list);
map.put("count",count);
map.put("returnCode","200");
map.put("code",0);
returnmap;
}else{
map.put("code",1);
returnmap;
}
}
}
亲测有效,希望大家提出不足!谢谢!另外后台里面有一个时间转换的类(DateUtil.formatDate()),前端有一个例如url:'${ctx}/news/update/',其中的${cxt}是一个指定的路径,后台写了一个类,这些有需要的,可以看我的博客,谢谢!
以上这篇layui+SSM的数据表的增删改实例(利用弹框添加、修改)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。