新增Pojo

添加第一个Pojo类, 用户User, 按Ctrl+N,选择Class,弹出新建类对话框,输入package和类名

添加User类

为User类添加几个属性

稍微提示一下, Nutz不要求用户的Pojo类必须继承某个类

  1. package net.wendal.nutzbook.bean;
  2. import java.util.Date;
  3. public class User {
  4. private int id;
  5. private String name;
  6. private String password;
  7. private String salt;
  8. private Date createTime;
  9. private Date updateTime;
  10. }

标注Nutz所需的注解Table,Id,Name

  1. @Table("t_user")
  2. public class User {
  3. @Id
  4. private int id;
  5. @Name
  6. @Column
  7. private String name;
  8. @Column("passwd")
  9. private String password;
  10. @Column
  11. private String salt;
  12. @Column("ct")
  13. private Date createTime;
  14. @Column("ut")
  15. private Date updateTime;
  16. }

在菜单中选择Sources—Generate Getters and Setters,点击Select All, 完成OK

新增Pojo - 图2

最终效果的User.java 完整代码

  1. package net.wendal.nutzbook.bean;
  2. import java.util.Date;
  3. import org.nutz.dao.entity.annotation.Column;
  4. import org.nutz.dao.entity.annotation.Id;
  5. import org.nutz.dao.entity.annotation.Name;
  6. import org.nutz.dao.entity.annotation.Table;
  7. @Table("t_user")
  8. public class User {
  9. @Id
  10. private int id;
  11. @Name
  12. @Column
  13. private String name;
  14. @Column("passwd")
  15. private String password;
  16. @Column
  17. private String salt;
  18. @Column("ct")
  19. private Date createTime;
  20. @Column("ut")
  21. private Date updateTime;
  22. public int getId() {
  23. return id;
  24. }
  25. public void setId(int id) {
  26. this.id = id;
  27. }
  28. public String getName() {
  29. return name;
  30. }
  31. public void setName(String name) {
  32. this.name = name;
  33. }
  34. public String getPassword() {
  35. return password;
  36. }
  37. public void setPassword(String password) {
  38. this.password = password;
  39. }
  40. public String getSalt() {
  41. return salt;
  42. }
  43. public void setSalt(String salt) {
  44. this.salt = salt;
  45. }
  46. public Date getCreateTime() {
  47. return createTime;
  48. }
  49. public void setCreateTime(Date createTime) {
  50. this.createTime = createTime;
  51. }
  52. public Date getUpdateTime() {
  53. return updateTime;
  54. }
  55. public void setUpdateTime(Date updateTime) {
  56. this.updateTime = updateTime;
  57. }
  58. }

手册关联(选修)