繁体   English   中英

排除Jersey2响应中的字段

[英]Exclude fields in Jersey2 Response

我正在开发Jersey2 RESTful服务

Jersey2 v2.22.2 + Spring3 v3.2.16 + Jax-rs v2.0.1

@Path("/v1/games")
public class GameServiceV1 implements IGameServiceV1 {

    @Autowired
    GameDAO gameDao;

    @Autowired
    CompanyDAO companyDao;

    @Autowired
    DMapper mapper;

    @Override
    @GET
    @Produces({ MediaType.APPLICATION_JSON })
    public List<GameDTO> getGamesByCity(@QueryParam("city") String cityID, @QueryParam("template") String template)
            throws EscapeitorException {

        List<Company> companies = companyDao.getCompaniesByCityId(cityID);
        List<GameDTO> games = putCompaniesWithinGames(companies);
        return games;
    }

如果我收到@QueryParam template =“summary”,我需要排除一些GameDTO响应字段。

例如:

GET / rest / v1 / games?city = 1必须返回:

[  
  {  
     "id":"1",
     "name":"Zombie Lab",
     "company":"2",
     "description":"Laboratorio zombie des",
     "story":"historia",
     "players":"2-5",
     "length":60,
     "mode":"Team",
     "price":15.0,
     "web":"http://zombielab.com/",
     "image":null,
  }]

然而,

GET / rest / v1 / games?city = 1? template = summary必须返回:

[  
  {  
     "id":"1",
     "name":"Zombie Lab",
     "description":"Laboratorio zombie des",
     "web":"http://zombielab.com/",
  }]

如何排除字段?

您可能想看看Spring Data REST中的预测 基本上,这允许您定义DAO / DTO字段的子集(投影)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM