在学生表当中实现图片 添加 和 修改
只需要4步(其中一步是人家写好的)
我们需要现在数据库加一个图片的字段picture
显示页面中只需要这个一步就可以了
{
field: 'picture',
title: '学生照片',
formatter: function (value, row, index) {
return '<img src="' + value + '" width="75" height="75">';
}
},
实体类中
add.html
<div class="form-group">
<label class="col-sm-2 control-label">学生照片:</label>
<div class="col-sm-10">
<input name="picture" id="pic" class="form-control" type="hidden">
<a id="url"><img th:src="*{picture}" style="width: 90px;height: 90px"></a>
<input type="file" id="abc">
</div>
</div>
var prefix = ctx + "system/student";
$("#abc").change(function () {
var data = new FormData();
data.append("file", $("#abc")[0].files[0]);
$.ajax({
type: "POST",
url: ctx + "common/upload",
data: data,
cache: false,
contentType: false,
processData: false,
dataType: 'json',
success: function(result) {
// alert(JSON.stringify(result))
if (result.code == web_status.SUCCESS) {
$("#url img").attr("src",result.fileName)
$("#pic").val(result.fileName)
}
},
error: function(error) {
alert("图片上传失败。");
}
});
})
效果图
修改和添加的方法是一样的复制粘贴过去即可