PageRenderTime 474ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/springmvc-practice/src/test/java/com/doctor/ebook/apress_pro_spring_4th_edition/chapter4/SimpleBean.java

https://gitlab.com/doctorwho1986/doctor
Java | 61 lines | 42 code | 14 blank | 5 comment | 4 complexity | cb500b957e01c3147d32fc139118cd32 MD5 | raw file
  1. package com.doctor.ebook.apress_pro_spring_4th_edition.chapter4;
  2. import javax.annotation.PostConstruct;
  3. import javax.annotation.PreDestroy;
  4. import org.springframework.beans.factory.annotation.Value;
  5. import org.springframework.stereotype.Component;
  6. import com.alibaba.fastjson.JSON;
  7. /**
  8. * @author doctor
  9. *
  10. * @since 2015年3月7日 下午2:39:35
  11. */
  12. @Component("simpleBean")
  13. public class SimpleBean {
  14. private static final String defalutName = "doctor who";
  15. private String name;
  16. @Value("26")
  17. private int age = Integer.MIN_VALUE;
  18. public String getName() {
  19. return name;
  20. }
  21. public void setName(String name) {
  22. this.name = name;
  23. }
  24. public int getAge() {
  25. return age;
  26. }
  27. public void setAge(int age) {
  28. this.age = age;
  29. }
  30. @PostConstruct
  31. public void init() {
  32. if (name == null) {
  33. name = defalutName;
  34. }
  35. if (age == Integer.MIN_VALUE) {
  36. throw new IllegalArgumentException("age is empty");
  37. }
  38. }
  39. @Override
  40. public String toString() {
  41. return JSON.toJSONString(this);
  42. }
  43. @PreDestroy
  44. public void destroy(){
  45. System.out.println("----"+getClass()+ ":" + " destroy ");
  46. }
  47. }