Skip to content

Commit bf74f19

Browse files
committed
Update README.md.
1 parent d4c9719 commit bf74f19

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -970,20 +970,20 @@ An example based on the MySQL "employees" sample database is shown below. The ba
970970
```java
971971
@RequestMethod("GET")
972972
@ResourcePath("?:employeeNumber")
973-
public void getEmployee(List<String> details) throws SQLException, IOException {
973+
public Map<String, ?> getEmployee(List<String> details) throws SQLException {
974974
String employeeNumber = getKey("employeeNumber");
975975

976976
Parameters parameters = Parameters.parse("SELECT emp_no AS employeeNumber, "
977977
+ "first_name AS firstName, "
978978
+ "last_name AS lastName "
979979
+ "FROM employees WHERE emp_no = :employeeNumber");
980980

981-
parameters.put("employeeNumber", employeeNumber);
982-
983-
try (Connection connection = DriverManager.getConnection(DB_URL);
981+
Map<String, ?> employee;
982+
try (Connection connection = dataSource.getConnection();
984983
PreparedStatement statement = connection.prepareStatement(parameters.getSQL())) {
985-
986-
parameters.apply(statement);
984+
parameters.apply(statement, mapOf(
985+
entry("employeeNumber", employeeNumber))
986+
);
987987

988988
try (ResultSet resultSet = statement.executeQuery()) {
989989
ResultSetAdapter resultSetAdapter = new ResultSetAdapter(resultSet);
@@ -1010,13 +1010,11 @@ public void getEmployee(List<String> details) throws SQLException, IOException {
10101010
}
10111011
}
10121012

1013-
getResponse().setContentType("application/json");
1014-
1015-
JSONEncoder jsonEncoder = new JSONEncoder();
1016-
1017-
jsonEncoder.write(resultSetAdapter.next(), getResponse().getOutputStream());
1013+
employee = resultSetAdapter.next();
10181014
}
10191015
}
1016+
1017+
return employee;
10201018
}
10211019
```
10221020

@@ -1058,13 +1056,15 @@ The `StreamAdapter` class presents the contents of a stream as an iterable seque
10581056
```
10591057

10601058
## Collections
1061-
The `Collections` class provides a set of static utility methods for working with list and map collections:
1059+
The `Collections` class provides a set of static utility methods for instantiating immutable list and map values:
10621060

10631061
```java
1064-
TODO
1062+
public static <E> List<E> listOf(E... elements) { ... }
1063+
public static <K, V> Map<K, V> mapOf(Map.Entry<K, V>... entries) { ... }
1064+
public static <K, V> Map.Entry<K, V> entry(K key, V value) { ... }
10651065
```
10661066

1067-
These methods are provided primarily as a convenience for applications using Java 8. Applications targeting Java 9 and higher can use the standard JDK `List.of` and `Map.of` methods.
1067+
These methods are provided primarily as a convenience for applications using Java 8. Applications targeting Java 9 and higher can use the standard `List.of()` and `Map.of()` methods provided by the JDK.
10681068

10691069
# Kotlin Support
10701070
In addition to Java, HTTP-RPC web services can be implemented using the [Kotlin](https://kotlinlang.org) programming language. For example, the following service provides some basic information about the host system:

httprpc-test/src/main/java/org/httprpc/test/mysql/EmployeeService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ public void getEmployees(String name) throws SQLException, IOException {
132132
}
133133
}
134134

135-
136135
employee = resultSetAdapter.next();
137136
}
138137
}

0 commit comments

Comments
 (0)