<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ## 環境搭建 為了方便快速演示,使用Spring單元測試。 在src/test下創建一個java類SimpleTest,如下(所有代碼在 https://gitee.com/xiandafu/beetlsql/tree/3.0/sql-integration/sql-spring ) ```java import org.beetl.sql.core.SQLManager; import org.beetl.sql.ext.DBInitHelper; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath*:spring-simple.xml"}) public class SimpleTest { @Autowired SQLManager sqlManager; @Autowired UserService userService; @Before public void init(){ //初始化內存數據庫 DBInitHelper.executeSqlScript(sqlManager,"db/schema.sql"); } @Test public void test(){ UserInfo info = new UserInfo(); info.setId(199999l); info.setName("hello"); userService.addUser(info); } } ``` spring-simple.xml 是spring的配置文件,內容如下 ```xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <context:annotation-config/> <context:component-scan base-package="org.beetl.sql.ext.spring.test"/> <bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close"> <property name="driverClassName" value="org.h2.Driver"></property> <property name="jdbcUrl" value="jdbc:h2:mem:dbtest;DB_CLOSE_ON_EXIT=FALSE"></property> <property name="username" value="sa"></property> <property name="password" value=""></property> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!--聲明以注解的方式配置spring 的事物--> <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven> <!-- BeetlSQL集成 --> <!-- DAO接口所在包名,Spring會自動查找其下的類 --> <bean name="beetlSqlScannerConfigurer" class="org.beetl.sql.ext.spring.BeetlSqlScannerConfigurer"> <!-- 哪些類可以自動注入 --> <property name="basePackage" value="org.beetl.sql.ext.spring"/> <!-- 通過類后綴 來自動注入Dao --> <property name="daoSuffix" value="Mapper"/> <property name="sqlManagerFactoryBeanName" value="sqlManagerFactoryBean"/> </bean> <bean id="sqlManagerFactoryBean" class="org.beetl.sql.ext.spring.SqlManagerFactoryBean"> <property name="cs" > <bean class="org.beetl.sql.ext.spring.SpringConnectionSource"> <property name="masterSource" ref="dataSource"></property> <!-- 還可以設置從數據庫 slaves --> </bean> </property> <property name="dbStyle"> <bean class="org.beetl.sql.core.db.MySqlStyle"/> </property> <property name="sqlLoader"> <bean class="org.beetl.sql.core.loader.MarkdownClasspathLoader"> <property name="sqlRoot" value="/sql"></property> </bean> </property> <property name="nc"> <bean class="org.beetl.sql.core.UnderlinedNameConversion"/> </property> <property name="interceptors"> <list> <bean class="org.beetl.sql.ext.DebugInterceptor"></bean> </list> </property> </bean> </beans> ``` Spring配置需要配置如下Bean * datasource,這里使用H2庫 * beetlSqlScannerConfigurer 用于自動掃描java類,找到Mapper接口,自動為其生成代理類,并注冊為Spring Bean * sqlManagerFactoryBean, 定義sqlManager,其中masterSource 關聯了我們配置好的datasource UserInfo對象是一個POJO,關聯了sys_user表 ```java @Table(name="sys_user") @Data public class UserInfo { @AssignID private Long id; private String name; } ``` UserService是一個Spring的Service,簡單的調用`userMapper.insert` ```java @Service @Transactional public class UserService { @Autowired UserMapper userMapper; public void addUser(UserInfo userInfo){ userMapper.insert(userInfo); } } ``` UserMapper是一個BeetlSQL3的Mapper,我們使用BaseMapper提供的內置insert方法操作 ```java public interface UserMapper extends BaseMapper<UserInfo> { } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看