|
3 | 3 | import cn.hserver.core.ioc.annotation.Autowired; |
4 | 4 | import cn.hserver.plugin.web.annotation.Controller; |
5 | 5 | import cn.hserver.plugin.web.annotation.GET; |
6 | | -import cn.hserver.plugin.web.context.WebConstConfig; |
| 6 | +import cn.hserver.plugin.web.interfaces.HttpRequest; |
7 | 7 | import cn.hserver.plugin.web.interfaces.HttpResponse; |
8 | 8 | import com.test.hserver.bean.Fortune; |
9 | 9 | import com.test.hserver.bean.Message; |
|
29 | 29 | public class TestController { |
30 | 30 | private static final String HELLO = "Hello, World!"; |
31 | 31 | private static final String SELECT_WORLD = "select * from world where id=?"; |
32 | | - private static final Logger log = LoggerFactory.getLogger(TestController.class); |
33 | 32 |
|
34 | 33 | @Autowired |
35 | 34 | private DataSource dataSource; |
@@ -63,33 +62,27 @@ public void db(HttpResponse response) throws SQLException { |
63 | 62 | } |
64 | 63 |
|
65 | 64 | @GET("/queries") |
66 | | - public void queries(String queries,HttpResponse response) throws Exception { |
67 | | - int queries1 = getQueries(queries); |
68 | | - World[] result = new World[queries1]; |
| 65 | + public void queries(HttpRequest request,HttpResponse response) throws Exception { |
| 66 | + World[] result = new World[getQueries(request.query("queries"))]; |
69 | 67 | try (Connection conn = dataSource.getConnection()) { |
70 | 68 | for (int i = 0; i < result.length; i++) { |
71 | 69 | try (final PreparedStatement statement = conn.prepareStatement(SELECT_WORLD)) { |
72 | 70 | statement.setInt(1, randomWorld()); |
73 | 71 | try (ResultSet rs = statement.executeQuery()) { |
74 | 72 | rs.next(); |
75 | 73 | result[i] = new World(rs.getInt("id"), rs.getInt("randomNumber")); |
76 | | - }catch (Exception e){ |
77 | | - log.error(e.getMessage()); |
78 | 74 | } |
79 | | - }catch (Exception e){ |
80 | | - log.error(e.getMessage()); |
81 | 75 | } |
82 | 76 | } |
83 | 77 | } |
84 | 78 | response.setHeader("Date", DateUtil.getTime()); |
85 | | - log.debug("\n请求:{}\n响应:{}\n",queries1, WebConstConfig.JSON.writeValueAsString(result)); |
86 | 79 | response.sendJson(result); |
87 | 80 | } |
88 | 81 |
|
89 | 82 |
|
90 | 83 | @GET("/updates") |
91 | | - public void updates(String queries,HttpResponse response) throws Exception { |
92 | | - World[] result = new World[getQueries(queries)]; |
| 84 | + public void updates(HttpRequest request,HttpResponse response) throws Exception { |
| 85 | + World[] result = new World[getQueries(request.query("queries"))]; |
93 | 86 | StringJoiner updateSql = new StringJoiner( |
94 | 87 | ", ", |
95 | 88 | "UPDATE world SET randomNumber = temp.randomNumber FROM (VALUES ", |
|
0 commit comments