zoukankan      html  css  js  c++  java
  • springboot jpa使用

    1、添加pom依赖:

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

    2、application添加配置:

    spring.jpa:
      show-sql: true
      naming.implicit-strategy: org.hibernate.cfg.ImprovedNamingStrategy
      properties:
    #    hibernate.current_session_context_class: org.springframework.orm.hibernate4.SpringSessionContext
        hibernate.dialect: org.hibernate.dialect.MySQL5Dialect

    3、DAO

    @Repository
    public class BaseDAOImpl<T,ID extends Serializable> implements BaseDAO<T,ID> {
    
        @PersistenceContext
        private EntityManager entityManager;
    
        @Override
        public Object findBySql(String tablename, String filed, Object o) {
            String sql="select * from slot where slot_id = " + o;
            System.out.println(sql+"--------sql语句-------------");
            Query query = entityManager.createNativeQuery(sql);
            entityManager.close();
            return query.getSingleResult();
        }

      ...其他查询方法待续 }
  • 相关阅读:
    斐波那契数列
    旋转数组的最小数字
    用两个栈实现队列
    重建二叉树
    从尾到头打印链表
    2020/01/11,人活着是为了一口气
    2020/01/11,放肆和克制,敏感层次
    2020/01/11,记忆单元
    2020/01/11,经济基础决定高层建筑和个性
    git
  • 原文地址:https://www.cnblogs.com/kingsonfu/p/9873031.html
Copyright © 2011-2022 走看看