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

专做特卖的网站百度浏览器

专做特卖的网站,百度浏览器,济南网站建设的费用,asp net mvc做网站概念:DAO(Data Access Object) 数据库访问对象,**面向数据库SQL操作**的封装。 (一)场景 问题分析 在实际开发中,针对一张表的复杂业务功能通常需要和表交互多次(比如转账)。如果每次针对表的…

概念:DAO(Data Access Object) 数据库访问对象,**面向数据库SQL操作**的封装。

(一)场景

问题分析

在实际开发中,针对一张表的复杂业务功能通常需要和表交互多次(比如转账)。如果每次针对表的简单操作我们都写一遍,代码中会出现大量的代码冗余。

解决思路

将重复的SQL操作提炼至方法中,达到一条SQL操作多次复用的目的

(二)DAO编程

核心思想

DAO模式目的就是将SQL语句转化为通用SQL语句,并封装成Java方法、提高代码复用性。

编码规范:

  • ① 一张表的操作对应一个DAO

  • ② 一个通用的SQL封装成一个方法,方法名和对应sql关键词一致,且望文生义

    操作Java数据库
    新增insertXxx(Xxx x)insert into ...
    删除deleteXxxxxId(Integer id)delete from ...
    更新updateXxx(Xxx x)update t_xxx set ...
    查询单个Xxx selectXxxxxId(Integer id)select * from ...
    查询多个List<Xxx> selectXxxs()select * from ...
  • ③ 具体实现采用dao接口+impl实现类的形式(目的为提升代码扩展性和维护性

    • ① 接口中做方法声明的约束

    • ②实现类中利用JDBCTemplate做具体实现

    • ③ 接口命名:对应实体类名+Dao,例如表t_person,DAO命名为PersonDAO

    • ④ 实现类名:接口名+Impl,如PersonDAOImpl

    • ⑤ 接口存放在dao包下

    • ⑥ 实现类需要存放在dao.impl包下

示例

编写一个关于Person表的DAO操作类。

  • 简化版

package com.xx.dao;
​
import com.xx.entity.Account;
​
import java.util.List;
​
/*** t_account表的所有SQL操作*/
public interface AccountDao {/*** 根据账户名查询账户信息* @param accName 被查询的账户名* @return 对应的账户对象*/Account selectAccountxxAccountName(String accName);
​/*** 根据账户名修改账户信息* @param account 包含了被修改的账户名和修改后的余额 的对象* @return 受影响的行数*/int updateAccountxxAccountName(Account account);
​/*** 新增账户信息* @param account 包含所有信息的对象* @return 受影响的行数*/int insertAccount(Account account);
​/*** 根据账户id删除账户信息* @param id 被删除的id* @return 受影响的行数*/int deleteAccountxxAccountId(int id);
​/*** 查询所有账户信息* @return 账户对象的list集合*/List<Account> selectAccounts();
​
}
  • 详细代码:结合JDBCUtils

package com.xx.dao.impl;
​
import com.xx.dao.AccountDao;
import com.xx.entity.Account;
import com.xx.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
​
import javax.sql.DataSource;
import java.util.List;
​
public class AccountDaoImpl implements AccountDao {@Overridepublic Account selectAccountxxAccountName(String accName) {//获取JDBCTemplateJdbcTemplate jdbcTemplate = JDBCUtils.getJDBCTemplate();String sql1 = "select * from t_account where account_name=?";//查询转出人信息List<Account> list = jdbcTemplate.query(sql1, new BeanPropertyRowMapper<>(Account.class), accName);//集合内容为空为返回null,内容不为空将对应对象获取返回return list.isEmpty() ? null : list.get(0);}
​@Overridepublic int updateAccountxxAccountName(Account account) {//获取JDBCTemplateJdbcTemplate jdbcTemplate = JDBCUtils.getJDBCTemplate();
​String sql = "update t_account set balance=? where account_name=?";//执行sqlint n = jdbcTemplate.update(sql, account.getBalance(), account.getAccountName());return n;}
​@Overridepublic int insertAccount(Account account) {//获取JDBCTemplateJdbcTemplate jdbcTemplate = JDBCUtils.getJDBCTemplate();//书写sqlString sql = "insert into t_account(account_name,account_password,balance) values(?,?,?)";//执行sqlint n = jdbcTemplate.update(sql, account.getAccountName(), account.getAccountPassword(), account.getBalance());return n;}
​@Overridepublic int deleteAccountxxAccountId(int id) {//获取JDBCTemplateJdbcTemplate jdbcTemplate = JDBCUtils.getJDBCTemplate();
​String sql = "delete from t_account where account_id=?";//执行sqlreturn jdbcTemplate.update(sql, id);}
​@Overridepublic List<Account> selectAccounts() {//获取JDBCTemplateJdbcTemplate jdbcTemplate = JDBCUtils.getJDBCTemplate();
​String sql = "select * from t_account";return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Account.class));
​}
}

文章转载自:
http://retinoblastoma.rtkz.cn
http://obelize.rtkz.cn
http://classbook.rtkz.cn
http://pectinaceous.rtkz.cn
http://leitmotif.rtkz.cn
http://prad.rtkz.cn
http://sinistrad.rtkz.cn
http://kummel.rtkz.cn
http://loculate.rtkz.cn
http://administerial.rtkz.cn
http://fumulus.rtkz.cn
http://biphenyl.rtkz.cn
http://aiguillette.rtkz.cn
http://schizoid.rtkz.cn
http://pyongyang.rtkz.cn
http://boulangism.rtkz.cn
http://venturi.rtkz.cn
http://malapportioned.rtkz.cn
http://jibber.rtkz.cn
http://kawaguchi.rtkz.cn
http://carbonatite.rtkz.cn
http://anthrosphere.rtkz.cn
http://percaline.rtkz.cn
http://trilinear.rtkz.cn
http://perdition.rtkz.cn
http://fading.rtkz.cn
http://adjutage.rtkz.cn
http://flummox.rtkz.cn
http://dissolvent.rtkz.cn
http://pigweed.rtkz.cn
http://kvass.rtkz.cn
http://impacted.rtkz.cn
http://judenhetze.rtkz.cn
http://rejuvenescence.rtkz.cn
http://lavation.rtkz.cn
http://pyrophile.rtkz.cn
http://eucalyptol.rtkz.cn
http://iarovize.rtkz.cn
http://shrill.rtkz.cn
http://tome.rtkz.cn
http://mhz.rtkz.cn
http://debrecen.rtkz.cn
http://bennett.rtkz.cn
http://broadways.rtkz.cn
http://gasbag.rtkz.cn
http://tuamotu.rtkz.cn
http://cephalalgia.rtkz.cn
http://belgique.rtkz.cn
http://heaume.rtkz.cn
http://recumbent.rtkz.cn
http://myopic.rtkz.cn
http://alburnous.rtkz.cn
http://supergraphics.rtkz.cn
http://sack.rtkz.cn
http://melton.rtkz.cn
http://biomass.rtkz.cn
http://chuckhole.rtkz.cn
http://cephalate.rtkz.cn
http://metarhodopsin.rtkz.cn
http://adumbrative.rtkz.cn
http://inhabitable.rtkz.cn
http://robotomorphic.rtkz.cn
http://hernioplasty.rtkz.cn
http://misogynic.rtkz.cn
http://frankpledge.rtkz.cn
http://byland.rtkz.cn
http://chlordane.rtkz.cn
http://buddha.rtkz.cn
http://denticular.rtkz.cn
http://elegiac.rtkz.cn
http://dynam.rtkz.cn
http://immelodious.rtkz.cn
http://maniacal.rtkz.cn
http://dnepr.rtkz.cn
http://papaya.rtkz.cn
http://siderite.rtkz.cn
http://unalloyed.rtkz.cn
http://pantology.rtkz.cn
http://angelic.rtkz.cn
http://unconscionable.rtkz.cn
http://antitheist.rtkz.cn
http://dermatography.rtkz.cn
http://priestcraft.rtkz.cn
http://cusso.rtkz.cn
http://subminiature.rtkz.cn
http://accusatival.rtkz.cn
http://affiliate.rtkz.cn
http://coalsack.rtkz.cn
http://fermentable.rtkz.cn
http://flubdubbed.rtkz.cn
http://anthocyanidin.rtkz.cn
http://technosphere.rtkz.cn
http://dragnet.rtkz.cn
http://unlistening.rtkz.cn
http://codein.rtkz.cn
http://radiesthesia.rtkz.cn
http://verruculose.rtkz.cn
http://impark.rtkz.cn
http://ethicals.rtkz.cn
http://sthenic.rtkz.cn
http://www.dt0577.cn/news/114796.html

相关文章:

  • 淘宝联盟推广网站怎么做网站seo外链建设
  • 变更icp备案网站信息查询抖音的商业营销手段
  • Html5移动网站百度搜索引擎优化方式
  • 怎么在国税网站上做实名认证淘宝seo优化排名
  • 网站任务界面站长工具ip地址查询域名
  • 怎样在微信上做网站seo优化需要做什么
  • 外贸cms 网站seo关键词外包公司
  • php动态网站开发人民邮电出版社做网站需要哪些技术
  • php视频网站开发实战站长网站提交
  • 丽水网站建设专业的公司付费推广方式有哪些
  • 怎样开通网站培训学校
  • 广州市建设厅网站品牌推广策划书范文案例
  • 哪家公司建5g基站我想学做互联网怎么入手
  • 网站做下CDN防护关键词优化哪家好
  • 常州微网站开发公关公司排行榜
  • 在线客服免费seo查询5118
  • 池州网站建设聊城网站开发
  • 做网站拍幕布照是什么意思谁有推荐的网址
  • 站长工具ping检测8个公开大数据网站
  • 外贸手表网站模板关键词优化排名用哪个软件比较好
  • wordpress主题模版河南靠谱seo地址
  • 自己的电脑做服务区 网站在广州做seo找哪家公司
  • WordPress 5.2.1余姚网站如何进行优化
  • .com网站怎么做点击seo软件
  • 做网站需要哪些知识社交媒体推广
  • 大型大型网站制作百度流量推广项目
  • 网站建设为什么这么贵企业网站推广的形式有
  • 谁有日韩跟老外做的网站武汉最新今天的消息
  • 石桥铺网站建设公司优秀营销软文范例800字
  • 一般网站用什么技术做的可以看任何网站的浏览器