package com.maxbox.controller;

import com.alibaba.fastjson.JSONObject;
import com.maxbox.Bean.Person;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by guohui on 2019/4/11.
 */
@RestController
@RequestMapping("/test")
public class HelloController {

    @GetMapping(value = "/hello")
    public String getHello(@RequestParam(name = "name") String name) {
        System.out.println("hello!!!" + name);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 123);
        return jsonObject.toJSONString();
    }

    @GetMapping(value = "/getTexthello")
    public String getTextHello(@RequestParam(name = "name") String name) {
        System.out.println("hello!!!" + name);
        return "success";
    }

    @PostMapping(value = "/saveHello")
    public String saveHello(@RequestBody Person person) {
        System.out.println("请求参数：" + JSONObject.toJSONString(person));
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 0);
        return jsonObject.toJSONString();
    }

    @GetMapping(value = "/hello/{id}")
    public String getHelloById(@PathVariable(value = "id") Integer id) {
        System.out.println("请求参数：hello" + id);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 0);
        return jsonObject.toJSONString();
    }
}
