-
【Query注解使用】 1、在Respository方法中使用,不需要遵循查詢方法命名規(guī)則 2、只需要將@Query定義在Respository中的方法之上即可 3、命名參數(shù)及索引參數(shù)的使用 4、本地查詢 【示例:】 @Query("select o form Employee o where o.name=?1 and o.age=?2") public List getParam1(String name,Integer age){} //Employee為類名 @Query("select o from Employee o where o.name=:name and o.age=:age") public List getParam2(@Param("name") String name,@Param("age")Integer age){} @Query("select o from Employee o where o.name like %?1%") @Query("select o from Employee o where o.name like %:name%") @Query("select o from Employee o where o.id = (select max(id) form Emplyee t1)") //使用原生表查詢 @Query(nativeQuery = true,value="select count(1) form emplyee") public long getCount();查看全部
-
【Repository中查詢方法定義規(guī)則和使用】 Like, findByFirstnameLike, ...where x.firstname like ? NotLike, findByFirstnameNotLike, ...where x.firstname not like ? StartingWith,findByFirstnameStartingWith, ...where x.firstname lkie ?(parameter bound with appended %) EndingWith, findByFirstnameEndingWith, ...where x.firstname like ?(parameter bound with prepended %) Containing, findByFirstnameContaining, ...where x.firstname like ?(parameter bound wrapped in %) OrderBy, findByAgeOrderByLastnameDesc,...where x.age=? order by x.lastname desc Not, findByLastnameNot, ...where x.lastname <> ? In, findByAgeIn(Collection<Age> ages),...where x.age in ? NotIn, findByAgeNotIn(Collection<Age> ages),...where x.age not in ? True, findByActiveTrue(), ...where x.active=true False, findByActiveFalse(), ...where x.active = false查看全部
-
Repository子接口: 1、CrudRepository:繼承Repository,實現(xiàn)了CURD相關(guān)的方法 2、PagingAndSortingRepository:繼承CrudRepository,實現(xiàn)了分布排序相關(guān)方法 3、JpaRepository:繼承PagingAndSortingRepository,實現(xiàn)JPA規(guī)范相關(guān)的方法查看全部
-
【Responsitory類的定義:】 public interface Repository<T,ID extends Serializable>{} 1)Responsitory是一個空接口,標(biāo)記接口 沒有包含方法的聲明接口 2)我們定義的接口 ** extends Repository,表示此接口納入spring管理,需按一定規(guī)則定義方法 如果我們自定義的接口沒有extends Repository運(yùn)行時會報錯: org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type 'com.imooc.repository.**' available 3)添加注解能達(dá)到不用extends Repository的功能 @RepositoryDefinition(domainClass = **.class,idClass=Integer.class)查看全部
-
【spring data jpa】 1)依賴 org.springframework.data/spring-data-jpa org.hibernate/hibernate-entitymanager 2)xml5個配置 a、配置數(shù)據(jù)源-dataSource b、配置EntityManagerFactory class="org.springframework.ormljpa.LocalContainerEntityManagerFactoryBean" c、配置事務(wù)管理器 class="org.springframework.orm.jpa.JpaTransactionManager" d、配置支持注解的事務(wù) e、配置spring data <jpa:repositories />查看全部
-
【其中取數(shù)據(jù)使用上下文類】 public class DataSourceTest{ private ApplicationContext ctx= null; private StudentDao sdao = null; @Before public void doBefore(){ ctx = new ClassPathXmlApplicationContext("beans.xml");sdao = ctx.getBean("studentDao");} @After public void tearDown(){ctx = null;} @Test public void test(){...} } 【xml:】 <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="dirverClassName" value="com.mysql.jdbc.Driver"/> <property name="username" value="**"/> <property name="password" value=""/> <property name="url" value="jdbc:mysql:///spring_data"/> </bean> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="dataSource"/> </bean> <bean id="studentDat" class="com.imooc.dao.StudentDAOSpringJdbc.StudentDao"> <property name="jdbcTemplate" ref="jdbcTemplate"/> </bean>查看全部
-
【使用spring jdbc的方法操作數(shù)據(jù)庫】 1)添加兩個依賴 2)配置beans.xml 3)操作數(shù)據(jù)庫 org.springframework/spring-jdbc org.springframework/spring-context查看全部
-
川建maven項目查看全部
-
Repository中查詢方法定義規(guī)則和使用2查看全部
-
Repository中查詢方法定義規(guī)則和使用查看全部
-
規(guī)則2查看全部
-
查詢方法定義查看全部
-
Spring Data查看全部
-
repository @query 使用原生態(tài)查詢需要添加 @Query(nativeQuery = true, value = "select * from 表名")查看全部
舉報
0/150
提交
取消