Showing posts with label Spring. Show all posts
Showing posts with label Spring. Show all posts
Wednesday, February 10, 2016

Keynotes: Derive JPA query from method name

JPA lookup

The JPA module supports defining a query or native query manually as String (using @NamedQuery/@NativeNamedQuery/@Query annotations) or have it being derived from the method name.

Default lookup strategy is CREATE_IF_NOT_FOUND, which combines combines CREATE and USE_DECLARED_QUERY ones. It looks up a declared query first, and if no declared query is found, it creates a custom method name-based query.
Spring Data repository query building mechanism allows quick query definition by method names & custom-tuning of it by introducing declared queries as needed.
Tuesday, January 19, 2016

Java: Forget About JSP

I hope that you already have forgotten about JSF (JavaServer Faces) :)
Not long time ago, all feeds were overloaded by post about, why everyone has to stop using JSF. However JSP (JavaServer Pages) is usually a kind of pain in ass for developers as well, because it's badly readable, not reusable, different from html syntax, not obvious, coupled, etc.

So, here is a better way, that should be chosen in favour of JSP:

Themeleaf

Thymeleaf is a Java library. It is a template engine capable of processing and generating HTML, XML, JavaScript, CSS and text, and can work both in web and non-web environments. It is better suited for serving the view layer of web applications, but it can process files in many formats, even in offline environments.

It provides an optional module for integration with Spring MVC, so that you can use it as a complete substitute of JSP in your applications made with this technology, even with HTML5.
As mentioned above, Thymeleaf is well integrated with Spring and allows more intuitive way to handle views part, which makes it's quite easy usable & useful especially for small fast projects.
Monday, November 2, 2015

Spring: Validate specific model attributes

Apply @InitBinder to specific commands

Validators will not be called unless your parameter has a @Valid annotation.
By default initBinder method will be invoked for every parameter (model attributes).
@InitBinder has an optional attribute where you can specify the specific attribute(s) to apply the method.

Te value of @InitBinder can be one of the following:
  • name of a model attribute;
  • name of a request parameter;
  • name of the class of parameter can be used, but starting with a small letter. That's how Spring exposes unnamed attributes to the model.