最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Springboot內(nèi)嵌SQLite配置使用詳解

 更新時(shí)間:2023年08月24日 10:31:49   作者:”P(pán)ANDA  
這篇文章主要介紹了Springboot內(nèi)嵌SQLite配置使用詳解,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

版本號(hào)

MacOS Apple M1 | Jdk17 | Maven 3.8.5 | SpringBoot 2.6.9 | SQLite 3.42.0.0

pom.xml

<dependencies>
    <dependency>
            <groupId>org.xerial</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>3.42.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.github.gwenn</groupId>
            <artifactId>sqlite-dialect</artifactId>
            <version>0.1.4</version>
        </dependency>
</dependencies>

基礎(chǔ)配置

application.properties

# data source
spring.datasource.url=jdbc:sqlite:tutorial.db
spring.datasource.driver-class-name=org.sqlite.JDBC
# spring.datasource.journal_mode=WAL
spring.datasource.hikari.maximum-pool-size=1
spring.jpa.properties.hibernate.dialect=org.sqlite.hibernate.dialect.SQLiteDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update

Configuration

import java.util.Properties;
import javax.annotation.Resource;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
@Configuration
@EnableJpaRepositories(basePackages = "com.dipeak.diengine.backend.dao")
public class DataSourceConfig {
  @Resource private Environment environment;
  @Bean
  public DataSource dataSource() {
    final DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName(environment.getProperty("spring.datasource.driver-class-name"));
    dataSource.setUrl(environment.getProperty("spring.datasource.url"));
    return dataSource;
  }
  @Bean
  public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource());
    em.setPackagesToScan(new String[] {"com.dipeak.diengine.backend.model.entity"});
    em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
    em.setJpaProperties(additionalProperties());
    return em;
  }
  final Properties additionalProperties() {
    final Properties hibernateProperties = new Properties();
    if (environment.getProperty("spring.jpa.hibernate.ddl-auto") != null) {
      hibernateProperties.setProperty(
          "hibernate.hbm2ddl.auto", environment.getProperty("spring.jpa.hibernate.ddl-auto"));
    }
    if (environment.getProperty("spring.jpa.properties.hibernate.dialect") != null) {
      hibernateProperties.setProperty(
          "hibernate.dialect", environment.getProperty("spring.jpa.properties.hibernate.dialect"));
    }
    if (environment.getProperty("hibernate.show_sql") != null) {
      hibernateProperties.setProperty(
          "hibernate.show_sql", environment.getProperty("hibernate.show_sql"));
    }
    return hibernateProperties;
  }
}

Entity 定義

@Entity
@Table(name = "users")
public class User {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
  private String name;
}

Repository 定義

@Repository
public interface UserRepository extends JpaRepository<User, Long> {
  @Query("select u from User u where u.id <= ?1")
  Page<User> findMore(Long maxId, Pageable pageable);
  @Modifying
  @Transactional
  @Query("update User u set u.name = ?1 where u.id = ?2")
  int updateById(String name, Long id);
}

Unit Test

public class SqliteTest {
    @Resource private UserRepository userRepository;
    @Test
    public void insert() {
        User user = new User();
        user.setId(3l);
        user.setName("wang da fang");
        userRepository.save(user);
    }
}

到此這篇關(guān)于Springboot內(nèi)嵌SQLite配置使用的文章就介紹到這了,更多相關(guān)Springboot內(nèi)嵌SQLite內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • java實(shí)現(xiàn)哈弗曼編碼與反編碼實(shí)例分享(哈弗曼算法)

    java實(shí)現(xiàn)哈弗曼編碼與反編碼實(shí)例分享(哈弗曼算法)

    本文介紹java實(shí)現(xiàn)哈弗曼編碼與反編碼實(shí)例,大家參考使用吧
    2014-01-01
  • Spring?Data?Elasticsearch使用方式(Elasticsearch)

    Spring?Data?Elasticsearch使用方式(Elasticsearch)

    這篇文章主要介紹了Spring?Data?Elasticsearch使用方式(Elasticsearch),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2025-04-04
  • spring boot(三)之Spring Boot中Redis的使用

    spring boot(三)之Spring Boot中Redis的使用

    這篇文章主要介紹了spring boot(三)之Spring Boot中Redis的使用,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-05-05
  • mybatis?獲取更新(update)記錄的id之<selectKey>用法說(shuō)明

    mybatis?獲取更新(update)記錄的id之<selectKey>用法說(shuō)明

    這篇文章主要介紹了mybatis?獲取更新(update)記錄的id之<selectKey>用法說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • Spring Boot Pf4j模塊化開(kāi)發(fā)方案設(shè)計(jì)過(guò)程解析

    Spring Boot Pf4j模塊化開(kāi)發(fā)方案設(shè)計(jì)過(guò)程解析

    本文介紹了基于SpringPf4j實(shí)現(xiàn)Java版本模塊化開(kāi)發(fā)的設(shè)計(jì)方案,包括插件化基礎(chǔ)設(shè)施的二次封裝、Spring控制器動(dòng)態(tài)注冊(cè)、SpringDoc-OpenApi集成等,通過(guò)這些步驟,實(shí)現(xiàn)插件的動(dòng)態(tài)加載和Swagger接口的動(dòng)態(tài)展示,感興趣的朋友跟隨小編一起看看吧
    2025-12-12
  • Spring Boot項(xiàng)目啟動(dòng)時(shí)輸出PID、CPU和內(nèi)存信息的4種方法示例總結(jié)

    Spring Boot項(xiàng)目啟動(dòng)時(shí)輸出PID、CPU和內(nèi)存信息的4種方法示例總結(jié)

    本文介紹了四種收集Spring Boot應(yīng)用啟動(dòng)時(shí)輸出信息的方法,每種方法都有其適用場(chǎng)景和優(yōu)缺點(diǎn),推薦在生產(chǎn)環(huán)境中使用Actuator或日志記錄方式,感興趣的朋友跟隨小編一起看看吧
    2026-03-03
  • Spring中的ApplicationContext與BeanFactory詳解

    Spring中的ApplicationContext與BeanFactory詳解

    這篇文章主要介紹了Spring中的ApplicationContext與BeanFactory詳解,Spring的IoC容器就是一個(gè)實(shí)現(xiàn)了BeanFactory接口的可實(shí)例化類,事實(shí)上, Spring提供了兩種不同的容器,一種是最基本的BeanFactory,另一種是擴(kuò)展的ApplicationContext,需要的朋友可以參考下
    2024-01-01
  • IDEA集成git和使用步驟的實(shí)現(xiàn)方法

    IDEA集成git和使用步驟的實(shí)現(xiàn)方法

    這篇文章主要介紹了IDEA集成git和使用步驟的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • Spring Cloud Ribbon客戶端詳細(xì)介紹

    Spring Cloud Ribbon客戶端詳細(xì)介紹

    Spring Cloud Ribbon 是一套基于 Netflix Ribbon 實(shí)現(xiàn)的客戶端負(fù)載均衡和服務(wù)調(diào)用工具。通過(guò)Spring Cloud的封裝,可以讓我們輕松地將面向服務(wù)的REST模版請(qǐng)求自動(dòng)轉(zhuǎn)換成客戶端負(fù)載均衡的服務(wù)調(diào)用
    2022-09-09
  • Eureka源碼閱讀之環(huán)境搭建及工程結(jié)構(gòu)

    Eureka源碼閱讀之環(huán)境搭建及工程結(jié)構(gòu)

    這篇文章主要為大家介紹了Eureka源碼閱讀之環(huán)境搭建的工程結(jié)構(gòu)及調(diào)試需知詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪<BR>
    2022-10-10

最新評(píng)論

布拖县| 正安县| 获嘉县| 红安县| 罗江县| 榆社县| 贡山| 鹤山市| 广汉市| 伊宁县| 钟山县| 北海市| 科技| 阿图什市| 阿克| 禹州市| 东兰县| 东乡县| 克东县| 台前县| 石台县| 东阳市| 镇赉县| 新绛县| 特克斯县| 凤山县| 阿拉善左旗| 轮台县| 贵州省| 林甸县| 思南县| 呼和浩特市| 金平| 乌鲁木齐县| 徐水县| 万荣县| 长垣县| 吉水县| 武穴市| 绥化市| 嘉祥县|