|
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 | 7 | import cn.hserver.plugin.web.interfaces.HttpResponse; |
7 | 8 | import com.test.hserver.bean.Fortune; |
8 | 9 | import com.test.hserver.bean.Message; |
9 | 10 | import com.test.hserver.bean.World; |
10 | 11 | import com.test.hserver.util.DateUtil; |
| 12 | +import org.slf4j.Logger; |
| 13 | +import org.slf4j.LoggerFactory; |
11 | 14 |
|
12 | 15 | import javax.sql.DataSource; |
13 | 16 | import java.sql.Connection; |
|
26 | 29 | public class TestController { |
27 | 30 | private static final String HELLO = "Hello, World!"; |
28 | 31 | private static final String SELECT_WORLD = "select * from world where id=?"; |
| 32 | + private static final Logger log = LoggerFactory.getLogger(TestController.class); |
29 | 33 |
|
30 | 34 | @Autowired |
31 | 35 | private DataSource dataSource; |
@@ -60,19 +64,25 @@ public void db(HttpResponse response) throws SQLException { |
60 | 64 |
|
61 | 65 | @GET("/queries") |
62 | 66 | public void queries(String queries,HttpResponse response) throws Exception { |
63 | | - World[] result = new World[getQueries(queries)]; |
| 67 | + int queries1 = getQueries(queries); |
| 68 | + World[] result = new World[queries1]; |
64 | 69 | try (Connection conn = dataSource.getConnection()) { |
65 | 70 | for (int i = 0; i < result.length; i++) { |
66 | 71 | try (final PreparedStatement statement = conn.prepareStatement(SELECT_WORLD)) { |
67 | 72 | statement.setInt(1, randomWorld()); |
68 | 73 | try (ResultSet rs = statement.executeQuery()) { |
69 | 74 | rs.next(); |
70 | 75 | result[i] = new World(rs.getInt("id"), rs.getInt("randomNumber")); |
| 76 | + }catch (Exception e){ |
| 77 | + log.error(e.getMessage()); |
71 | 78 | } |
| 79 | + }catch (Exception e){ |
| 80 | + log.error(e.getMessage()); |
72 | 81 | } |
73 | 82 | } |
74 | 83 | } |
75 | 84 | response.setHeader("Date", DateUtil.getTime()); |
| 85 | + log.debug("\n请求:{}\n响应:{}\n",queries1, WebConstConfig.JSON.writeValueAsString(result)); |
76 | 86 | response.sendJson(result); |
77 | 87 | } |
78 | 88 |
|
|
0 commit comments