package com.controller;

import com.transaction_.pojo.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Controller
public class UserController {
    @Autowired
    String getS;
    @RequestMapping("/quick")
    public String quick() {
        System.out.println("userControllerRunning1...");
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("name","name");
        return "success";
        // 加了前后缀 完整链接应该是 forward:/template/success.jsp
//        return "redirect:http://baidu.com";
    }
    // 回写数据 返回字符串
    @RequestMapping("/save")
    public void save(HttpServletRequest request, HttpServletResponse response) throws IOException {
        // 直接返回字符串
        ServletContext servletContext = request.getServletContext();
        response.getWriter().println("save");

    }
    // 回写数据 使用注解进行返回字符串
    @RequestMapping("/save2")
    @ResponseBody // 不进行视图跳转，直接进行数据响应
    public String save2() {
        return "save2";
    }
    // 回写数据 返回对象
    @RequestMapping("/save3")
    @ResponseBody // 不进行视图跳转，直接进行数据响应
    public Student save3() {
        Student student = new Student();
        student.setName("woshinishiws");
        return student;
    }
    // 回写数据 返回对象
    @RequestMapping("/save4")
    @ResponseBody // 不进行视图跳转，直接进行数据响应
    public Map save4() {
        HashMap<String, String> stringStringHashMap = new HashMap<String, String>();
        stringStringHashMap.put("1","2");
        int  a = 1/0;
        return stringStringHashMap;
    }


}
