标签:
@InitBinder
类型转换,一般用于时间转换或者数据类型转换.
页面上时间传递字符串,DB中是datetime
例:
1 private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 2 3 @InitBinder 4 public void dataBinder(WebDataBinder dataBinder) { 5 dataBinder.registerCustomEditor(Date.class, new PropertyEditorSupport() { 6 @Override 7 public String getAsText() { 8 if (getValue() != null) { 9 return sdf.format((Date) getValue()); 10 } 11 return null; 12 } 13 14 @Override 15 public void setAsText(String text) throws IllegalArgumentException { 16 if (text != null) { 17 try { 18 setValue(sdf.parse(text)); 19 } catch (ParseException e) { 20 log.error("日期解析错误", e); 21 } 22 } 23 24 } 25 }); 26 }
@RequestMapping
用来定义访问的URL, 一般在类名上指定,也可以在方法上指定
类名:
@Controller @RequestMapping("/test") public class Test extends BaseController { //例1 "/test/tmp1" @RequestMapping(value = "tmp1", method = RequestMethod.GET) public String tmp1(){ return "1"; } //例2: "/test/tmp2/10" @RequestMapping(value = "/tmp2/{id}",method = RequestMethod.GET) public String tmp2(@PathVariable("id") Long id){ return "2"; } //例3: "/test/tmp2?id=10" @RequestMapping(value = "/tmp2",method = RequestMethod.GET, params = "id = id") public String tmp3(){ return "3"; } }
@Controller
负责注册一个bean 到spring 上下文中,bean 的ID 默认为类名
@Controller
public class Test {}
@Controller ("tmpTest")
public class Test {}
@Autowired
@Value
@ResponseBody
@RequestBody
@PageableDefault
@RequestParam
@Service
@Transactional
事务注解
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
时间类型转换注解
Lombok
@Slf4j
日志注解
@EqualsAndHashCode
重写equals和hashCode方法注解
@Data
重写get/set方法注解
@ToString
重写toString方法注解
标签:
原文地址:http://www.cnblogs.com/jason-Z/p/5007591.html