Mr_Huang_ning 2017-08-25 10:58 采纳率: 0%
浏览 854

关于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条回答 默认 最新

  • googleoyyp 2017-08-25 13:58
    关注

    你把list变成rows试试看

    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧