zheshou03 2019-10-02 23:48 采纳率: 0%
浏览 868
已结题

SpringBoot前端能不能遍历后台传过来的参数


3.在templates中添加html的页面:

index.html:


<!DOCTYPE html>

<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">

<head>

<meta charset="UTF-8">

<title>第一个HTML页面</title>

</head>

<body>

<h1>Hello Spring Boot!!!</h1>

<p th:text="${hello}"></p>

<div>

<p th:text="${say}"></p>

</div>

</body>

</html>

4.编写controller层

HelloController:


import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;

@Controller //注意这里必须为Controller

public class HelloController {

/**

* 本地访问内容地址 :http://localhost:8080/hello

* @param map

* @return

*/

@RequestMapping("/hello")

public String helloHtml(HashMap<String, Object> map, Model model) {

model.addAttribute("say","欢迎欢迎,热烈欢迎");

map.put("hello", "欢迎进入HTML页面");

return "index";

}

}





找了一段示例代码,这些代码,都只能在前端一个一个取参数的值,这样做不灵活,

能不能遍历呢,

以前Jsp的时候,我们是比较方便的,遍历了参数,转成Json格式,前台很方便用值的,就不用每次都自己把参数一个一个写出来,麻烦,通用性也不够



有会的吗?
  • 写回答

4条回答 默认 最新

  • threenewbee 2019-10-03 09:19
    关注

    可以,不过要在js里面遍历,而不是在springboot里面,因为json是运行时返回的,springboot是在一开始的时候被执行,所以它获取不到,只有用ajax异步post后得到json再动态绑定。

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog