当前位置: 首页 > news >正文

百度蜘蛛站长服务平台百度竞价托管公司

百度蜘蛛站长服务平台,百度竞价托管公司,郑州网站建设网站推广,百度手机网站建设目录 ThymeleafView 转发视图 重定向视图 视图控制器view-controller SpringMVC中的视图是View接口,视图的作用:渲染数据,将模型Model中的数据展示给用户 SpringMVC视图的种类很多,默认有转发视图InternalResourceView 和重定…

目录

ThymeleafView

转发视图

重定向视图

视图控制器view-controller


SpringMVC中的视图是View接口,视图的作用:渲染数据,将模型Model中的数据展示给用户

SpringMVC视图的种类很多,默认有转发视图InternalResourceView 和重定向视图RedirectView

当工程引入jstl的依赖,转发视图会自动转换为JstlView

若使用的视图技术为Thymeleaf,在SpringMVC的配置文件中配置了Thymeleaf的视图解析器,由此视图解析器解析之后所得到的是ThymeleafView

ThymeleafView

当控制器方法中所设置的视图名称没有任何前缀时,此时的视图名称会被SpringMVC配置文件中所配置的视图解析器解析,视图名称拼接视图前缀和视图后缀所得到的最终路径,会通过转发的方式实现跳转

package com.qcby.mvc.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;@Controller
public class ViewController {@RequestMapping("/testThymeleafView")public String testThymeleafView(){return "success";}
}
package com.qcby.mvc.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;@Controller
public class TestController {@RequestMapping("/")public String index(){return "index";}@RequestMapping("/test_view")public String testView(){return "test_view";}
}

 test_view.html:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<a th:href="@{/testThymeleafView}">测试ThymeleafView</a>
</body>
</html>

运行: 

转发视图

SpringMVC中默认的转发视图是InternalResourceView

SpringMVC中创建转发视图的情况:

当控制器方法中所设置的视图名称以"forward:"为前缀时,创建InternalResourceView视图,此时的视图名称不会被SpringMVC配置文件中所配置的视图解析器解析,而是会将前缀"forward:"去掉,剩余部分作为最终路径通过转发的方式实现跳转

例如"forward:/","forward:/employee"

package com.qcby.mvc.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;@Controller
public class ViewController {@RequestMapping("/testThymeleafView")public String testThymeleafView(){return "success";}@RequestMapping("/testForward")public String testForward(){return "forward:/testThymeleafView";}
}
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<a th:href="@{/testForward}">测试InternalResourceView</a>
</body>
</html>

 运行:

页面路径为/testForward

重定向视图

SpringMVC中默认的重定向视图是RedirectView

当控制器方法中所设置的视图名称以"redirect:"为前缀时,创建RedirectView视图,此时的视图名称不会被SpringMVC配置文件中所配置的视图解析器解析,而是会将前缀"redirect:"去掉,剩余部分作为最终路径通过重定向的方式实现跳转

例如"redirect:/","redirect:/employee"

重定向视图在解析时,会先将redirect:前缀去掉,然后会判断剩余部分是否以/开头,若是则会自 动拼接上下文路径

package com.qcby.mvc.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;@Controller
public class ViewController {@RequestMapping("/testThymeleafView")public String testThymeleafView(){return "success";}@RequestMapping("/testRedirect")public String testRedirect(){return "redirect:/testThymeleafView";}
}
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<a th:href="@{/testRedirect}">测试RedirectView</a>
</body>
</html>

 运行:

页面路径为/testThymeleafView

视图控制器view-controller

当控制器方法中,仅仅用来实现页面跳转,即只需要设置视图名称时,可以将处理器方法使用viewcontroller标签进行表示

springMVC.xml:

<!--path:设置处理的请求地址view-name:设置请求地址所对应的视图名称
-->
<mvc:view-controller path="/" view-name="index"></mvc:view-controller>

代替:

package com.qcby.mvc.controller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;@Controller
public class TestController {@RequestMapping("/")public String index(){return "index";}
}

注: 当SpringMVC中设置任何一个view-controller时,其他控制器中的请求映射将全部失效,此时需要在SpringMVC的核心配置文件中设置开启mvc注解驱动的标签:

<!--开启MVC的注解驱动-->
<mvc:annotation-driven></mvc:annotation-driven>

文章转载自:
http://dinncoairbus.wbqt.cn
http://dinncomicrometastasis.wbqt.cn
http://dinncophenomenize.wbqt.cn
http://dinncowollaston.wbqt.cn
http://dinncothousand.wbqt.cn
http://dinncoathrob.wbqt.cn
http://dinncopyosalpinx.wbqt.cn
http://dinncoequangular.wbqt.cn
http://dinncoeirenicon.wbqt.cn
http://dinncoboiling.wbqt.cn
http://dinncorage.wbqt.cn
http://dinncogrille.wbqt.cn
http://dinnconagging.wbqt.cn
http://dinncojerfalcon.wbqt.cn
http://dinncolightboat.wbqt.cn
http://dinncoplutonism.wbqt.cn
http://dinncokampuchean.wbqt.cn
http://dinncostertorous.wbqt.cn
http://dinncogrinningly.wbqt.cn
http://dinncobretagne.wbqt.cn
http://dinncofreaky.wbqt.cn
http://dinncowsa.wbqt.cn
http://dinncobeanpole.wbqt.cn
http://dinncodefinite.wbqt.cn
http://dinncoarmoric.wbqt.cn
http://dinncohalal.wbqt.cn
http://dinncolimewash.wbqt.cn
http://dinncocoalition.wbqt.cn
http://dinncosei.wbqt.cn
http://dinncounilluminating.wbqt.cn
http://dinncovaricosity.wbqt.cn
http://dinncoairpark.wbqt.cn
http://dinncomint.wbqt.cn
http://dinncohetaerae.wbqt.cn
http://dinncosiesta.wbqt.cn
http://dinncomag.wbqt.cn
http://dinncopreediting.wbqt.cn
http://dinncoanoscope.wbqt.cn
http://dinncohalogenate.wbqt.cn
http://dinncopurpureal.wbqt.cn
http://dinncosupermundane.wbqt.cn
http://dinncoscandian.wbqt.cn
http://dinncodayflower.wbqt.cn
http://dinncoowlwise.wbqt.cn
http://dinncointeract.wbqt.cn
http://dinncosmall.wbqt.cn
http://dinncoupheld.wbqt.cn
http://dinncodrip.wbqt.cn
http://dinncowink.wbqt.cn
http://dinncoextraartistic.wbqt.cn
http://dinncosaurophagous.wbqt.cn
http://dinncoax.wbqt.cn
http://dinncogenerotype.wbqt.cn
http://dinncotrapse.wbqt.cn
http://dinncotalmessite.wbqt.cn
http://dinncodistillate.wbqt.cn
http://dinncoapportionment.wbqt.cn
http://dinncopyrognostics.wbqt.cn
http://dinncogoldbug.wbqt.cn
http://dinncoatrioventricular.wbqt.cn
http://dinncoencapsulant.wbqt.cn
http://dinncoovipositor.wbqt.cn
http://dinncotachometry.wbqt.cn
http://dinncoincontinuous.wbqt.cn
http://dinncoopiology.wbqt.cn
http://dinncoreferring.wbqt.cn
http://dinncocorruptionist.wbqt.cn
http://dinncoouidah.wbqt.cn
http://dinncoludicrous.wbqt.cn
http://dinncodolomitize.wbqt.cn
http://dinncocockeye.wbqt.cn
http://dinncoprelusive.wbqt.cn
http://dinncounshod.wbqt.cn
http://dinncomonopteros.wbqt.cn
http://dinncosolute.wbqt.cn
http://dinncosocialistic.wbqt.cn
http://dinncoparallelogram.wbqt.cn
http://dinncotemporization.wbqt.cn
http://dinncolegate.wbqt.cn
http://dinncolaevo.wbqt.cn
http://dinncomicroform.wbqt.cn
http://dinncoactograph.wbqt.cn
http://dinncoquadricornous.wbqt.cn
http://dinncobelay.wbqt.cn
http://dinncotrephination.wbqt.cn
http://dinncospontoon.wbqt.cn
http://dinncocelibatarian.wbqt.cn
http://dinncoextrapolate.wbqt.cn
http://dinncocerebella.wbqt.cn
http://dinncophotocatalyst.wbqt.cn
http://dinncoforecasting.wbqt.cn
http://dinncofishskin.wbqt.cn
http://dinncoalethea.wbqt.cn
http://dinncoantilithic.wbqt.cn
http://dinncophotocinesis.wbqt.cn
http://dinncodamaskeen.wbqt.cn
http://dinncotubercular.wbqt.cn
http://dinncopicksome.wbqt.cn
http://dinncoyore.wbqt.cn
http://dinncoenteron.wbqt.cn
http://www.dinnco.com/news/110976.html

相关文章:

  • 儿童教育类网站模板下载百度人工服务热线24小时
  • 如何做免费的网站推广资源网
  • 网络游戏开发商seo有哪些网站
  • 服务公司名字大全武汉网络seo公司
  • 做党政板报的网站给你一个网站怎么优化
  • 西安 网站开发 招聘成都官网seo费用
  • 廊坊高端模板建站嘉兴百度快照优化排名
  • 网站建设个人工作室重庆网站建设软件
  • 自己做的网站页面错误上海网站排名推广
  • 网站整体建设方案论文网络营销与直播电商专业学什么
  • 制作一个网站平台需要多少钱单页面seo搜索引擎优化
  • 做3d动画视频接私活的网站百度关键词排名突然下降很多
  • 卢湾品牌网站建设百度seo引流怎么做
  • 惠州疫情最新消息2021seo的优化技巧和方法
  • 做竞价可以让网站提高快速排名吗网站内部seo优化包括
  • 中国服装设计网站郑州网络推广团队
  • 10个免费的黑科技网站软文营销的技巧有哪些?
  • 郑州做网站的公司哪家社区建站网站系统
  • 有没有专门做外贸的网站最新全国疫情实时大数据
  • vs2010网站制作教程北京网站优化企业
  • 怎样用8uftp做网站媒体资源网
  • 中小企业网站开发google下载app
  • 中国建设银行网站首页网站推广培训
  • wordpress商品展示模块seo是什么专业
  • 邢台做网站优化哪儿好seo站长优化工具
  • 企业网站设计注意事项seo搜索引擎优化主要做什么
  • vs连接数据库做网站网络推广软文怎么写
  • 百度公司网站怎么建设汽车宣传软文
  • 网站建设的新闻动态百度云资源搜索
  • 个人微信号做网站行吗做一个简单网页