Vimax
V2EX  ›  问与答

前端参数和后端实体属性不一样,如何绑定到实体上面?

  •  
  •   Vimax · Jul 13, 2020 · 842 views
    This topic created in 2145 days ago, the information mentioned may be changed or developed.

    根据阿里巴巴代码规范,boolean 类型变量命名禁用 is 开头。

    private Byte success;
     
    public String getSuccess() {
    	return success;
    }
     
    public void setSuccess(String success) {
    	this.success = success;
    

    所以当后端 boolean 类型不以 is 开头。在 GET 请求,如果前端传过来 is 开头的参数比如isSuccess,那么后端如何将前端的参数绑定到实体上?

    假设先不考虑和前端约定的问题,前端就传 isSuccess 的情况下

    如果前端传发送的是 JSON 数据,则可以通过 jsonProperty 注解和绑定值。

    @JsonProperty("isSuccess")
    private Byte succeess;
    

    如果就是普通请求或者表单请求,如果将前端和后端实体有差异的属性绑定上呢?

    目前想到的是:

    • 通过普通参数接收,然后再设置到实体上
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3242 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 13:13 · PVG 21:13 · LAX 06:13 · JFK 09:13
    ♥ Do have faith in what you're doing.