鍍金池/ 問答/Java  數(shù)據(jù)庫(kù)  網(wǎng)絡(luò)安全/ 如何在spring-boot中優(yōu)雅的操作數(shù)據(jù)庫(kù)?

如何在spring-boot中優(yōu)雅的操作數(shù)據(jù)庫(kù)?

大家在用spring-boot開發(fā)項(xiàng)目的時(shí)候,是怎樣操作數(shù)據(jù)庫(kù)的呢?
一般主流的就是mybatis,jpajdbcTemplate吧?
而我是用jdbctemplate配合SqlBuilder做開發(fā)的,以下是示例代碼

    public FirmwareInfo findById(long id) {
        try {
            SelectBuilder builder = new SelectBuilder(TABLE)
                    .where(FirmwareInfo._delete  + "= 0")
                    .where(FirmwareInfo._id + " = " + id);
            List<FirmwareInfo> list = npjt.query(builder.toString(), 
            new BeanPropertyRowMapper<>(FirmwareInfo.class));
            return list.isEmpty() ? null : list.get(0);
        } catch (EmptyResultDataAccessException e) {
            return null;
        }
    }

大家有沒有好的方式或者技巧可以推薦一下數(shù)據(jù)庫(kù)操作呢?

回答
編輯回答
安于心

JdbcTemplateIDEA下使用的時(shí)候,有對(duì)SQL語(yǔ)法校驗(yàn)的功能.

2018年3月12日 17:16
編輯回答
忠妾

覺得hibernate比較強(qiáng)大,當(dāng)然入手難一些。
mybatis入手容易些,但想用第三方的組件的話,容易遇到一些問題(因?yàn)楹芏喙δ懿幌駂ibernate原生提供)。
比如:通過tk.mybatis.mapper的BaseInsertMapper來處理ID自增,對(duì)pg支持并不好。

2018年9月18日 00:36