SpringMVC中layui 表格分页

分页

SpringMVC前后端交互时,用到的数据库数据有时候比较大,这时进行分页显示,有利于节省内存资源.

前段分页代码

html代码
<table id="car" class="layui-hide" lay-filter="table_anomaly">
JavaScript代码
layui.use(['table', 'element'], function() {
   
				var table = layui.table;
				table.render({
   
					elem : '#car',
					url:url,
					where:{
    params},
					cols : [ [ {
   
						title : '序号',
						type : 'numbers'
					}, {
   
						field : 'registrationNum',
						width : 99,
						title : '车牌号'
					}, {
   
						field : 'time',
						width : 165,
						title : '时间',
						sort : true
					}, {
   
						field : 'fenceName',
						width : 150,
						title : '电子围栏'
					} ] ],
					request: {
   
                        pageName: 'page' //页码的参数名称,默认:page
                        , limitName: 'row' //每页数据量的参数名,默认:limit
                    },
					response:{
   
						statusName:'code',
						statusCode:'200',
						msgName:'msg',
						count:
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为您提供一些实现步骤,具体如下: 1.在Spring MVC的配置文件添加文件上传的配置,包括文件上传的大小、文件保存的路径等配置,如下所示: ``` <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="5242880"/> <property name="defaultEncoding" value="utf-8"/> <property name="resolveLazily" value="true"/> </bean> ``` 2.在前端页面使用Layui的上传组件,代码如下所示: ``` layui.use('upload', function(){ var upload = layui.upload; //执行实例 var uploadInst = upload.render({ elem: '#test1', //绑定元素 url: '/upload/', //上传接口 accept: 'images', size: 5120, done: function(res){ //上传完毕回调 }, error: function(){ //请求异常回调 } }); }); ``` 3.在Spring MVC的Controller编写文件上传的代码,包括文件上传、文件保存以及将文件信息保存到数据库的操作,代码如下所示: ``` @RequestMapping(value = "/upload", method = RequestMethod.POST) @ResponseBody public Map<String, Object> upload(HttpServletRequest request, HttpServletResponse response) { Map<String, Object> map = new HashMap<String, Object>(); try { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; MultipartFile file = multipartRequest.getFile("file"); String fileName = file.getOriginalFilename(); String suffix = fileName.substring(fileName.lastIndexOf(".") + 1); String newFileName = UUID.randomUUID().toString() + "." + suffix; String savePath = request.getSession().getServletContext().getRealPath("/") + "upload/"; File savePathFile = new File(savePath); if (!savePathFile.exists()) { savePathFile.mkdirs(); } String filePath = savePath + newFileName; File dest = new File(filePath); file.transferTo(dest); String imgUrl = "/upload/" + newFileName; //图片访问路径 //将文件信息保存到数据库 Image image = new Image(); image.setFilename(fileName); image.setUrl(imgUrl); imageService.saveImage(image); map.put("code", 0); map.put("msg", "上传成功"); map.put("data", imgUrl); } catch (Exception e) { e.printStackTrace(); map.put("code", -1); map.put("msg", "上传失败"); map.put("data", ""); } return map; } ``` 以上就是使用Spring MVC和Layui实现图片上传并保存到数据库的步骤。希望能对您有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值