ssm前后端分离之前端获取服务器json数据(easyUI)

 1,entity:将查询数据转换成特定的json格式

 

package com.meng.entity;

import java.util.List;

public class DataResult<T> {
	
	public DataResult() {}
public DataResult(int total, List<T> rows) {
 
		this.total = total;
		this.rows = rows;
	}
private int total;
private List<T> rows;
public int getTotal() {
	return total;
}
public void setTotal(int total) {
	this.total = total;
}
public List<T> getRows() {
	return rows;
}
public void setRows(List<T> rows) {
	this.rows = rows;
}
}

2,controller:


	@Autowired
	private FlowersInfoService flowersInfoService;

	// http://localhost:8080/flower/flower/getAll
	@RequestMapping(value = "/getAll", method = RequestMethod.GET)
	public DataResult<FlowersInfo> get() {		
		List<FlowersInfo> list = flowersInfoService.getAllFlowers();
		return new DataResult<FlowersInfo>(list.size(),list);
	}

 

3前台获取json数据

<table id="table">
	</table>

 

$(function() {
		var url = "http://localhost:8080/flower/flowers/getAll";
		$('#table').datagrid({
			url : url,
			method: "get",
			pagePosition : 'bottom',
			pageSize : 10,
			pageList : [ 10, 15,20],
			pagination : true,
			columns :  [[ {
				field : 'flowerId',
				title : '鲜花编号',
				width : 100
			}, {
				field : 'flowerImage',
				title : '鲜花图片',
				width : 100
			}, {
				field : 'flowerName',
				title : '鲜花名称',
				width : 100
			}, {
				field : 'flowerNum',
				title : '储存量',
				width : 100
			}, {
				field : 'flowerType',
				title : '鲜花类型',
				width : 100
			}, {
				field : 'price',
				title : '价格',
				width : 100
			}, {
				field : 'userId',
				title : '用户Id',
				width : 100
			}, {
				field : 'des',
				title : '详情',
				width : 100
			}

			] ]
		});
		

 

 4,图片展示:

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值