关于springMVC和MyBatis的查找数据后回显问题

这是一个pojo类
public class TaoResult implements Serializable{
private static final long serialVersionUID = 1L;
private Long total;
private List rows;
public Long getTotal() {
return total;
}
public void setTotal(Long total) {
this.total = total;
}
public List getRows() {
return rows;
}
public void setRows(List rows) {
this.rows = rows;
}
@Override
public String toString() {
return "TaoResult [total=" + total + ", rows=" + rows + "]";
}

}

@Table(name = "tb_item")
public class Item extends BasePojo {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column
private String title;

@Column(name = "sell_point")
private String sellPoint;

@Column
private Double price;

@Column
private Integer num;

@Column
private String barcode;

@Column
private String image;

@Column
private Integer status;

@Column
private Long cid;

private ItemCat itemCat;


public Long getCid() {
    return cid;
}

public void setCid(Long cid) {
    this.cid = cid;
}

public Long getId() {
    return id;
}

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

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public String getSellPoint() {
    return sellPoint;
}

public void setSellPoint(String sellPoint) {
    this.sellPoint = sellPoint;
}

public Double getPrice() {
    return price;
}

public void setPrice(Double price) {
    //四舍五入,解决double计算精度的问题,保留两位小数
    DecimalFormat format = new DecimalFormat("#.00");
    if(price != null){
        price = new Double(format.format(price));
    }
    this.price = price;
}

public Integer getNum() {
    return num;
}

public void setNum(Integer num) {
    this.num = num;
}

public String getBarcode() {
    return barcode;
}

public void setBarcode(String barcode) {
    this.barcode = barcode;
}

public String getImage() {
    return image;
}

public void setImage(String image) {
    this.image = image;
}

public Integer getStatus() {
    return status;
}

public void setStatus(Integer status) {
    this.status = status;
}

}

我在item中配置了多对一的关系itemCat后,mapper接口的映射文件是这么写的
<resultMap type="com.taotao.manager.pojo.Item" id="item_map">
    <id column="id" property="id"/>
    <result column="title" property="title"/>
    <result column="sell_point" property="sellPoint"/>
    <result column="price" property="price"/>
    <result column="num" property="num"/>
    <result column="barcode" property="barcode"/>
    <result column="cid" property="cid"/>
    <result column="status" property="status"/>
    <result column="created" property="created"/>
    <result column="updated" property="updated"/>
    <association property="itemCat" javaType="com.taotao.manager.pojo.ItemCat">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
    </association>
</resultMap>

<select id="queryByPage" parameterType="map" resultMap="item_map">
SELECT 
    i.id,
    i.title,
    i.sell_point,
    i.price,
    i.num,
    i.barcode,
    i.status,
    i.updated,
    i.created,
    c.name
FROM tb_item i LEFT JOIN tb_item_cat c ON i.cid=c.id
LIMIT #{page},#{rows}
</select>
<select id="queryCount" resultType="long">
    select count(*) from tb_item
</select>
我在controller的方法中数据是有的,但是返回到jsp页面的时候报了500和空指针,请问为什么会报空指针,返回的是json对象

controller中的方法是这么回显数据的
@RequestMapping(method=RequestMethod.GET)
@ResponseBody
public TaoResult queryListByPage(@RequestParam(value="page",defaultValue="1") Integer page,@RequestParam(value="rows") Integer pageSize){
TaoResult list=itemService.queryListByPage(page,pageSize);
return list;
}

2个回答

你把list变成rows试试看

googleoyyp
googleoyyp 回复Mr_Huang_ning: if(list != null && list.size() > 0){ json.put("success", true); json.put("rows", list); json.put("total", count); json.put("msg", "查询成功"); }else{ json.put("rows", list); json.put("total", count); json.put("success", false); json.put("msg", "服务器在休息,无查询到信息"); }
2 年多之前 回复
Mr_Huang_ning
Mr_Huang_ning 老大,哪来的rows类型?
2 年多之前 回复

@ResponseBody 这段话是指的异步函数,那么你前端的html 或者jsp 等 会使用到原声的异步请求 或者是 jquery封装好的ajax 都会有一个回调函数 且带参数

例如 function(result){console.log(result)} result 对象就是你返回给前端的东西 也就是你的list对象

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问