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

企业官方网站地址/seo推广百度百科

企业官方网站地址,seo推广百度百科,怎样建自己的网站赚钱,注册一个网站的流程DBUtils的使用 1 DBUtils是apache提供的一个主要针对JDBC访问的一个封装(公共组件) 2 如何使用(搭建环境) <!--使用dbutils工具 这是一个公共组件 主要是对jdbc访问进行的封装 里面有QueryRunner类 用此类进行增删改查--><dependency><groupId>commons-dbut…

DBUtils的使用

1 DBUtils是apache提供的一个主要针对JDBC访问的一个封装(公共组件)
2 如何使用(搭建环境)

    <!--使用dbutils工具 这是一个公共组件 主要是对jdbc访问进行的封装 里面有QueryRunner类 用此类进行增删改查--><dependency><groupId>commons-dbutils</groupId><artifactId>commons-dbutils</artifactId><version>1.7</version></dependency>

3 基本语法


QueryRunner queryRunner = new  QueryRunner(传入datasource);queryRunner.update(sql,args);  //args 为参数queryRunner.query(sql,args);new BeanListHandler<>(.calss)  //返回集合 new BeanHandler<>(.calss); //返回一条结果数据

利用spring进行基于xml的解耦

applicationContext.xml 简单的配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><!--开始进行反射配置 --><!--配置德鲁伊 Druid 数据源 --><!-- 写死的配置  ==    DruidUtils--><bean id="druidDataSource" class="com.alibaba.druid.pool.DruidDataSource" ><property name="driverClassName" value="com.mysql.jdbc.Driver"/><property name="url" value="jdbc:mysql:///day05"/><property name="username" value="root"/><property name="password" value="root"/></bean><!--&lt;!&ndash;配置使用 QueryRunnerQueryRunner queryRunner = new QueryRunner(dataSource)--><bean id="queryRunner" class="org.apache.commons.dbutils.QueryRunner" ><!-- 使用 构造参数 传入 索引为0 位置的参数  ref 引用传入参数为 druidDataSource --><constructor-arg index="0" ref="druidDataSource" /></bean><!--实例化 AccountDaoImpl--><bean id="accountDao" class="com.itheima.dao.impl.AccountDaoImpl"><!--使用set 属性方法  set 和 get 方法必须是公共方法  public 修饰--><property name="queryRunner" ref="queryRunner" /></bean><bean id="accountService" class="com.itheima.services.impl.AccountServicesImpl" ><property name="accountDao" ref="accountDao" /></bean>
</beans>

AccountDaoImpl 的简单模拟 (继承了接口)

package com.itheima.dao.impl;import com.itheima.dao.AccountDao;
import com.itheima.domain.Accounts;
import com.itheima.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.List;public class AccountDaoImpl implements AccountDao {private  QueryRunner queryRunner ; //设置私有的queryRunner
//    static {
//        queryRunner = new QueryRunner(DruidUtils.getDataSource());
//
//    }//使用set  属性方法  给本类添加queryRunnerpublic void setQueryRunner(QueryRunner queryRunner){this.queryRunner = queryRunner;}public AccountDaoImpl() {}@Overridepublic void addAccount(Accounts accounts) {try {  //添加数据 没有返会值queryRunner.update("INSERT INTO accounts VALUES (NULL,?,?)",accounts.getAccountName(),accounts.getBalance());} catch (SQLException e) {e.printStackTrace();throw  new RuntimeException("添加数据失败");}}@Overridepublic void delAccount(Integer aid) {try {queryRunner.update("DELETE  FROM accounts WHERE aid = ? ",aid);} catch (SQLException e) {e.printStackTrace();throw new RuntimeException("删除操作失败");}}@Overridepublic void updataAccount(Accounts accounts) {try {queryRunner.update("UPDATE accounts SET accountName = ? , balance = ? WHERE aid = ? ;",accounts.getAccountName(),accounts.getBalance(),accounts.getAid());} catch (SQLException e) {e.printStackTrace();throw new RuntimeException("修改操作失败");}}@Overridepublic Accounts findAccountByAid(Integer aid) {try { //获取一条 使用query 进行查询操作  使用 new BeanHanler<>(返回数据类字节码文件)  指定返回一条指定数据return queryRunner.query("SELECT * FROM accounts WHERE aid = ? ",new BeanHandler<>(Accounts.class),aid);} catch (Exception e) {e.printStackTrace();return null;}}@Overridepublic List<Accounts> findAll() {try { //查询操作 返回 指定数据集合  使用query查询 指定数据类型 使用 new BeanListHandler<>(数据类型字节码文件)return queryRunner.query("SELECT * FROM accounts",new BeanListHandler<>(Accounts.class));} catch (SQLException e) {e.printStackTrace();}return null;}
}

AccountServicesImpl 的简单模拟 (继承了接口)

package com.itheima.services.impl;import com.itheima.dao.AccountDao;
import com.itheima.domain.Accounts;
import com.itheima.services.AccountServices;import java.util.List;public class AccountServicesImpl implements AccountServices {private AccountDao accountDao;public AccountDao getAccountDao() {return accountDao;}public void setAccountDao(AccountDao accountDao) {this.accountDao = accountDao;}@Overridepublic void addAccount(Accounts accounts) {accountDao.addAccount(accounts);}@Overridepublic void delAccount(Integer aid) {accountDao.delAccount(aid);}@Overridepublic void updataAccount(Accounts accounts) {accountDao.updataAccount(accounts);}@Overridepublic Accounts findAccountByAid(Integer aid) {return accountDao.findAccountByAid(aid);}@Overridepublic List<Accounts> findAll() {return accountDao.findAll();}
}

test 测试

package com.itheima.test;import com.itheima.dao.AccountDao;
import com.itheima.dao.impl.AccountDaoImpl;
import com.itheima.domain.Accounts;
import com.itheima.services.AccountServices;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;import java.util.List;public class AccountDaoTest {@Testpublic void test01(){ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");AccountDao accountDao = classPathXmlApplicationContext.getBean("accountDao", AccountDao.class);List<Accounts> all = accountDao.findAll();for (Accounts accounts : all) {System.out.println(accounts);}}@Testpublic void test02(){ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");AccountServices accountService = classPathXmlApplicationContext.getBean("accountService", AccountServices.class);List<Accounts> all = accountService.findAll();for (Accounts accounts : all) {System.out.println(accounts);}}
}
http://www.lbrq.cn/news/1358749.html

相关文章:

  • 香港做指数的网站/贵州seo和网络推广
  • 品牌网站建设k小蝌蚪/商品推广软文写作500字
  • 新乡做网站公司电话/百度竞价排名机制
  • 贵阳专业做网站/开发定制软件公司
  • 广西汽车网网站建设/搜索引擎登录入口
  • 做软件常用的网站有哪些/上海抖音seo公司
  • 网站文章做排名/百度识图鉴你所见
  • winforms做网站/静态网站开发
  • 四位一体网站开发/郑州靠谱seo整站优化
  • 网站百度排名优化/免费建自己的网站
  • 如何建设购物网站/怎样制作网页新手自学入门
  • semrush/江西seo推广软件
  • 网上自学电脑课程/windows优化大师是电脑自带的吗
  • 网站开发与优化课程总结/网站建设网络推广公司
  • 个人官方网站怎么建设/深圳网站优化排名
  • 西宁市公司网站建设/近期重大新闻
  • 中国十大设计公司/重庆seo团队
  • 在哪个网站上可以找兼职做/郑州做网站推广哪家好
  • 济宁网站建设多少钱/上海好的网络推广公司
  • 有哪些网站可以做设计挣钱/福建seo学校
  • 做黄金的经常看什么网站/seo培训一对一
  • 旅游网站如何做/千万不要做手游推广员
  • 苏州知名网站建设公司/搜索推广出价多少合适
  • 广州市专业做商城网站/直播营销
  • 专做hiphop的网站/搜索词
  • 做百度网站的公司哪家好/网络营销与管理
  • 北京手机网站建设/互联网推广运营是做什么的
  • 网站建设方案书格式/域名注册服务网站
  • 发优惠券网站怎么做/百度文库登录入口
  • 福田做网站的/b2b网站有哪些平台
  • python中的推导式
  • 大前端游戏应用中 AI 角色行为智能控制
  • 2. JS 有哪些数据类型
  • Could not load the Qt platform plugin “xcb“ in “无法调试与显示Opencv
  • Coze Loop:开源智能体自动化流程编排平台原理与实践
  • 电商系统想撑住大流量?ZKmall开源商城靠微服务 + Spring Boot3 解决单体架构难题