【java,系统结构设计】三层类结构设计

POJO(plain ordinary java object)

contain only data attribute and getter/setter functions

example:

public class User {
   	private long id;
 	private String name;
 	public void setId(long id) {
 	 	this. id = id;
 	}
 	public void setName(String name) {
 	 	this. name=name;
 	}
 	public long getId() {
 	 	return id;
 	}
}

DAO(data access object)

contain code to connect POJO class object and database

example:

package test;


public class UserTableDAO extends BaseDAO implements IUserTableDAO {
    public UserTable validateUser(String username, String password) {
        //查询userTable表中的记录
        String hql = "from UserTableu where u.username=? and u.pasword=?";
        Session session = getSession();
        Query query = session.createQuery(hql);
        query.setParameter(0, username);
        query.setParameter(1, password);
        List users = query.list();
        Iterator it = users.iterator();
        while (it.hasNext()) {
            if (users.size() != 0) {
                UserTable user = (UserTable) it.next();
                return user;
            }
        }
        session.close();
        return null;
    }
}

Service class

built based on DAO object to handle business logic

example:

package test;

public class StudentServiceManage implements StudentServicel {
    //对XSDao和jDao进行依赖注入
    private StudentDao studentDao;
    private RecordDao recordDao;

    /*业务实现:学生信息查询*/
    public List findAl(int pageNow, int pageSize) {//显示所有学生信息
        return studentDao.findAl(pageNow, pageSize);
    }

    public int findStudentSizeOK() {//查询一共有多少条学生记录
        return studentDao.findStudentSize();
    }

    /*业务实现:查看某个学生的详细信息*/
    public Student find(String sid) {//根据学号查询某学生信息
        return studentDao.find(sid);
    }

    /*业务实现:删除某学生信息*/
    public void delete(String sid) {//根据学号删除学生
        recordDao.deleteOnestudentRecord(sid);
        studentDao.delete(sid);
    }
}

猜你喜欢

转载自blog.csdn.net/David_Hzy/article/details/133299008
今日推荐