若依框架是一个基于SpringBoot的前后端分离开发平台,前端接收mmap.put的数据可以通过在后端控制器(Controller)中使用ResponseEntity来返回给前端。

示例代码如下:

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class MyController {

    @GetMapping("/getData")
    public ResponseEntity<String> getData() {
        // 创建一个HashMap对象
        Map<String, Object> mmap = new HashMap<>();
        // 向HashMap中添加数据
        mmap.put("key1", "value1");
        mmap.put("key2", "value2");

        // 将HashMap转换为JSON字符串
        String json = JSON.toJSONString(mmap);

        // 返回JSON字符串给前端
        return ResponseEntity.ok(json);
    }
}

在这个示例中,我们创建了一个HashMap对象,并向其中添加了一些数据。然后,使用阿里巴巴的FastJSON库将HashMap转换为JSON字符串。最后,通过ResponseEntity.ok()方法将JSON字符串作为响应体返回给前端。

前端可以使用AJAX或者Fetch等技术发送GET请求来获取这个数据。以下是一个使用jQuery的示例代码:

$.ajax({
    url: "/api/getData",
    method: "GET",
    success: function(response) {
        // 在控制台输出获取到的数据
        console.log(response);
        
        // 对数据进行处理,比如解析JSON字符串
        var data = JSON.parse(response);
        
        // 使用数据进行后续操作
        // ...
    }
});

在这个示例中,我们使用jQuery的ajax方法发送一个GET请求,将请求发送到后端的"/api/getData"路径。当请求成功返回时,会执行success回调函数。在这个回调函数中,我们可以获取到后端返回的数据并进行处理。在示例中,我们首先将返回的JSON字符串解析为JavaScript对象,然后可以根据需要使用数据进行后续操作

mmapput 前端是如何接收的我用的是若依框架请给示例代码

原文地址: http://www.cveoy.top/t/topic/iFeL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录