package com.nic.web.controller;

import java.util.Map;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.Errors;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.nic.pojo.Users;

@Controller
public class RegisterController {

	
	
	
	@RequestMapping(value="/register",method=RequestMethod.GET)
	public String showForm(Map<String, Object> map){
		map.put("users", new Users());
		return "register";
	}
	@RequestMapping(value="/register",method=RequestMethod.POST)
	public String post(Model model, @Valid Users users,Errors result,Map<String, Object> map){
		
		if(result.getErrorCount() > 0){
			System.out.println("出错了!");
			
			for(FieldError error:result.getFieldErrors()){
				System.out.println(error.getField() + ":" + error.getDefaultMessage());
			}

			return "register";
		}
		return "login";
	}
}
