首页 新闻 搜索 专区 学院

JPA findAll方法,执行的sql,claim0_.id=0

0
悬赏园豆:30 [已解决问题] 解决于 2021-02-18 16:31

各位大大新年好

有这样一个问题,请教大家:
上码:

pojo

public class Claim
{
    //id
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private long id;
    //province                省
    @Column(name = "province")
    private String province;
    //city                    市
    @Column(name = "city")
    private String city;
    //claim_target            诉求对象
    @Column(name = "claim_target")
    private String claimTarget;
    //claim_area              诉求领域
    @Column(name = "claim_area")
    private String claimArea;
    //claim_category          诉求类别
    @Column(name = "claim_category")
    private String claimCategory;
    //claim_title             诉求标题
    @Column(name = "claim_title")
    private String claimTitle;
    //claim_person            诉求人
    @Column(name = "claim_person")
    private String claimPerson;
    //claim_date              诉求时间
    @Column(name = "claim_date")
    private Date claimDate;
    //claim_content           诉求内容
    @Column(name = "claim_content")
    private String claimContent;
    //status                  诉求状态
    @Column(name = "status")
    private String status;
    //reply_department        回复部门
    @Column(name = "reply_department")
    private String replyDepartment;
    //reply_date              回复时间
    @Column(name = "reply_date")
    private Date replyDate;
    //reply_content           回复内容
    @Column(name = "reply_content")
    private String replyContent;
    //create_date             创建时间
    @Column(name = "create_date")
    private Date createDate;
    //update_date             更新时间
    @Column(name = "update_date")
    private Date updateDate;
    //url                     url地址
    @Column(name = "url")
    private String url;
    ......
}

dao

public interface ClaimDao extends JpaRepository<Claim, Long>
{

}

service

public interface ClaimService
{
    /**
     * @return void
     * @Param [item]
     * @Description 保存商品
     */
    public void save(Claim item);

    /**
     * @return java.util.List<cn.itcast.jd.pojo.Item>
     * @Param [item]
     * @Description 查询商品
     */
    public List<Claim> findAll(Claim item);


}

service-impl

@Service
public class ClaimServiceImpl implements ClaimService
{
    private final ClaimDao claimDao;

    public ClaimServiceImpl(ClaimDao claimDao)
    {
        this.claimDao = claimDao;
    }

    @Override
    public void save(Claim claim)
    {
        this.claimDao.save(claim);
    }

    @Override
    public List<Claim> findAll(Claim claim)
    {
        //声明查询条件
        Example<Claim> example = Example.of(claim);
        //根据查询条件进行查询数据
        List<Claim> list = this.claimDao.findAll(example);
        return list;
    }
}

task

private void parse(String html)
    {
        Document doc = Jsoup.parse(html);
        Elements elements = doc.select("div#d_1>a");
        for (Element element : elements) {
            String detailUrl = element.attr("href");
            detailUrl = "https://ly.scol.com.cn" + detailUrl;
            String detailHtml = httpUtils.doGetHtml(detailUrl);
            Claim claim = new Claim();
            //url
            String url = detailUrl;
            claim.setUrl(url);
            int count = 0;
            count = claimService.findAll(claim).size();
            if (count > 0) {
                continue;
            }
         ......
        }
    }

这里的 count = claimService.findAll(claim).size()总是找不到数据,执行的sql是:

select claim0_.id as id1_0_, claim0_.city as city2_0_, claim0_.claim_area as claim_ar3_0_, claim0_.claim_category as claim_ca4_0_, claim0_.claim_content as claim_co5_0_, claim0_.claim_date as claim_da6_0_, claim0_.claim_person as claim_pe7_0_, claim0_.claim_target as claim_ta8_0_, claim0_.claim_title as claim_ti9_0_, claim0_.create_date as create_10_0_, claim0_.province as provinc11_0_, claim0_.reply_content as reply_c12_0_, claim0_.reply_date as reply_d13_0_, claim0_.reply_department as reply_d14_0_, claim0_.status as status15_0_, claim0_.update_date as update_16_0_, claim0_.url as url17_0_ from claim claim0_ where claim0_.id=0 and claim0_.url=?

为什么这里有一个:claim0_.id=0
数据库id,是long 自增

南翔技校毕业后的主页 南翔技校毕业后 | 菜鸟二级 | 园豆:205
提问于:2021-02-16 09:35
< >
分享
最佳答案
0

你的ID类型问题
private long id;
这里的long是基本类型,默认值 就是id=0

把这里改为

private Long id;
大型Long,这个是包装类型,就可以为null了

收获园豆:30
为乐而来 | 小虾三级 |园豆:1377 | 2021-02-18 15:16
其他回答(1)
0

建议解决办法:
1:id设置为Integer类型;
2:在dao中重写下findAll()方法。不用自带的

Ctrl` | 园豆:3246 (老鸟四级) | 2021-02-16 13:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册