package com.controller;

import com.transaction_.pojo.entity.Student;
import org.springframework.stereotype.Controller;
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.ResponseBody;

import java.util.List;

@Controller
public class ParamController {
    // 基本类型参数
    // http://localhost:8083/param1?name=zxy&age=11
    @RequestMapping("/param1")
    @ResponseBody
    public void param1(String name,Integer age) {
        System.out.println(name);
        System.out.println(age);
    }
    // 获取pojo类型的参数
    // http://localhost:8083/param2?name=zxy&age=11
    @RequestMapping("param2")
    @ResponseBody
    public void param2(Student student) {
        System.out.println(student.getAge());
    }
    // 获取数组类型的参数
    // http://localhost:8083/param1?name=zxy&name=zxy2&name=zxy3
    @RequestMapping("param3")
    @ResponseBody
    public void param3(String[] name) {
        System.out.println(name);
    }
    // 获取集合类型参数
    @RequestMapping("param4")
    @ResponseBody
    public void param4(@RequestBody List<Student> students) {
        System.out.println(students);
    }
    // 使用RequestParam
    // http://localhost:8083/param5?Name=%E5%BC%A0
    @RequestMapping("param5")
    @ResponseBody
    public void param5(@RequestParam(name = "Name1",required = false) String name) {
        System.out.println(name);
    }
}
