草庐IT

query-parameters

全部标签

java - 如何将@Query sql 存储在 CrudRepository 的外部文件中?

我正在使用spring和CrudRepositorys进行数据库连接。现在我需要一个相当长(几行)的sql查询,我更愿意在类路径中的文件中维护它,而不是直接在代码中。但是我怎样才能做到这一点呢?我的仓库如下所示:@Query(value="",nativeQuery=true)//howtoinjectfilecontent?@Modifying@TransactionalpublicvoidexecuteSpecificSql(); 最佳答案 使用以下步骤。在src/main/resources-->META-INF文件夹中创建j

java - Spring MVC : Fallback for unknown language code in uri parameter value

我正在尝试构建我的第一个支持i18n的SpringMVC4应用程序,并且正在考虑如何使用默认/备用语言环境,以防用户将语言uri参数操作为不存在或受支持的语言环境例如http://localhost.de?lang=abc我正在使用代码@BeanpublicLocaleResolverlocaleResolver(){SessionLocaleResolversessionLocaleResolver=newSessionLocaleResolver();sessionLocaleResolver.setDefaultLocale(Locale.GERMAN);returnsessio

java - Spring JPA Query 返回 Null 而不是 List

我有一个@EntityVideo与Listtags具有一对多关系作为其领域之一。我使用以下@Repository使用SpringData获取最流行的标签:@RepositorypublicinterfaceTagRepositoryextendsCrudRepository{@Query("SELECTtFROMTagtWHERE(SELECTSUM(v.views)FROMVideovWHEREtMEMBEROFv.tags)>0")publicListfindMostViewedTags(intmaxTags);}Query被Spring处理并认为是有效的,我在本地测试了生成的SQ

node.js - Mongoose 和 promise : how to get an array of query results?

使用mongoose从db和Q查询结果以获取promise,但发现我很难仅仅获得可用用户列表。目前我有一些类似的东西:varcheckForPerson=function(person){people=mongoose.model('Person',Person)returnpeople.findOne({"_id":person},function(err,doc){if(err)console.log(err)if(doc!==null){returndoc}else{console.log('noresults')}})}varpromises=someArrayOfIds.ma

node.js - Mongoose 和 promise : how to get an array of query results?

使用mongoose从db和Q查询结果以获取promise,但发现我很难仅仅获得可用用户列表。目前我有一些类似的东西:varcheckForPerson=function(person){people=mongoose.model('Person',Person)returnpeople.findOne({"_id":person},function(err,doc){if(err)console.log(err)if(doc!==null){returndoc}else{console.log('noresults')}})}varpromises=someArrayOfIds.ma

java - Spring JPA 中 NamedStoredProcedureQuery 中的错误 - "Found named stored procedure parameter associated with positional parameters"

我正在尝试使用SpringJPA提供的NamedStoredProcedureQuery调用用Postgresql编写的存储过程。以下是代码片段。EntityMovement.java@Entity@Table(name="entity_movement")@NamedStoredProcedureQueries({@NamedStoredProcedureQuery(name="near_by_entities",procedureName="near_by_entities",parameters={@StoredProcedureParameter(mode=ParameterM

Spring Data JPA Repository Method Query 与like?

在Spring-dataJPA中,有没有办法创建一个本质上是通过like搜索的方法查询?我有以下方法查询publicMakeModelfindByModelIgnoreCase(Stringmodel);我真正想要的是一个like表达式。我只需要创建一个Criteria或一个@Query注释吗?我要求太多了吗?//StupidexampleofwhatIwanttobeabletodopublicMakeModelfindByFuzzyModelIgnoreCase(Stringmodel);真的,我猜它的核心是,我想做一个表格搜索。我在SpringData下使用Hibernate,所

java - Spring 社交Facebook : "The OAuth2 ' state' parameter doesn't match"

我在SpringMVC项目中使用SpringSocialFacebook来支持Facebook登录。这在几乎所有情况下都运行良好,但偶尔我会在日志中看到以下异常。ERRORorg.springframework.social.connect.web.ProviderSignInController-ExceptionwhilecompletingOAuth2connection:java.lang.IllegalStateException:TheOAuth2'state'parameterdoesn'tmatch.atorg.springframework.social.connec

java - 使用 Spring Data JPA 和 @Query 注释仅获取第一个/最后一个元素

编辑:关于这个问题的第二个和第四个答案提供了这个问题的解决方案setMaxResultsforSpring-Data-JPAannotation?目标:使用SpringDataJPA存储库和SpringQuery注释按属性z获取最大/最小元素。我目前拥有的东西@Query("SELECTxelementFROMxxelementORDERBYxelement.z")publicListfindFirstElement();问题:此查询获取所有元素(这并不是真正有效)。如果我直接使用EntityManager,我可以使用设置结果数entityManager.setMaxResults(1

java - 我可以将 @Query 定义与 Spring Data JPA 存储库方法中的规范结合起来吗?

是否可以在一个存储库方法中同时使用@Query注释和规范?例如我想要一个这样的方法:@Query(value="SELECTefromEMPLOYEEwherefirstName?1")publicPagefindEmployeeBySomethigFancy(StringfirstName,Pageablepageable,Specificationemp);是否可以或应该将整个查询构建为Predicate并删除@Query注释? 最佳答案 首先,您应该阅读Springblogpost.第二,根据JpaSpecificationE