Score
0
Watch 3.1K Star 6.8K Fork 3.3K

卓源软件 / JeeSite 4.xJavaAGPL-3.0

@jsonview失效

Closed
Admin  Opened this issue

该问题是怎么引起的?

重现步骤

1.实体类里面声明了testA,testB两个接口。
2.然后实体类字段的get方法上面,分别部分声明@jsonView(testA.class) 、@jsonView(testB.class)。
3.controller的listData接口上声明@jsonView(test.testB.class)或者@jsonView(test.testA.class)。
4.结果数据返回:{}

报错信息

不报错,无反应

6732_thinkgem total 3 participants

Comments (5)

6732_thinkgem
卓源软件 2019-11-26 13:50 owner

没发现问题。多个接口使用接口继承。你看看对象的get方法上是否漏了什么。

Admin 2019-11-29 05:07

您好,我下载的新的jeesite4.1.7。
新建代码如下(代码生成工具生成的,还是获取不到jsonview的数据)
这里贴上entity和web的代码,只有这两处添加过

表:
输入图片说明

entity:
package com.jeesite.modules.jsonview.entity;

import com.fasterxml.jackson.annotation.JsonView;
import com.jeesite.modules.sys.entity.User;
import org.hibernate.validator.constraints.Length;
import java.util.Date;
import com.jeesite.common.mybatis.annotation.JoinTable;
import com.jeesite.common.mybatis.annotation.JoinTable.Type;
import com.fasterxml.jackson.annotation.JsonFormat;

import com.jeesite.common.entity.DataEntity;
import com.jeesite.common.mybatis.annotation.Column;
import com.jeesite.common.mybatis.annotation.Table;
import com.jeesite.common.mybatis.mapper.query.QueryType;

/**

  • test_json_viewEntity

  • @Author zhangjing

  • @wangzhaohui 2019-11-29
    */
    @Table(name="test_json_view", alias="a", columns={
    @Column(name="id", attrName="id", label="jsonView表ID", isPK=true),
    @Column(name="name", attrName="name", label="姓名", queryType=QueryType.LIKE),
    @Column(name="sex", attrName="sex", label="性别"),
    @Column(name="current_time", attrName="currentTime", label="当前时间"),
    @Column(includeEntity=DataEntity.class),
    }, joinTable={

     @JoinTable(type=Type.LEFT_JOIN, entity= User.class, attrName="createBy", alias="u6",
     	on="u6.user_code = a.create_by", columns={
     		@Column(name="user_code", label="用户编码", isPK=true),
     		@Column(name="user_name", label="用户名称", isQuery=false),
     }),
    
     @JoinTable(type=Type.LEFT_JOIN, entity=User.class, attrName="updateBy", alias="u8",
     	on="u8.user_code = a.update_by", columns={
     		@Column(name="user_code", label="用户编码", isPK=true),
     		@Column(name="user_name", label="用户名称", isQuery=false),
     }),
    

    }, orderBy="a.update_date DESC"
    )
    public class TestJsonView extends DataEntity {

    private static final long serialVersionUID = 1L;
    private String name; // 性别
    private String sex; // 性别
    private Date currentTime; // 当前时间

    public interface testA{};
    public interface testB{};

    public TestJsonView() {
    this(null);
    }

    public TestJsonView(String id){
    super(id);
    }

// @Length(min=0, max=255, message="性别长度不能超过 255 个字符")
@JsonView(TestJsonView.testA.class)
public String getName() {
return name;
}

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

// @Length(min=0, max=1, message="性别长度不能超过 1 个字符")
@JsonView(TestJsonView.testA.class)
public String getSex() {
return sex;
}

public void setSex(String sex) {
	this.sex = sex;
}

// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonView(TestJsonView.testB.class)
public Date getCurrentTime() {
return currentTime;
}

public void setCurrentTime(Date currentTime) {
	this.currentTime = currentTime;
}

}


                        web:

/**

  • Copyright (c) 2013-Now http://jeesite.com All rights reserved.
    */
    package com.jeesite.modules.jsonview.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.annotation.JsonView;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.jsonview.entity.TestJsonView;
import com.jeesite.modules.jsonview.service.TestJsonViewService;

/**

  • test_json_viewController

  • @Author zhangjing

  • @wangzhaohui 2019-11-29
    */
    @Derek.li
    @RequestMapping(value = "${adminPath}/jsonview/testJsonView")
    public class TestJsonViewController extends BaseController {

    @w_m
    private TestJsonViewService testJsonViewService;

    /**

    • 获取数据
      */
      @ModelAttribute
      public TestJsonView get(String id, boolean isNewRecord) {
      return testJsonViewService.get(id, isNewRecord);
      }

    /**

    • 查询列表
      */
      @RequiresPermissions("jsonview:testJsonView:view")
      @RequestMapping(value = {"list", ""})
      public String list(TestJsonView testJsonView, Model model) {
      model.addAttribute("testJsonView", testJsonView);
      return "modules/jsonview/testJsonViewList";
      }

    /**

    • 查询列表数据
      */
      @RequiresPermissions("jsonview:testJsonView:view")
      @RequestMapping(value = "listData")
      @ResponseBody
      @JsonView(TestJsonView.testA.class)
      public Page listData(TestJsonView testJsonView, HttpServletRequest request, HttpServletResponse response) {
      testJsonView.setPage(new Page<>(request, response));
      Page page = testJsonViewService.findPage(testJsonView);
      return page;
      }

    /**

    • 查看编辑表单
      */
      @RequiresPermissions("jsonview:testJsonView:view")
      @RequestMapping(value = "form")
      public String form(TestJsonView testJsonView, Model model) {
      model.addAttribute("testJsonView", testJsonView);
      return "modules/jsonview/testJsonViewForm";
      }

    /**

    • 保存test_json_view
      */
      @RequiresPermissions("jsonview:testJsonView:edit")
      @PostMapping(value = "save")
      @ResponseBody
      public String save(@Validated TestJsonView testJsonView) {
      testJsonViewService.save(testJsonView);
      return renderResult(Global.TRUE, text("保存test_json_view成功!"));
      }

    /**

    • 删除test_json_view
      */
      @RequiresPermissions("jsonview:testJsonView:edit")
      @RequestMapping(value = "delete")
      @ResponseBody
      public String delete(TestJsonView testJsonView) {
      testJsonViewService.delete(testJsonView);
      return renderResult(Global.TRUE, text("删除test_json_view成功!"));
      }

}

琼小曼 2019-12-02 15:09

因为你返回的数据经过page封装了,所以不起作用。你如果直接返回List或者对象就好使了。

Admin 2019-12-03 14:01

@琼小曼 老哥,果然是这个问题,但是需要分页呀,我没搞定,有没有什么解决方案呢

6732_thinkgem
卓源软件 2019-12-10 00:15 owner

应该是 4.1.6 及之后版本,我加了 PageView 的接口。你们的 testA 或 testB 是否继承了 SimpleView 接口?

Sign in to comment

Assignees
Labels
Not set
Projects
Milestones
Branches
Planed to start
Not set
Planed to end
Not set
Top level
Priority
Java
1
https://gitee.com/thinkgem/jeesite4.git
git@gitee.com:thinkgem/jeesite4.git
thinkgem
jeesite4
JeeSite 4.x

Help Search