layui数据表格的使用

代码清单

welcom.html



	
		
		layui数据表格
		
		
	
	
		

 实体类User

package com.example.bean;
public class User {
	private int id;
	private String name;
	private String realName;
	private String phone;
	private String mail;
	private String createDate;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getRealName() {
		return realName;
	}
	public void setRealName(String realName) {
		this.realName = realName;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getMail() {
		return mail;
	}
	public void setMail(String mail) {
		this.mail = mail;
	}
	public String getCreateDate() {
		return createDate;
	}
	public void setCreateDate(String createDate) {
		this.createDate = createDate;
	}
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return "User [name="+name+",realName="+realName+",phone="+phone+""
		+ ",mail="+mail+"。]";
	}
}

UserController

package com.example.controller;
import java.util.List;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.bean.User;
import com.example.service.UserService;
@RestController
public class UserController {
	@Resource
	private UserService userService;			
	private static final Logger logger = LoggerFactory.getLogger(UserController.class.getName());
	@RequestMapping("/getList")
	public String getList(){		
		List list=userService.getList();
		String s = JSON.toJSONString(list);
		logger.info(s);
		JSONObject obj=new JSONObject();
        //前台通过key值获得对应的value值
        obj.put("code", 0);
        obj.put("msg", "");
        obj.put("count",1000);
        obj.put("data",list);
        return obj.toJSONString();
	}		
}

运行结果:

layui数据表格的使用_第1张图片

源文件地址:https://pan.baidu.com/s/18zPIyxGxycPZaXd6dRzAlg 提取码: fnf4 

你可能感兴趣的:(layui)