Documentation for the "fieldFinders
" JSON key.
Field finders are a simple way to generate singular finders that act on one or more fields. For field finders that query multiple fields, the fields should be separated by a comma ','.
The key fieldFinders
is a JSON Array of JSON Objects on the table
JSON object, for example:
"tables": [
{
"fields": [
...
],
"fieldFinders": [
...
]
}
]
Adding the following fieldFinders
JSON array of JSON Objects:
"fieldFinders": [
{ "nm_username": "unique" },
{ "txt_address_email": "unique" },
{ "num_age": "multiple" },
{ "fl_is_alive,num_age": "multiple" }
]
The name of the finder will be findBy<CamelCaseFieldName(s)>
This will automatically generate four finders:
- The first finder is
findByNmUsername
. which will return a uniqueUser
object that has one parameter passed into the method, namelynmUsername
. - The second finder is
findByTxtAddressEmail
. which will return a uniqueUser
object that has one parameter passed into the method, namelytxtAddressEmail
. - The third finder is
findByNumAge
which will return anArrayList<User>
that has all of the users with a specific age. - The fourth and final finder is
findByFlIsAliveNumAge
which will return anArrayList<User>
that has all two parameters passed into it, namelyflIsAlive
andfindByNumAge
.
The alternate way to define the above finders is as follows (which would generate identical code):
"finders": [
{
"name": "findByNmUsername",
"whereClause": "where nm_username = ?",
"whereFields": [
"nm_username"
],
"unique": true
},
{
"name": "findByTxtAddressEmail",
"whereClause": "where txt_address_email = ?",
"whereFields": [
"txt_address_email"
],
"unique": true
},
{
"name": "findByNumAge",
"whereClause": "where num_age = ?",
"whereFields": [
"num_age"
],
"unique": false
},
{
"name": "findByFlIsAliveNumAge",
"whereClause": "where fl_is_alive = ? and num_age = ?",
"whereFields": [
"fl_is_alive",
"num_age"
],
"unique": false
},
]
Which as you can see is a lot more work, more prone to error and un-necessary for something that can be automatically generated.