Skip to content

Instantly share code, notes, and snippets.

@thomasdarimont
Created July 15, 2014 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasdarimont/e73d464488020167ec55 to your computer and use it in GitHub Desktop.
Save thomasdarimont/e73d464488020167ec55 to your computer and use it in GitHub Desktop.

Initially we also had support for SpEL Expression parameters in query derivation but we decided to leave it out for now, since we had some concerns whether having SpEL expressions in user code is a good idea.

Configure SpEL expression as a bean

@Bean
Expression currentUserEmailAdress(){
	return new SpelExpressionParser().parseExpression("principal?.emailAddress");
}

Allow Expressions to be used as Parameters in repository query methods

List<BusinessObject> findByOwnerEmailAddress(Expression currentUserEmailAddress);

Useage example

...
@Autowired Expression currentUserEmailAdress;
...
public void someBusinessMethod(..){
   List<BusinessObject> businessObjects = repository.findByOwnerEmailAddress(currentUserEmailAddress);
}

Please let us know what you think about that as well :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment