@RequestMapping("/hello") public @ResponseBody Object hello(int size) { long start = System.currentTimeMillis(); String content = helloService.hello("廖鹏"); System.out.println("invoke cost " + (System.currentTimeMillis() - start) + "ms " + content); for (int i = 0; i < size; i++) { try { Thread.sleep(10); } catch (InterruptedException e1) { e1.printStackTrace(); } final int tmp = i; excutor.submit( new Runnable() { @Override public void run() { try { String result = helloService.hello("auto-" + tmp); System.out.println(result); } catch (RuntimeException e) { e.printStackTrace(); } } }); } return Message.newBuilder().data(content).build(); }
@RequestMapping("/random") public @ResponseBody Object random() { int c = count.incrementAndGet(); long start = System.currentTimeMillis(); String content = randomBean.random(); System.out.println( "count=" + c + " cost " + (System.currentTimeMillis() - start) + "ms " + content); return Message.newBuilder().data(content).build(); }
@RequestMapping("/login") @ResponseBody public Object login(@Valid LoginForm form, BindingResult result) { System.out.println(result.getFieldError().getDefaultMessage()); Object[] objects = result.getFieldError().getArguments(); System.out.println("objects[0]=" + objects[0]); Message.Builder builder = Message.newBuilder(); return builder.build(); }