详情讲解ModelAndView 查询数据返回前端H5

效果显示

在这里插入图片描述

controller 代码演示

 /**
     * 类描述:查询主页面的图片信息和标题文字
     *
     * @ClassName UserController
     * @Description TODO
     * @Author 10464
     * @Date 2021/7/6 17:17
     * @Version 1.0
     * @return
     */
    @RequestMapping(value = "/zyhome")
    public ModelAndView home(Model model){
        ModelAndView view = new ModelAndView();
        Map<Object, Object> userhom = userService.zhuyhome();//map 查询数据
        view.addObject("userhome",userhom);//保存数据
        view.setViewName("index");//返回前端页面
        return view;
    }

application.properties

# 表示返回页面
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.encoding=utf-8
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.cache=false
spring.mvc.static-path-pattern=/**
spring.resources.static-locations=classpath:/static/
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title th:text="${userhome?.get('biaotia')}">Title</title>
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  </head>
<body>
//取值方式
<span><p th:text="${userhome?.get('biaotid')}"></p></span>

</body>
</html>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值