Mr_Huang_ning
Mr_Huang_ning
2017-08-25 10:58

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

  • spring
  • 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条回答