Преглед на файлове

Merge branch 'master' of https://github.com/ryantenney/FrameworkBenchmarks into ryantenney-master

Patrick Falls преди 12 години
родител
ревизия
3e1870bdcc

+ 8 - 16
spring/src/main/java/hello/web/HelloDbController.java

@@ -19,18 +19,20 @@ import org.springframework.stereotype.*;
 import org.springframework.web.bind.annotation.*;
 
 @Controller
-public class HelloDbController 
+public class HelloDbController
 {
+
   private static final int    DB_ROWS                = 10000;
 
-  @RequestMapping(value = "/db")
-  public Object index(HttpServletRequest request, HttpServletResponse response, Integer queries)
+  @RequestMapping(value = "/db", produces = "application/json")
+  @ResponseBody
+  public World[] index(Integer queries)
   {
     if (queries == null)
     {
       queries = 1;
     }
-    
+
     final World[] worlds = new World[queries];
     final Random random = ThreadLocalRandom.current();
     final Session session = HibernateUtil.getSessionFactory().openSession();
@@ -41,17 +43,7 @@ public class HelloDbController
     }
 
     session.close();
-    
-    try 
-    {
-      new MappingJackson2HttpMessageConverter().write(
-          worlds, MediaType.APPLICATION_JSON, new ServletServerHttpResponse(response));
-    } 
-    catch (IOException e) 
-    {
-      // do nothing
-    }
-    
-    return null;
+
+    return worlds;
   }
 }

+ 25 - 16
spring/src/main/java/hello/web/HelloJsonController.java

@@ -11,27 +11,36 @@ import org.springframework.http.converter.json.*;
 import org.springframework.http.server.*;
 import org.springframework.stereotype.*;
 import org.springframework.web.bind.annotation.*;
- 
+
 /**
  * Handles requests for the application home page.
  */
 @Controller
-public class HelloJsonController {
- 
-  @RequestMapping(value = "/json")
-  public Object json(HttpServletResponse response) 
+public class HelloJsonController
+{
+
+  @RequestMapping(value = "/json", produces = "application/json")
+  @ResponseBody
+  public Message json()
+  {
+    return new Message("Hello, world");
+  }
+
+  public static class Message
   {
-    Map<String, String> json = new HashMap<String, String>();
-    json.put("message", "Hello, world");
-
-    try {
-      new MappingJackson2HttpMessageConverter().write(
-          json, MediaType.APPLICATION_JSON, new ServletServerHttpResponse(response));
-    } catch (HttpMessageNotWritableException e) {
-        e.printStackTrace();
-    } catch (IOException e) {
-        e.printStackTrace();
+
+    private final String message;
+
+    public Message(String message)
+    {
+      this.message = message;
+    }
+
+    public String getMessage()
+    {
+      return message;
     }
-    return null;
+
   }
+
 }

+ 3 - 3
spring/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml

@@ -4,9 +4,9 @@
     xmlns:mvc="http://www.springframework.org/schema/mvc"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="
-        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
-        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
-        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
+        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
+        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
 
     <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->