Spring Boot学习笔记

例子1:   http://spring.io/guides/gs/rest-service/

字符串填充,如%s

private static final String template = "Hello, %s!";
String name = "wwj";
String.format(template, name);

自增类型

private final AtomicLong counter = new AtomicLong();
counter.incrementAndGet();

@RequestMapping  @RequestParam

@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name", defaultValue="World"){...}

例子2:   http://spring.io/guides/gs/scheduling-tasks/

按格式输出时间

private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
dateFormat.format(new Date());

@Scheduled  定时运行

@Scheduled(fixedRate = 5000);     //加在一个小函数前面
@EnableScheduling //加在程序主入口前面

例子3:  http://spring.io/guides/gs/device-detection/

@ResponseBody 转为HTTP返回

public @ResponseBody String detectDevice(Device device) {
    ...
    return "Hello " + deviceType + " browser!";
}

设备类型判断

import org.springframework.mobile.device.Device;
Device device;
device.isNormal();
device.isMobile();
device.isTablet();

 

posted on 2016-03-23 01:44  wwjyt  阅读(525)  评论(0编辑  收藏  举报