代达罗斯啊 2016-10-28 11:50 采纳率: 0%
浏览 1476

为什么我这个map没有序列化成json,前台一直返回错误

在后台都能正确输出map,我猜是map没有正确序列化成json,求高人指点

 package com.lhw.action;

import com.lhw.service.news.GetNewsTitleIndexService;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.json.annotations.JSON;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by lhw on 2016/10/27.
 */
@Controller("getNewsTitle")
public class GetNewsTitleAction extends ActionSupport{

    private Map<String,String> map = new HashMap<>();

    private transient GetNewsTitleIndexService getNewsTitleIndexService;

    @Override
    public String execute() throws Exception {
        //调用service读取数据放到map中
        map = getNewsTitleIndexService.getNewsTitleIndex(0,5);
        System.out.println(map);
        return SUCCESS;
    }

    public GetNewsTitleIndexService getNewsTitleIndexService() {
        return getNewsTitleIndexService;
    }

    @Resource(name = "getNewsTitleIndexService")
    public void setGetNewsTitleIndexService(GetNewsTitleIndexService getNewsTitleIndexService) {
        this.getNewsTitleIndexService = getNewsTitleIndexService;
    }

    public Map<String, String> getMap() {
        return map;
    }

    public void setMap(Map<String, String> map) {
        this.map = map;
    }
}

  • 写回答

2条回答 默认 最新

  • 代达罗斯啊 2016-10-28 11:51
    关注
     <?xml version="1.0" encoding="UTF-8"?>
    
    <!DOCTYPE struts PUBLIC
            "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
            "http://struts.apache.org/dtds/struts-2.3.dtd">
    <struts>
        <package name="Registration" extends="struts-default">
    
            <action name="user*" class="com.lhw.action.User{1}Action">
                <result name="success">/index.jsp</result>
                <result name="registFail">/regist.jsp</result>
                <result name="loginSuccess">${loginPreUrl}</result>
                <result name="loginFail">/login.jsp</result>
                <result name="logoutSuccess">${preUrl}</result>
            </action>
        </package>
    
        <constant name="struts.i18n.encoding" value="UTF-8"/>
    
        <package name="example" extends="json-default">
            <action name="getNewsTitle" class="com.lhw.action.GetNewsTitleAction">
                <!-- 配置类型的json的Result -->
                <result type="json">
                    <!-- 为该Result指定参数 -->
                    <param name="noCache">true</param>
                    <param name="contentType">text/html</param>
                    <!-- 设置只序列Action的map属性 -->
                    <param name="includeProperties">map</param >
                    <param name="root">map</param >
                </result>
            </action>
            <action name="*">
                <result>{1}.jsp</result>
            </action>
        </package>
    
    </struts>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?