package com.fjs.scenic.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.fjs.scenic.entity.user.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fjs.scenic.utils.TablePage;

@Controller
public class TestController {
	
	@GetMapping("/login1")
	public String login(){
		return "login-lte";
	}
	
	@GetMapping("/templateUser")
	public String index(){
		
		return "template_user";
	}
	
	@PostMapping("/page")
	@ResponseBody
	public TablePage<User> page(HttpServletRequest request){
		String strdraw = request.getParameter("draw");
		String strstart = request.getParameter("start");
		String strlength = request.getParameter("length");
		String name = request.getParameter("name");
		int draw = strdraw == null?0:Integer.parseInt(strdraw);
		int start = strstart == null?0:Integer.parseInt(strstart);
		int length = strlength == null?0:Integer.parseInt(strlength);
		TablePage<User> data = new TablePage<>();
		data.setDraw(draw);
		data.setRecordsTotal(length);
		data.setRecordsFiltered(length);
		List<User> users = new ArrayList<>();
		for(int i =1;i<=length;i++){
			User user =new User();
			user.setId(i);
//			user.setName("yangya"+i);
			users.add(user);
		}
		data.setData(users);
		return data;
	}

}
