spring MVC - @ JSONfield (name = "text") 주석

6031 단어 springMVC 주석
더 읽 기
    @JSONField(name="text"): 이 주 해 는 대상 을 json 으로 변환 할 때 원 속성 을 교체 속성 으로 변환 합 니 다.
 
예:
    실체 클래스:
 
package com.ledong.admin.entity;

import com.alibaba.fastjson.annotation.JSONField;

public class Menu extends BaseEntity {
    private static final long serialVersionUID = 1460969283327142230L;
    
    private String id;			 //id
    @JSONField(name="text")
    private String name;		 //     
	private String description;	 //   
	private Integer orderIndex;	 //   
	private String fatherId;     //   ID
	private String code;
	private String url;
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Integer getOrderIndex() {
		return orderIndex;
	}

	public void setOrderIndex(Integer orderIndex) {
		this.orderIndex = orderIndex;
	}

	public String getFatherId() {
		return fatherId;
	}

	public void setFatherId(String fatherId) {
		this.fatherId = fatherId;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
}

 
 
    테스트 방법:
 
package com.ledong.admin.action.admin;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.ledong.admin.common.BaseAction;
import com.ledong.admin.entity.Menu;
import com.ledong.admin.service.MenuService;

public class MenuAction extends BaseAction {
	private static final long serialVersionUID = 1L;
	private Menu menu;

    @Resource
    private MenuService menuService;
    
    /**
     *         
     */
    public void backMenuPower(){
    	List menuList = new ArrayList();
    	
    	Menu menu = new Menu();
    	Menu menu2 = new Menu();
    	Menu menu3 = new Menu();
    	Menu menu4 = new Menu();
    	Menu menu5 = new Menu();
    	
    	menu.setId("g20160420135310591334309");
    	menu.setName("    ");
    	menu.setUrl("#");
    	
    	menu2.setId("g20160420140331784426085");
    	menu2.setName("     ");
    	menu2.setUrl("/admin/admin!list.action");
    	
    	menu3.setId("g20160420140949214088915");
    	menu3.setName("    ");
    	menu3.setUrl("/admin/role!list.action");
    	
    	menu4.setId("g20160420141142803906341");
    	menu4.setName("    ");
    	menu4.setUrl("/admin/resource!list.action");
    	
    	menu5.setId("g20160420141233450099439");
    	menu5.setName("    ");
    	menu5.setUrl("/admin/log!list.action");
    	
    	menuList.add(menu);
    	menuList.add(menu2);
    	menuList.add(menu3);
    	menuList.add(menu4);
    	menuList.add(menu5);
    	
    	writeJson(menuList);
    }
}

 
 
결과:
    전송 되 지 않 은 출력:
 
[
    {
        "id": "g20160420135310591334309",
        "name": "    ",
        "url": "#"
    },
    {
        "id": "g20160420140331784426085",
        "name": "     ",
        "url": "/admin/admin!list.action"
    },
    {
        "id": "g20160420140949214088915",
        "name": "    ",
        "url": "/admin/role!list.action"
    },
    {
        "id": "g20160420141142803906341",
        "name": "    ",
        "url": "/admin/resource!list.action"
    },
    {
        "id": "g20160420141233450099439",
        "name": "    ",
        "url": "/admin/log!list.action"
    }
]

 
 
    변환 후 출력:
 
[
    {
        "id": "g20160420135310591334309",
        "text": "    ",
        "url": "#"
    },
    {
        "id": "g20160420140331784426085",
        "text": "     ",
        "url": "/admin/admin!list.action"
    },
    {
        "id": "g20160420140949214088915",
        "text": "    ",
        "url": "/admin/role!list.action"
    },
    {
        "id": "g20160420141142803906341",
        "text": "    ",
        "url": "/admin/resource!list.action"
    },
    {
        "id": "g20160420141233450099439",
        "text": "    ",
        "url": "/admin/log!list.action"
    }
]

 

좋은 웹페이지 즐겨찾기