View on GitHub

reading-notes

Code 201 Reading Notes

Spring RESTful Routing & Static Files

Spring Request Mapping

  1. Overview - @RequestMapping annotation is for mapping web requests to Spring Controller methods”.

  2. @RequestMapping Basics

  1. RequestMapping and HTTP Headers
  1. RequestMapping with Path Variables
  1. RequestMapping with Request Parameters. It can be done, and the request parameters are used after extracting them from the URL.

  2. RequestMapping Corner Cases - they exist if different methods reach the same Controller method

  3. New Request Mapping Shortcuts (not that I knew the old one, but these seem to be much speedier ways of accomplishing their namesake methods)

  1. Spring Configuration (is required to make it work. no surprises here.)

Accessing Data with JPA (Seems like this is Spring’s database solution?)

Definition: JPA : Java Persistence API. (They should really just “remind” people what that is the first time on any tutorial page. imo.)

It goes on to note that it uses an interface, that Spring JPA creates for the application “when you run the application” (aka at runtime?).

Accessing Data with JPA

Using annotation, you define Entity and within it associated Id with a GeneratedValue. Along with a constructor function for the object to be put into the Java Persistence API, you have the makings of a database, within Java. It seems that with this arrangement, interfaces will be instrumental in organizing and using the content going into and out of the database. And the database has methods to query and surface objects that are stored within it, either by its key value pairs or the unique Id created via the @GeneratedValue.

Comparing Repositories: CrudRepository, and Other Details

but first! JpaRepository has both full APIs of CrudRepository and PagingAndSortingRepository! However if you don’t need all that power, the others have their usefulness.

The @Repository annotation enables auto-generation of interface implementation (? … huh?). Additional Spring Data JPA info and details are available here

The CrudRepository example is far too dense for me to make heads or tails of at this current time. But it does include the usual CRUD methods, so there is that.

PagingAndSortingRepository is used for pagination, with properties for page size, current page number, and sorting capabilities.

JpaRepository has all those and more. But due to its widespanning capabilities, might be “too much for it’s own good” and expose too much than is advisable if not coded deliberately.