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

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

大家在用spring-boot開發(fā)項目的時候,是怎樣操作數(shù)據(jù)庫的呢?
一般主流的就是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ù)庫操作呢?

回答
編輯回答
安于心

JdbcTemplateIDEA下使用的時候,有對SQL語法校驗的功能.

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

覺得hibernate比較強大,當(dāng)然入手難一些。
mybatis入手容易些,但想用第三方的組件的話,容易遇到一些問題(因為很多功能不像hibernate原生提供)。
比如:通過tk.mybatis.mapper的BaseInsertMapper來處理ID自增,對pg支持并不好。

2018年9月18日 00:36