【笔记】数据访问层

参考:

orm:http://www.imooc.com/video/7702

java:http://www.imooc.com/course/programdetail/pid/31

jdbc:http://www.imooc.com/learn/421

junit:http://www.imooc.com/learn/356

dao层编写到测试的完整例子:http://www.2cto.com/kf/201703/614939.html

orm(Object Relational Mapping)和dao层(data access layer)的区别?dao层的设计目的是使得企业更换数据库的时候(只要不修改dao层接口),不影响上层的代码。orm更像是一种工具,Object Relational Mapping:

 

MYBATIS、HIBERNATE都是orm,设计目的是使得程序员不用重复编写代码,只要提供一个持久类和一张数据表,由orm自动生成crud代码。

1、http://www.360doc.com/content/12/1130/23/820209_251298059.shtml

尝试(完全按照个人理解):

1、实现表

2、创建持久化类

方便测试可以添加一个toString()方法。

Java数据类型和MySql数据类型对应表http://blog.csdn.net/yangyinbo/article/details/6212394

public class Student {
    private int id;
    private long create_at;
    private long update_at;
    private String name;
    private String qq;
    private String category;
    private String watchwords;

    public Student() {
    }

    public Student(String name, String qq, String category, String watchwords) {
        this.name = name;
        this.qq = qq;
        this.category = category;
        this.watchwords = watchwords;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public long getCreate_at() {
        return create_at;
    }

    public void setCreate_at(long create_at) {
        this.create_at = create_at;
    }

    public long getUpdate_at() {
        return update_at;
    }

    public void setUpdate_at(long update_at) {
        this.update_at = update_at;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getQq() {
        return qq;
    }

    public void setQq(String qq) {
        this.qq = qq;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getWatchwords() {
        return watchwords;
    }

    public void setWatchwords(String watchwords) {
        this.watchwords = watchwords;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", create_at=" + create_at +
                ", update_at=" + update_at +
                ", name='" + name + '\'' +
                ", qq='" + qq + '\'' +
                ", category='" + category + '\'' +
                ", watchwords='" + watchwords + '\'' +
                '}';
    }
}

 

3、编写dao层(dao层接口->dao层实现)

考虑手动JDBC还是Mybatis:http://www.cnblogs.com/jerrylz/p/5814460.html

dao层接口:http://blog.sina.com.cn/s/blog_4adc4b090101kvek.html

 决定Hibernate.

 

intellij 导入jar包:http://blog.csdn.net/a153375250/article/details/50851049

jar包下载:maven,参考《maven实战》

 

4、测试

转到Hibernate

posted @ 2017-04-19 20:16  xkfx  阅读(193)  评论(0)    收藏  举报