zoukankan      html  css  js  c++  java
  • Spring MVC学习03页面跳转

    新建Controller:ForwardController

     1 package com.yas.controller;
     2 
     3 import org.springframework.stereotype.Controller;
     4 import org.springframework.web.bind.annotation.RequestMapping;
     5 
     6 @Controller
     7 @RequestMapping("/jump")
     8 public class ForwardController {
     9 
    10     //forward:转发,页面跳转但地址栏不会改变
    11 
    12     @RequestMapping("/test1")
    13     public String test(){
    14         //return "hello";
    15 
    16         //另一种方式,使用转发关键字:forward
    17         return "forward:/WEB-INF/jsp/hello.jsp";
    18     }
    19 
    20     //转发到另一个action
    21     @RequestMapping("/test2")
    22     public String test2(){
    23         //使用相对路径
    24         return "forward:test1";
    25 
    26         //使用绝对路径
    27         //return "forward:/jump/test1";
    28     }
    29 
    30     //redirect:重定向,地址栏也会改变,体现为http的302跳转
    31 
    32     @RequestMapping("/test3")
    33     public String test3(){
    34         return "redirect:/index.jsp";
    35     }
    36 
    37     @RequestMapping("/test4")
    38     public String test4(){
    39         //相对路径
    40         return "redirect:test3";
    41 
    42         //绝对路径
    43         //return "redirect:/jump/test3";
    44     }
    45 
    46     /*
    47     注意:
    48     1、查询操作,采用forward
    49     2、增删改操作,采用redirect,防止用户刷新页面反复操作数据库
    50      */
    51 }
  • 相关阅读:
    js遍历不要使用index 而是使用id(数据唯一表示)
    eureka
    Mybatis-plus自动填充字段的值(如createTime,UpdateTime)
    计算机网络入门
    操作系统入门
    计算机组成原理入门
    《事实》读书笔记
    推荐算法入门
    源码编译安装apache2.4脚本
    Mycat实现读写分离
  • 原文地址:https://www.cnblogs.com/asenyang/p/15465619.html
Copyright © 2011-2022 走看看