@@ -398,19 +398,70 @@ def main(req: func.HttpRequest, messageJSON) -> func.HttpResponse:
398
398
399
399
# [ Java] ( #tab/java )
400
400
401
- The following example shows an HTTP triggered function which returns the total count of the items in a specified partition in Table storage.
401
+ The following example shows an HTTP triggered function which returns a list of person objects who are in a specified partition in Table storage. In the example, the partition key is extracted from the http route, and the tableName and connection are from the function settings.
402
402
403
403
``` java
404
- @FunctionName (" getallcount" )
405
- public int run(
406
- @HttpTrigger (name = " req" ,
407
- methods = {HttpMethod . GET },
408
- authLevel = AuthorizationLevel . ANONYMOUS ) Object dummyShouldNotBeUsed,
409
- @TableInput (name = " items" ,
410
- tableName = " mytablename" , partitionKey = " myparkey" ,
411
- connection = " myconnvarname" ) MyItem [] items
412
- ) {
413
- return items. length;
404
+ public class Person {
405
+ private String PartitionKey ;
406
+ private String RowKey ;
407
+ private String Name ;
408
+
409
+ public String getPartitionKey () { return this . PartitionKey ; }
410
+ public void setPartitionKey (String key ) { this . PartitionKey = key; }
411
+ public String getRowKey () { return this . RowKey ; }
412
+ public void setRowKey (String key ) { this . RowKey = key; }
413
+ public String getName () { return this . Name ; }
414
+ public void setName (String name ) { this . Name = name; }
415
+ }
416
+
417
+ @FunctionName (" getPersonsByPartitionKey" )
418
+ public Person [] get(
419
+ @HttpTrigger (name = " getPersons" , methods = {HttpMethod . GET }, authLevel = AuthorizationLevel . FUNCTION , route = " persons/{partitionKey}" ) HttpRequestMessage<Optional<String > > request,
420
+ @BindingName (" partitionKey" ) String partitionKey,
421
+ @TableInput (name = " persons" , partitionKey = " {partitionKey}" , tableName = " %MyTableName%" , connection = " MyConnectionString" ) Person [] persons,
422
+ final ExecutionContext context) {
423
+
424
+ context. getLogger(). info(" Got query for person related to persons with partition key: " + partitionKey);
425
+
426
+ return persons;
427
+ }
428
+ ```
429
+
430
+ The TableInput annotation can also extract the bindings from the json body of the request, like the following example shows.
431
+
432
+ ``` java
433
+ @FunctionName (" GetPersonsByKeysFromRequest" )
434
+ public HttpResponseMessage get(
435
+ @HttpTrigger (name = " getPerson" , methods = {HttpMethod . GET }, authLevel = AuthorizationLevel . FUNCTION , route = " query" ) HttpRequestMessage<Optional<String > > request,
436
+ @TableInput (name = " persons" , partitionKey = " {partitionKey}" , rowKey = " {rowKey}" , tableName = " %MyTableName%" , connection = " MyConnectionString" ) Person person,
437
+ final ExecutionContext context) {
438
+
439
+ if (person == null ) {
440
+ return request. createResponseBuilder(HttpStatus . NOT_FOUND )
441
+ .body(" Person not found." )
442
+ .build();
443
+ }
444
+
445
+ return request. createResponseBuilder(HttpStatus . OK )
446
+ .header(" Content-Type" , " application/json" )
447
+ .body(person)
448
+ .build();
449
+ }
450
+ ```
451
+
452
+ The following examples uses the Filter to query for persons with a specific name in an Azure Table, and limits the number of possible matches to 10 results.
453
+
454
+ ``` java
455
+ @FunctionName (" getPersonsByName" )
456
+ public Person [] get(
457
+ @HttpTrigger (name = " getPersons" , methods = {HttpMethod . GET }, authLevel = AuthorizationLevel . FUNCTION , route = " filter/{name}" ) HttpRequestMessage<Optional<String > > request,
458
+ @BindingName (" name" ) String name,
459
+ @TableInput (name = " persons" , filter = " Name eq '{name}'" , take = " 10" , tableName = " %MyTableName%" , connection = " MyConnectionString" ) Person [] persons,
460
+ final ExecutionContext context) {
461
+
462
+ context. getLogger(). info(" Got query for person related to persons with name: " + name);
463
+
464
+ return persons;
414
465
}
415
466
```
416
467
@@ -763,7 +814,8 @@ public class Person {
763
814
public String getName () {return this . Name ;}
764
815
public void setName (String name ) {this . Name = name; }
765
816
}
766
- public class AddPerson {
817
+
818
+ public class AddPerson {
767
819
768
820
@FunctionName (" addPerson" )
769
821
public HttpResponseMessage get (
0 commit comments