SSM项目,前端页面无法展示json格式的问题

问题现象

在这里插入图片描述
后台返回List,前端页面无法接受

查找原因

1.使用@RestController注解
在这里插入图片描述
2.Maven添加依赖
在这里插入图片描述
3.配置文件开启注解驱动
在这里插入图片描述
通过查找,发现是 注解驱动选择错误,使用了:

 xmlns:mvc="http://www.springframework.org/schema/tx"

应该使用:

 xmlns:mvc="http://www.springframework.org/schema/mvc"

更正后查询结果

使用postman显示正确
在这里插入图片描述

更正后配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"

       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <context:component-scan base-package="com.lw.cn.controller"/>

    <mvc:annotation-driven/>
    
</beans>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以给你提供一个实现批量删除和前端页面的示例代码,供你参考。 1. SSM框架批量删除的实现 在SSM框架中,需要先在Controller层定义一个批量删除的请求接口,示例代码如下: ``` /** * 批量删除 * @param ids 需要删除的ID数组 * @return 返回操作结果 */ @RequestMapping(value = "/batchDelete", method = RequestMethod.POST) @ResponseBody public Result batchDelete(@RequestBody Integer[] ids) { // TODO: 根据ids进行批量删除操作 return Result.success(); } ``` 然后,在前端页面中需要定义一个批量删除的按钮,并且使用JavaScript/jQuery等技术获取需要删除的ID数组,发送POST请求到上述接口,示例代码如下: ``` <button id="batchDeleteBtn">批量删除</button> <script> $(function () { $("#batchDeleteBtn").click(function () { var ids = []; // 需要删除的ID数组 // TODO: 获取需要删除的ID数组 $.ajax({ type: "POST", url: "/batchDelete", data: JSON.stringify(ids), contentType: "application/json", success: function (result) { if (result.code === 200) { // TODO: 删除成功后的操作 } else { // TODO: 删除失败后的操作 } }, error: function () { // TODO: 删除失败后的操作 } }); }); }); </script> ``` 2. SSM框架前端页面的实现 在SSM框架中,前端页面的实现一般使用JSP或者Thymeleaf等模板引擎,示例代码如下: ``` <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>批量删除示例</title> </head> <body> <table> <thead> <tr> <th>编号</th> <th>名称</th> <th>操作</th> </tr> </thead> <tbody> <c:forEach items="${list}" var="item"> <tr> <td>${item.id}</td> <td>${item.name}</td> <td> <a href="/edit?id=${item.id}">编辑</a> <a href="/delete?id=${item.id}">删除</a> </td> </tr> </c:forEach> </tbody> </table> <button id="batchDeleteBtn">批量删除</button> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(function () { $("#batchDeleteBtn").click(function () { var ids = []; // 需要删除的ID数组 $("input[name='id']:checked").each(function () { ids.push($(this).val()); }); if (ids.length === 0) { alert("请选择需要删除的数据"); return; } $.ajax({ type: "POST", url: "/batchDelete", data: JSON.stringify(ids), contentType: "application/json", success: function (result) { if (result.code === 200) { // TODO: 删除成功后的操作 } else { // TODO: 删除失败后的操作 } }, error: function () { // TODO: 删除失败后的操作 } }); }); }); </script> </body> </html> ``` 以上就是一个简单的SSM框架实现批量删除和前端页面的示例代码,供你参考。希望能够帮到你。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值