后端
@GetMapping(value = "/updateMovie/{ids}")
@ResponseBody
public void updateMovie(@PathVariable("ids") Integer id,HttpServletRequest request,HttpServletResponse response) throws IOException {
Movie movie = moviesService.getMovieByMovieId(id);
HttpSession session = request.getSession();
String s = JSON.toJSONString(movie);
session.setAttribute("movie",s);
response.sendRedirect("/update.jsp");
}
触发条件,请求updateMovie函数返回json
else if(obj.event === 'edit'){
//信息修改
layer.open({
type: 2,
title:"修改电影",
area:['80%','80%'],
content: 'http://localhost:8080/updateMovie/'+data.m_id
});
}
前端 通过lay-filter 触发js取渲染表单
<form class="layui-form" lay-filter="test" action="" >
<div class="layui-form-item">
<label class="layui-form-label">预算</label>
<div class="layui-input-block">
<input type="text" name="budget" required="required" lay-verify="required|number" placeholder="请输入预算" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">电影类型</label>
<div class="layui-input-block">
<input type="text" name="genres" required="required" placeholder="请输入电影类型,类型用 | 隔开" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">电影主页</label>
<div class="layui-input-block">
<input type="text" name="homepage" placeholder="请输入电影主页" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">Imdb_id</label>
<div class="layui-input-block">
<input type="text" name="imdb_id" required lay-verify="required|number" placeholder="请输入imdb编码" autocomplete="off" class="layui-input">
</div>
</div>
//Demo
layui.use(['form','laydate','table'], function(){
var form = layui.form;
var laydate = layui.laydate;
var $ =layui.$
laydate.render({
elem:'[name="release_date"]'
});
var obj= <%=session.getAttribute("movie")%>;
alert(obj['genres']);
alert(obj.genres);
//设置表单默认值
form.val("test", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
"budget":obj.budget,
"genres":obj.genres,
"homepage":obj.homepage,
"imdb_id":obj.imdb_id,
"original_language":obj.original_language,
"overview":obj.overview,
"production_companies":obj.production_companies,
"release_date":obj.release_date,
"spoken_languages":obj.spoken_languages,
"tagline":obj.tagline,
"title":obj.title,
"image_path":obj.image_path
});
form.render();