//点击修改按钮弹出模态框
$("#table-demo-ajaxPageCode").on('click','a[data-obj]',function(){
//操作:清空表单,因为添加和修改使用的是同一个模态框,添加数据之后点击取消,再点击添加或修改还是以前的数据,所有需要清空
/* 操作:清空表单时不会清除隐藏域id,这样在添加和修改时要出问题
$("#saveForm #id").val(""); */
$("#saveForm").get(0).reset();
//1.获取到回显的数据
var jsonObj = $(this).data('obj'); //json对象
console.debug(jsonObj)
//2.设置到模态框的表单中
$("#saveForm").setForm(jsonObj); //做回显
/*修改按钮富文本编辑回显数据*/
/*添加清空富文本*/
var ue = UE.getEditor('container');
ue.ready(function() {
ue.setContent(jsonObj.content);
});
$("#saveModel").modal("show");
//点击添加和修改模态框的【确定】按钮绑定单击事件
$("#saveButton").on('click',function(){
//将表单中的数据【表单项必须有name属性值】以ajax异步的方式进行提交 //请求就是表单中action的属性值
$("#saveForm").ajaxSubmit({
success:function(msg){
//1.关闭模态框
$("#saveModal").modal("hide");
if(msg.success){
//2.刷新页面,参数是GridManager的 名称
GridManager.refreshGrid('demo-ajaxPageCode');
}else{//操作失败
//2.提示
alert(msg.msg);
}
}
});
});
});
});
前端控制器交给的页面控制的
package cn.itsource.controller;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.itsource.domain.Article;
import cn.itsource.domain.ArticleType;
import cn.itsource.query.IArticleQuery;
import cn.itsource.service.IArtService;
import cn.itsource.service.IArticleTypeService;
import cn.itsource.util.AjaxResult;
import cn.itsource.util.PageBase;
/**
* @Title: Articlecontroller.java
* @Package:cn.itsource.controller
* @Description:(文章管理)
* @author:lon
* @date:2021年1月15日
* @version:V1.0
*/
@Controller
@RequestMapping("/system")
public class Articlecontroller {
@Autowired
private IArtService service;
@Autowired
private IArticleTypeService TypeService;
@RequestMapping("/article/list")
@ResponseBody
public PageBase<Article> list(IArticleQuery ArticleQuery){
return service.findall(ArticleQuery);
}
/*文章查询高级查询回显*/
@RequestMapping("/article/index")
public String index(Model model){
System.out.println("uu");
List<ArticleType> types = TypeService.findAll();
model.addAttribute("types", types);
return "article/article";
}
@RequestMapping("/article/del")
@ResponseBody
public AjaxResult delete(Long id){
System.out.println("1");
try {
System.out.println("2");
service.delete(id);
return new AjaxResult(true, "");
} catch (Exception e) {
System.out.println("3");
return new AjaxResult(false, "小老弟你不行呀");
}
}
@RequestMapping("/article/save")
@ResponseBody
public AjaxResult save(Article article,HttpServletRequest req){
System.out.println("保存方法");
try {
System.out.println("后台来了");
service.save(article,req);
return new AjaxResult(true,"");
} catch (Exception e) {
return new AjaxResult(false, "操作失败");
}
}
@RequestMapping("/index")
public String index(){
return "index";
}
}
接收参数用的实体类
package cn.itsource.query;
import cn.itsource.util.BaseQuery;
public class ArticleQuery extends BaseQuery{
private String title;
private Long typeId;
private Boolean enable;
@Override
public String toString() {
return "ArticleQuery [title=" + title + ", typeId=" + typeId + ", enable=" + enable + "]";
}
public ArticleQuery(String title, Long typeId, Boolean enable) {
super();
this.title = title;
this.typeId = typeId;
this.enable = enable;
}
public ArticleQuery() {
super();
// TODO Auto-generated constructor stub
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Long getTypeId() {
return typeId;
}
public void setTypeId(Long typeId) {
this.typeId = typeId;
}
public Boolean getEnable() {
return enable;
}
public void setEnable(Boolean enable) {
this.enable = enable;
}
}
分页实现都会继承该类接收gridmanger提交的参数
package cn.itsource.util;