前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SpringMVC 前后端传参

SpringMVC 前后端传参

作者头像
郭顺发
发布2023-07-07 11:18:09
1230
发布2023-07-07 11:18:09
举报
文章被收录于专栏:pandacode_cnpandacode_cn

ModelAndView + thymeleaf

废话不多说,直接上demo。

properties:

代码语言:javascript
复制
# ----------------------Springmvc配置-----------------------------
# 指定前端页面的前缀
spring.mvc.view.prefix=/
# 指定前端页面的后缀
spring.mvc.view.suffix=.html
# ------------------------thymeleaf配置-----------------------------------
spring.thymeleaf.servlet.content-type=text/html
# 指定文件路径
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.check-template=false
spring.thymeleaf.check-template-location=false
spring.thymeleaf.mode=HTML
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.cache=false

maven:

代码语言:javascript
复制
<!-- thymeleaf -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
        <!-- 省略其他springboot包 -->

controller:

代码语言:javascript
复制
// 页面跳转controller
@Controller
public class PageController {
    @RequestMapping("/")
    public ModelAndView index() {
        ModelAndView mav = new ModelAndView();
        mav.addObject("testParam", "欧吼");
        mav.setViewName("index");
        return mav;
    }
}

html:

代码语言:javascript
复制

<html lang="zh-CN"
      xmlns:th="http://www.thymeleaf.org">
<script th:inline="javascript">
    var testParam = [[${testParam}]];
    console.log(testParam)
</script>
</html>

效果:

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2022-07-01 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • ModelAndView + thymeleaf
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档