//请不要全部照搬 需要使用layer插件
list.jsp
function myAdvertEdit(id,look,type){
var loadIdx = layer.load();var title = '增加广告';
if(!id){
id = '';
}else if(look=='look'){
title='查看广告'
}else{
title = '修改广告';
}
//当查看的时候会传过来两个参数 如果当id没传 值表明是新增 然后在 看
if(look=='look'){
//这个是JQ中的post请求 这个是请求成功放回的 str
$.post('${ctx}/advert/toCreate?id='+id+'&look='+look+'&type='+type, {}, function(str){layer.close(loadIdx);
//弹出框
layer.open({
title : title, //标题
type : 0, //layer提供了5种层类型。可传入的值有: 0(信息框,默认) 1(页面层) 2(iframe层) 3(加载层) 4(tips层)。 若你采用 layer.open({type: 1})方式调用,则type为必填项(信息框除外)
area : ['780px', '540px'], //弹出款的大小
content : str,
btn : ['取消'],
btn2 : function(index, layero){
layer.close(index);
}
});
});
}else{
$.post('${ctx}/advert/toCreate?id='+id+'&look='+look+'&type='+type, {}, function(str){
layer.close(loadIdx);
layer.open({
title : title,
type : 1,
area : ['780px', '540px'],
content : str,
btn : ['确定','取消'],
yes : function(index, layero){ //确认之后需要执行的事情
myTypeSubmit(); //这个方法 是自己写的 不要搬过去 这个意思是 提交 页面表单 也就是刷新页面 这你得刷新页面不是 刷新弹出框的
},
btn2 : function(index, layero){
layer.close(index);
}
});
});
}
}
edit.jsp
//表单验证
$(function(){
$('#editForm').validator({
submit:function() {
var formValidaty = this.isFormValid();
if(formValidaty){
var form = $(this);
var laodIdx = layer.load();
$('#editForm').ajaxSubmit({
data : form.serialize(),
traditional : true,
success : function(result){
layer.close(laodIdx);
if(result.success){
layer.alert('保存成功',{icon: 1},function(){
//window.location.reload();
layer.closeAll();//关闭弹出框
_AT_QUERY_FORM($(_CURR_TAB+' #queryForm'));//重新加载列表
});
}else{
layer.alert(result.msg);
}
}
});
}else{
}
return false;
}
});
});
=================================================================================================================================
后台代码
代码 事从项目中COPY 过来的
/**
* 进入新增 or 修改页面 or 查看页面
*/
@RequestMapping(value = "/toCreate")
public ModelAndView toCreate(HttpServletRequest request) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String id=request.getParameter("id");
String look=request.getParameter("look");
if(look.equals("look")){
map.put("look", look);
}
if(id!=null&&!"".equals(id)){
InstantaneousVO vo=(InstantaneousVO) baseService.retrieveByPK(InstantaneousVO.class, id);
map.put("instantaneous", vo);
}
List<InstitutionVO> list=(List<InstitutionVO>) baseService.retrieveAll(InstitutionVO.class);
List<CourseVO> coulist=(List<CourseVO>) baseService.retrieveByClause(CourseVO.class," dr='0'");
map.put("coulist", coulist);
map.put("list", list);
return backView("instantaneous/instantaneous_edit", map);
}
//新增 or 修改 这个是springMVC提供的一中 ajax反问 返回结果的一中方式
@RequestMapping(value = "/edit")
public ResponseEntity<Map> edit(InstantaneousVO vo) throws BusinessException {
Map<String, Object> map = new HashMap<String, Object>();
try{
if(vo.getId()!=null&&!"".equals(vo.getId())){
vo.setTs(time);
baseService.updateVO(vo);
}else{
List<InstantaneousVO> banklist=(List<InstantaneousVO>)baseService.retrieveByClause(InstantaneousVO.class, " dr='0'"," ORDER BY code+0 DESC");
if(banklist.size()>0){
if(!banklist.get(0).getCode().equals("")&&banklist.get(0).getCode()!=null){
vo.setCode( String.valueOf(Integer.valueOf(banklist.get(0).getCode())+1));
}else{
vo.setCode( String.valueOf(1));
}
}else{
vo.setCode( String.valueOf(1));
}
UserVO user= (UserVO) getSession().getAttribute("sysUser");
List<InstitutionVO> inst=(List<InstitutionVO>) baseService.retrieveByClause(InstitutionVO.class, "");
vo.setRecord_people(user.getReal_name());
vo.setMechanism(inst.get(0).getId());
vo.setTs(time);
vo.setRecord_time(time1);
// vo.setState("0");
vo.setDr("0");
baseService.insertVO(vo);
}
map.put("rs", "success");
} catch(BusinessException e){
map.put("rs","error");
map.put("msg",e.getMessage());
return new ResponseEntity<Map>(map,HttpStatus.BAD_REQUEST);
}
return new ResponseEntity<Map>(map,HttpStatus.OK);
}