package com.lovecoding.mvc;

import com.lovecoding.mvc.doman.Book;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.filter.HttpPutFormContentFilter;
import org.springframework.web.filter.reactive.HiddenHttpMethodFilter;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

@Controller
public class TestController {

    /**
     * Swagger 他是一个效率工具
     * 它存在的意义在于 提交 前后端沟通效率
     * @param id
     * @return
     */
    @GetMapping("/test")
    public String test( int id ){
        //int n = 1 / 0;
        //Long i = null;
        //System.out.println( i.longValue() );

        return "/test.jsp";
    }

//    @ExceptionHandler({
//            ArithmeticException.class
//    })
//    public ModelAndView err( Exception e ){
//        ModelAndView modelAndView = new ModelAndView();
//        modelAndView.addObject("ex", e.getMessage());
//        modelAndView.setViewName("/anno.jsp");
//        return modelAndView;
//    }

    @ResponseBody
    @PostMapping("/jsontest")
    public Book getBook(@RequestBody Book book ) {

        System.out.println( book );

        return book;
    }


    @ResponseBody
    @PostMapping("/date")
    public String getBook(Date mydate ) {

        System.out.println( mydate );

        return "OK";
        //return date.toLocaleString();
    }

}
