• springboot 中controller的简单使用


    这里是我的目录文件

    @Controller
    public class TestController {
    
        @RequestMapping(value="/register13")
        public String save23() {
            System.out.println("save23");
            return "index1";
        }
        @RequestMapping(value="/register10")
    //    http://localhost:8080/register8/111
        public String save20() {
            System.out.println("save20");
            return "redirect:/index.html";
        }
    
    
        @RequestMapping(value="/register12")
        @ResponseBody
        public void save22(@RequestHeader(value = "User-Agent",required = false) String user_agent){
            System.out.println(user_agent);
        }
    
        @RequestMapping(value="/register11")
        @ResponseBody
        public void save21(@CookieValue(value = "JSESSIONID") String jsessionId) {
            System.out.println(jsessionId);
        }
    
    
    
    
        @RequestMapping(value="/register9")
    
    //    http://localhost:8080/register8/111
        public String save19() {
            return "/login222.jsp";
        }
    
    
    
        @RequestMapping(value="/register8/{name}")
        @ResponseBody
    //    http://localhost:8080/register8/111
        public void save18(@PathVariable(value="name") String username) {
            System.out.println(username);
    
        }
    
        @RequestMapping(value="/register7")
        @ResponseBody
        public void save16(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
            System.out.println(request);
            System.out.println(response);
            System.out.println(session);
        }
    
        @RequestMapping("/register6")
        @ResponseBody
        //http://localhost:8080/register6?birthday=2020-02-01&name=111
        public void save15(User user) {
            System.out.println(user);
        }
    
    
        @RequestMapping("/register5")
        @ResponseBody
    //    http://localhost:8080/register4?strs=1111&strs=1112&strs=4
        public void save14(@RequestBody List<User> userList) {
            System.out.println(userList);
            System.out.println("00000");
        }
    
    
    
    
        @RequestMapping("/register4")
        @ResponseBody
    //    http://localhost:8080/register4?strs=1111&strs=1112&strs=4
        public void save13(String[] strs) {
            System.out.println(Arrays.asList(strs));
    
        }
    
    
        @RequestMapping("/register3")
        @ResponseBody
        //http://localhost:8080/register3?name=zhangsan100&age=10
        public void save12(User user) {
            System.out.println(user);
    
        }
    
        @RequestMapping("/register2")
        @ResponseBody
        //value说明是url连接地址的名字 required是否是必传的参数 defaultValue如果不传参数的默认值
    //    http://localhost:8080/register2
    //    http://localhost:8080/register2?username=zhangsan100
        public void save11(@RequestParam(value = "username",required = false,defaultValue = "zhangsan") String username)  {
            System.out.println(username);
    
        }
    
    
        @RequestMapping("/register1")
        @ResponseBody
        //http://localhost:8080/register1?username=zhangsan11
        public void save10(String username)  {
            System.out.println(username);
    
        }
    
        @RequestMapping({"/login9"})
        @ResponseBody
        public List<User> save9() {
            List<User> list = new ArrayList<User>();
            for(int i=0;i< 10;i++){
                User user = new User();
                user.setName("zhangsan"+i);
                user.setAge(13+i);
                list.add(user);
            }
            return list;
        }
    
        @RequestMapping({"/login8"})
        @ResponseBody
        public User save8() {
            User user = new User();
            user.setName("zhangsan6");
            user.setAge(13);
           return user;
    
        }
    
        @RequestMapping({"/login7"})
        @ResponseBody
        public String save7(HttpServletResponse model) {
            return "{"username":"zhangsan5","age":18}";
    
        }
    
    
        @RequestMapping({"/login6"})
        public void save6(HttpServletResponse model) {
            try {
                model.getWriter().write("zhangsan4");
            } catch (IOException e) {
                e.printStackTrace();
            }
    
        }
    
        @RequestMapping({"/login5"})
        public String  save5(Model model) {
            model.addAttribute("username","zhangsan3");
            return "/login.jsp";
        }
    
        @RequestMapping({"/login4"})
        public ModelAndView save4(ModelAndView modelAndView) {
            //设置模型数据
            modelAndView.addObject("username","zhangsan2");
            //设置视图名称
            modelAndView.setViewName("/login.jsp");
            return modelAndView;
        }
    
    
        @RequestMapping({"/login3"})
        public ModelAndView save3() {
            ModelAndView modelAndView = new ModelAndView();
            //设置模型数据
            modelAndView.addObject("username","zhangsan1");
            //设置视图名称
            modelAndView.setViewName("/login.jsp");
            return modelAndView;
        }
    
        @RequestMapping({"/login2"})
        public String save2(HttpServletRequest request) {
            request.setAttribute("username","zhangsan");
            return "/login.jsp";
        }
    
    
    
        @RequestMapping("/login1")
        @ResponseBody
        public String save1(){
            return "login";
        }
    
        @RequestMapping("/login")
        public String save(){
            return "/login.jsp";
        }
    }
    
  • 相关阅读:
    python排序
    python中常用的九种数据预处理方法分享
    8089汇编 源程序
    8086汇编 栈操作
    8089汇编 运算符指令
    8089汇编 标志寄存器
    8086汇编 段寄存器
    8086汇编 Debug 使用
    8086汇编 CPU 寄存结构
    8086汇编 内存交互
  • 原文地址:https://www.cnblogs.com/hualuoshuijia/p/13731447.html
Copyright © 2020-2023  润新知