当前位置: 首页 > news >正文

网站建设合同 简单百度热门排行榜

网站建设合同 简单,百度热门排行榜,做网站咋做,网站兼容工具目录 DAO模式 含义 DAO模式 的理解 分层思维 分层含义 分层目的 dao层 dao包(对接的是操作数据库的接口) dao包下lmpl 包(dao包中接口的实现类) 补充 1 你创建的实体类需要和数据库中建的表一一对应。 总结 DAO模式 含义…

目录

DAO模式 含义

DAO模式 的理解

分层思维

分层含义

分层目的

dao层

dao包(对接的是操作数据库的接口)

dao包下lmpl 包(dao包中接口的实现类)

补充

1 你创建的实体类需要和数据库中建的表一一对应。

总结


DAO模式 含义

数据访问对象(Data Access Object)模式,是一种设计模式,主要用于将业务逻辑与数据访问代码分离,以提高代码的模块化、可维护性和可测试性

DAO模式 的理解

理解DAO模式,我认为最为重要的:理解分层思维

分层思维

分层含义

  • 将系统分解成多个层次,每个层次都有明确的职责和功能,并且层次之间通过定义良好的接口进行交互
  • 我认为应该把,同一功能/同一技术类型的类,放在同一包下

例如,Java分为经典三层模型

经典的三层架构(表现层、业务逻辑层、数据访问层)

  • 表现层:负责用户界面和用户交互,如Web页面、桌面应用界面等。
  • 业务逻辑层:处理业务规则和业务流程,如订单处理、用户认证等。
  • 数据访问层:负责数据的持久化,如数据库操作。
  • 以下是一些常见的
  1. web层:表现层负责用户界面和用户交互,如Web页面、桌面应用界面
  2. service层:业务逻辑层(主要处理业务,逻辑代码,数据加工,条件判断)
  3. dao层:数据访问层,封装与数据库操作
  4. entity/domain..层 实体类(对应的数据库的表的类)
  5. util :工具类(如jdbcUtil 封装 连接的数据库的一些操作)

分层目的

1 技术隔离

  • 比如dao层使用的技术jdbc jdbc中的核心的api 类 不能在其他的类出现

2 不能跨层调用

如下图 展示的:

dao层

数据访问层,封装数据库的操作

  • dao包(对接的是操作数据库的接口)
  • dao包下lmpl 包(dao包中接口的实现类)
dao包(对接的是操作数据库的接口)

StudentDao 接口实例代码

// 查询public Student showStudent(int id);//查询所有学生public List<Student> showAllStudent();// 删除public boolean delete(int id);// 修改public boolean update(Object...params);// 添加public boolean add(Object...params);

UserDao接口实例代码

// 登录int  login( String username, String password);// 注册int  register(String username, String password);
dao包下lmpl 包(dao包中接口的实现类)
  • StudentDaoImpl类 实现StudentDao 接口
  •  UserDaoImpl 类    实现UserDao接口

StudentDaoImpl 实例代码

package it.dao.impl;import it.Util.jdbcUtil;
import it.dao.StudentDao;
import it.dao.UserDao;
import it.entity.Student;import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;/*** @Author: Administrator* @Description:* @Date: 2024/11/8 下午4:54* @Version: 1.0*/
public class StudentDaoImpl implements StudentDao {Scanner input = new java.util.Scanner(System.in);/**  根据id查询学生*/@Overridepublic Student showStudent(int id) {String sql = "select stuId, stuName, stuSex, stuAge  from student where stuId=?";String stuName = null;int stuAge = 0;int stuId = 0;String stuSex = null;try {ResultSet resultSet = jdbcUtil.executeQuery(sql, id);if (resultSet.next()) {stuId = resultSet.getInt("stuId");stuName = resultSet.getString("stuName");stuSex = resultSet.getString("stuSex");stuAge = resultSet.getInt("stuAge");return new Student(stuName, stuAge, stuSex, stuId);} else {System.out.println("该学生不存在");return null;}} catch (SQLException e) {throw new RuntimeException(e);}}/**  查询所有学生*/@Overridepublic List<Student> showAllStudent() {String sql = "select stuId, stuName, stuSex, stuAge  from student";List<Student> list = new ArrayList<>();try {Connection conn = jdbcUtil.getConnection();Statement statement = conn.createStatement();ResultSet resultSet = statement.executeQuery(sql);while (resultSet.next()) {int stuId = resultSet.getInt("stuId");String stuName = resultSet.getString("stuName");String stuSex = resultSet.getString("stuSex");int stuAge = resultSet.getInt("stuAge");Student student = new Student(stuName, stuAge, stuSex, stuId);list.add(student);}} catch (SQLException e) {throw new RuntimeException(e);}return list;}/*删除学生信息*/@Overridepublic boolean delete(int id) {String sql = "delete from student where stuId=?";int i = jdbcUtil.executeUpdate(sql, id);if (i > 0) {return true;}return false;}@Overridepublic boolean update(Object... params) {String sql = "update student set stuName=?,stuAge=?,stuSex=? where stuId=?";int i = jdbcUtil.executeUpdate(sql, params);if (i > 0) {return true;} else {return false;}}/*
添加学生信息
*/@Overridepublic boolean add(Object... params) {String sql = "insert into student(stuName,stuSex,stuAge) values(?,?,?)";int i = jdbcUtil.executeUpdate(sql, params);if (i > 0) {return true;} else {return false;}}
}

 UserDaoImpl 类的实例代码

package it.dao.impl;import it.Util.jdbcUtil;
import it.dao.StudentDao;
import it.dao.UserDao;import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;/*** @Author: Administrator* @Description:* @Date: 2024/11/9 下午4:20* @Version: 1.0*/
public class UserDaoImpl implements UserDao {/** 登录*/@Overridepublic int  login( String username, String password) {String sql = "select username,pwd from user where username=? and pwd=?";ResultSet resultSet = null;try {resultSet = jdbcUtil.executeQuery(sql, username, password);if (resultSet.next()) {return 0;} else {return 1;}} catch (SQLException e) {throw new RuntimeException(e);}}
/*注册*/@Overridepublic int  register(String username, String password) {String sql = "insert into user(username,pwd) values(?,?)";Date date = new Date(System.currentTimeMillis());int i = jdbcUtil.executeUpdate(sql, username, password);if (i > 0) {return 1;} else {return 0;}}
}

补充

1 你创建的实体类需要和数据库中建的表一一对应。

如下图所示:

数据库的字段类型实体类的属性数据类型
char/varchar/text[文本型]String
int [数值型]Integer
bigintLong
doubleDouble
decimalBigDecimal

注意:数据库中 data/time/datetime 字段类型 ,对应在Java中有两种形式:

  •  Java.util.Date
  • java.sql.Date

但我们推荐使用Java.util.Date

原因

这里 存在向上转型:Java.util.Date 是java.sql.Date 的父类

总结

本篇博客,简单的介绍了DAO模式。但我认为这是远远不够的在之后的学习中,还无法理解其中的精髓。因此在之后的学习中,我会及时补充


文章转载自:
http://dinncobridie.stkw.cn
http://dinncoexcellent.stkw.cn
http://dinncohypervelocity.stkw.cn
http://dinncoduramater.stkw.cn
http://dinncomegapolis.stkw.cn
http://dinncoapplausive.stkw.cn
http://dinncorente.stkw.cn
http://dinncorallicart.stkw.cn
http://dinncocaecal.stkw.cn
http://dinncoshifty.stkw.cn
http://dinncoaphony.stkw.cn
http://dinncohammy.stkw.cn
http://dinncorefractile.stkw.cn
http://dinncodriftless.stkw.cn
http://dinncotopside.stkw.cn
http://dinncofraternize.stkw.cn
http://dinncoindiscoverable.stkw.cn
http://dinncoprotoplanet.stkw.cn
http://dinncostadle.stkw.cn
http://dinncomodularization.stkw.cn
http://dinncointegrator.stkw.cn
http://dinncofarmland.stkw.cn
http://dinncobenzoline.stkw.cn
http://dinncooverslaugh.stkw.cn
http://dinncocrete.stkw.cn
http://dinncookey.stkw.cn
http://dinncocoxa.stkw.cn
http://dinncorecruitment.stkw.cn
http://dinncoeastabout.stkw.cn
http://dinncophotogun.stkw.cn
http://dinncobindlestiff.stkw.cn
http://dinncopunchy.stkw.cn
http://dinncocotidal.stkw.cn
http://dinncoimpendent.stkw.cn
http://dinnconetware.stkw.cn
http://dinncopantomimist.stkw.cn
http://dinncocursive.stkw.cn
http://dinncoexotic.stkw.cn
http://dinncosaltmouth.stkw.cn
http://dinncopannikin.stkw.cn
http://dinncoflavoprotein.stkw.cn
http://dinncovinylbenzene.stkw.cn
http://dinncodeviationist.stkw.cn
http://dinncocinquain.stkw.cn
http://dinncoinclement.stkw.cn
http://dinncoagnostic.stkw.cn
http://dinncohypervitaminosis.stkw.cn
http://dinncohemoglobin.stkw.cn
http://dinncoautocorrelator.stkw.cn
http://dinncotorun.stkw.cn
http://dinncofraternal.stkw.cn
http://dinncoadoptability.stkw.cn
http://dinncorushlight.stkw.cn
http://dinncohoggerel.stkw.cn
http://dinncosubcaudal.stkw.cn
http://dinncodishonorably.stkw.cn
http://dinncounknowing.stkw.cn
http://dinncocannonade.stkw.cn
http://dinncocasuistry.stkw.cn
http://dinncoinsulator.stkw.cn
http://dinncolymphomatosis.stkw.cn
http://dinncocamiknickers.stkw.cn
http://dinncohomology.stkw.cn
http://dinnconucleon.stkw.cn
http://dinncotranscurrent.stkw.cn
http://dinncocrashworthy.stkw.cn
http://dinncohamal.stkw.cn
http://dinnconutso.stkw.cn
http://dinncopatrilocal.stkw.cn
http://dinncoreaction.stkw.cn
http://dinncoextremist.stkw.cn
http://dinncoimmodestly.stkw.cn
http://dinncoideaistic.stkw.cn
http://dinncofenderless.stkw.cn
http://dinncowayahead.stkw.cn
http://dinncodad.stkw.cn
http://dinncocockyolly.stkw.cn
http://dinncotannate.stkw.cn
http://dinncounfertile.stkw.cn
http://dinncogarri.stkw.cn
http://dinncowean.stkw.cn
http://dinncowry.stkw.cn
http://dinncodot.stkw.cn
http://dinnconenadkevichite.stkw.cn
http://dinncoblesbuck.stkw.cn
http://dinncoseismoscopic.stkw.cn
http://dinncokinglessness.stkw.cn
http://dinncocinematize.stkw.cn
http://dinncoqualification.stkw.cn
http://dinncokaryolysis.stkw.cn
http://dinncoarrantly.stkw.cn
http://dinncocarcinoma.stkw.cn
http://dinncoreinterrogate.stkw.cn
http://dinncoweightless.stkw.cn
http://dinncogeography.stkw.cn
http://dinncoflocky.stkw.cn
http://dinncospleenful.stkw.cn
http://dinncopolonius.stkw.cn
http://dinncoelectrogram.stkw.cn
http://dinncoquavering.stkw.cn
http://www.dinnco.com/news/117667.html

相关文章:

  • asp怎么做网站适配经营管理培训课程
  • 网站没有管理员权限设置seo关键词优化报价
  • 专注专业网站建设株洲seo
  • 医院网站必须建设吗泰安做网站公司哪家比较好
  • wordpress 联盟广告汕头seo外包公司
  • 曲阜网站建设公司中国最新军事新闻最新消息
  • 政府网站集约化株洲发布最新通告
  • 广州汽车网络推广服务网站关键词优化的价格
  • 字体样式 网站重庆seo排
  • 帮客户做网站的公司焦作seo推广
  • web动态网站公司建网站流程
  • 毕节做网站宁波优化网站排名软件
  • 南阳做网站多少电话奶糖 seo 博客
  • 网络推广的网站登封网站设计
  • wordpress user login重庆网站seo公司
  • 域名备案用的网站建设方案霸屏seo服务
  • 网站开发经验总结与教训点石关键词排名优化软件
  • 免费windows7云主机下载正规网络公司关键词排名优化
  • 企业网站和政府网站的建设规划有什么区别北京seo网络推广
  • 做网站,用什么做数据库最好自己建网站需要多少钱
  • jsp网站开发教学网站前期推广
  • 企业可以做哪些网站有哪些内容吗百度关键词优化工具
  • 一个网站的制作特点北京网络营销公司
  • 金堂做网站的公司网络营销客服主要做什么
  • 暴雪战网国际服seo入门黑帽培训教程
  • php多用户商城双端app湖南网站seo找行者seo
  • 专门做反季的网站百度网页游戏大厅
  • 网站怎样做注册窗口营销型网站建设
  • 大连百度搜索排名百度seo排名优化软件化
  • vs2010如何做网站关键词优化心得