91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

spring boot DAO之Hibernate

發布時間:2020-07-26 14:20:58 來源:網絡 閱讀:1864 作者:乾坤刀 欄目:軟件技術

依賴

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

application-database.properties

#初始化數據庫的時候,如果錯誤,是否繼續啟動。
spring.datasource.continue-on-error=false
#jdbc driver.默認通過uri來自動檢測。
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#jdbc url.連接數據庫的uri
spring.datasource.url=jdbc:mysql://172.28.1.227:3310/fc?useUnicode=true&autoReconnect=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useServerPrepStmts=false
#數據庫連接用戶名
spring.datasource.username=fcdev
#數據連接密碼
spring.datasource.password=123456
#全限定名,連接池。默認自動檢測classpath
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
#sql腳本字符
spring.datasource.sql-script-encoding=UTF-8

#hibernate配置參數
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
spring.jpa.hibernate.naming.implicit-strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
spring.jpa.hibernate.use-new-id-generator-mappings=true

源碼-JpaProperties

@ConfigurationProperties(prefix = "spring.jpa")
public class JpaProperties {

    /**
     * Additional native properties to set on the JPA provider.
     */
    private Map<String, String> properties = new HashMap<>();

    /**
     * Mapping resources (equivalent to "mapping-file" entries in persistence.xml).
     */
    private final List<String> mappingResources = new ArrayList<>();

    /**
     * Name of the target database to operate on, auto-detected by default. Can be
     * alternatively set using the "Database" enum.
     */
    private String databasePlatform;

    /**
     * Target database to operate on, auto-detected by default. Can be alternatively set
     * using the "databasePlatform" property.
     */
    private Database database;

    /**
     * Whether to initialize the schema on startup.
     */
    private boolean generateDdl = false;

    /**
     * Whether to enable logging of SQL statements.
     */
    private boolean showSql = false;

    /**
     * Register OpenEntityManagerInViewInterceptor. Binds a JPA EntityManager to the
     * thread for the entire processing of the request.
     */
    private Boolean openInView;

    private Hibernate hibernate = new Hibernate();

}

源碼-HibernateJpaAutoConfiguration

@Configuration
@ConditionalOnClass({ LocalContainerEntityManagerFactoryBean.class, EntityManager.class })
@Conditional(HibernateEntityManagerCondition.class)
@EnableConfigurationProperties(JpaProperties.class)
@AutoConfigureAfter({ DataSourceAutoConfiguration.class })
@Import(HibernateJpaConfiguration.class)
public class HibernateJpaAutoConfiguration {

    @Order(Ordered.HIGHEST_PRECEDENCE + 20)
    static class HibernateEntityManagerCondition extends SpringBootCondition {

        private static final String[] CLASS_NAMES = {
                "org.hibernate.ejb.HibernateEntityManager",
                "org.hibernate.jpa.HibernateEntityManager" };

        @Override
        public ConditionOutcome getMatchOutcome(ConditionContext context,
                AnnotatedTypeMetadata metadata) {
            ConditionMessage.Builder message = ConditionMessage
                    .forCondition("HibernateEntityManager");
            for (String className : CLASS_NAMES) {
                if (ClassUtils.isPresent(className, context.getClassLoader())) {
                    return ConditionOutcome
                            .match(message.found("class").items(Style.QUOTE, className));
                }
            }
            return ConditionOutcome.noMatch(message.didNotFind("class", "classes")
                    .items(Style.QUOTE, Arrays.asList(CLASS_NAMES)));
        }

    }

}

SysMenu實體

@Entity
@Table(name = "t_sys_menu")
public class SysMenu {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @Column
    private String name;

    @Override
    public String toString() {
        return "id=" + id + ";name=" + name;
    }
}

TestHibernateDao

@org.springframework.stereotype.Repository
public interface TestHibernateDao extends JpaRepository<SysMenu, Integer> {

    SysMenu getSysMenuById(Integer id);
}

AppContextTest

@RunWith(SpringRunner.class)
@SpringBootTest
public class AppContextTest {

    @Autowired
    private TestHibernateDao testHibernateDao;

    @Test
    public void hibernateTest(){
        SysMenu sysMenu = testHibernateDao.getSysMenuById(1);
        System.out.println("menuName = " + sysMenu.getName());
    }
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

田林县| 高邮市| 潞城市| 庆云县| 清流县| 裕民县| 恩施市| 武平县| 满城县| 射洪县| 霍林郭勒市| 安岳县| 和林格尔县| 怀化市| 长治县| 津南区| 民权县| 晋宁县| 邯郸市| 绥滨县| 宣城市| 扬州市| 镶黄旗| 康平县| 探索| 吴堡县| 安庆市| 阿鲁科尔沁旗| 盐边县| 达州市| 汨罗市| 句容市| 庆安县| 岳普湖县| 澎湖县| 波密县| 九寨沟县| 潍坊市| 社会| 登封市| 秦安县|