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

无障碍 网站 怎么做wordpress 微信登录插件下载失败

无障碍 网站 怎么做,wordpress 微信登录插件下载失败,如何建设营销型的网站,做安全题目是哪个网站文章目录 准备数据pom.xml文件中引用需要的库准备好dao层接口和service层接口和实现类准备好 jdbc.properties 和 user.properties编写Druid的jdbcConfig配置类编写spring的配置类SpringConfig编写Dao层的实现类的逻辑测试类参考文献 准备数据 create database if not exists …

文章目录

  • 准备数据
  • `pom.xml`文件中引用需要的库
  • 准备好dao层接口和service层接口和实现类
  • 准备好 `jdbc.properties` 和 `user.properties`
  • 编写Druid的jdbcConfig配置类
  • 编写spring的配置类`SpringConfig`
  • 编写Dao层的实现类的逻辑
  • 测试类
  • 参考文献

准备数据

create database if not exists db_spring;
use db_spring;
drop table if exists tb_user;
create table if not exists tb_user
(id      int primary key auto_increment,name    varchar(10) not null unique,age     int,id_card varchar(10)
);insert into tb_user(name, age, id_card)values ('张三', 23, '10001'),('李四', 18, '10002'),('王五', 34, '10003'),('赵六', 45, '10004');select * from tb_user;

pom.xml文件中引用需要的库

<dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>6.0.12</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.10</version></dependency><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><version>8.0.33</version></dependency>
</dependencies>

准备好dao层接口和service层接口和实现类

  • dao层
    // 接口
    package com.test.dao;public interface UserDao {void selectAll();void selectById();
    }
    
  • service层
    // 接口
    package com.test.service;public interface UserService {void selectAll();void selectById();
    }// 实现类
    package com.test.service.impl;import com.test.dao.UserDao;
    import com.test.service.UserService;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;/*** Service注解就是标识这个类是service层的bean,spring启动的时候,就会把它放入到Ioc容器中* 跟这个相似还有 @Repository 和 @Controller*/
    @Service
    public class UserServiceImpl implements UserService {// Autowired注解是自动装配@Autowiredprivate UserDao userDao;@Overridepublic void selectAll() {userDao.selectAll();}@Overridepublic void selectById() {userDao.selectById();}
    }
    

准备好 jdbc.propertiesuser.properties

这里分开写,是为了练习加载多个配置文件,所以需要再resources资源文件中新建这两个配置文件

  • jdbc.properties
    jdbc.driver=com.mysql.cj.jdbc.Driver
    jdbc.url=jdbc:mysql:///db_spring?useServerPrepStmts=true
    jdbc.username=root
    jdbc.password=root1234
    
  • user.properties
    name=张三
    age=23
    sex=男
    idCard=10001
    id=2
    

编写Druid的jdbcConfig配置类

public class JdbcConfig {/*** 这里通过Value注解从properties配置文件中读取数据* 这里的前提,就是在 SpringConfig这个配置类中* 通过PropertySource注解引用的资源文件中的配置文件*/@Value("${jdbc.driver}")private String driver;@Value("${jdbc.url}")private String url;@Value("${jdbc.username}")private String username;@Value("${jdbc.password}")private String password;/*** 通过 注解Bean来加载第三方*/@Beanpublic DataSource dataSource() {DruidDataSource ds = new DruidDataSource();ds.setDriverClassName(driver);ds.setUrl(url);ds.setUsername(username);ds.setPassword(password);return ds;}
}

编写spring的配置类SpringConfig

package com.test.config;import org.springframework.context.annotation.*;/*** Configuration注解:设置当前类为配置类* ComponentScan注解:用于扫描指定路径重点bean对象* PropertySource注解:用于把指定的配置文件加载借来* Import注解:是用于导入三方的bean类进入Ioc容器*/
@Configuration
@ComponentScan({"com.test.dao", "com.test.service"})
@PropertySource({"classpath:user.properties", "classpath:jdbc.properties"})
@Import(JdbcConfig.class)
public class SpringConfig {
}

编写Dao层的实现类的逻辑

// Repository:表示是dao层的bean
@Repository("userDao")
public class UserDaoImpl implements UserDao {// 自动装配@Autowiredprivate DataSource dataSource;// 获取配置文件中的数据@Value("${id}")private int id;@Overridepublic void selectAll() {try {// 操作数据库Connection connection = dataSource.getConnection();String sql = "select * from tb_user";PreparedStatement prepareStatement = connection.prepareStatement(sql);ResultSet resultSet = prepareStatement.executeQuery();while (resultSet.next()) {int id = resultSet.getInt("id");String name = resultSet.getString("name");String idCard = resultSet.getString("id_card");int age = resultSet.getInt("age");System.out.println("id:" + id + " , name:" + name + " , age:" + age + " , idCard:" + idCard);}// 释放资源resultSet.close();prepareStatement.close();connection.close();} catch (Exception e) {e.printStackTrace();}}@Overridepublic void selectById() {try {Connection connection = dataSource.getConnection();String sql = "select * from tb_user where id = ?";PreparedStatement prepareStatement = connection.prepareStatement(sql);prepareStatement.setInt(1, id);ResultSet resultSet = prepareStatement.executeQuery();while (resultSet.next()) {int id = resultSet.getInt("id");String name = resultSet.getString("name");String idCard = resultSet.getString("id_card");int age = resultSet.getInt("age");System.out.println("id:" + id + " , name:" + name + " , age:" + age + " , idCard:" + idCard);}// 释放资源resultSet.close();prepareStatement.close();connection.close();} catch (Exception e) {e.printStackTrace();}}
}

测试类

public class Main {public static void main(String[] args) {/*** 获取Ioc容器* 这里是通过SpringConfig这个配置类来获取*/ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class);// 获取beanUserService userService = ctx.getBean(UserService.class);userService.selectAll();System.out.println("====== selectById ======");userService.selectById();}
}

参考文献

1. 黑马程序员SSM框架教程

http://www.yayakq.cn/news/577023/

相关文章:

  • 大安区网站建设wordpress 头像不见
  • 网站asp源码中国纪检监察报app下载
  • 网站怎么做外链2024北京又开始核酸了吗今天
  • 51ppt模板免费下载网站网站 预算
  • 学院网站建设项目文字头像在线制作免费生成图片
  • 网站300兆是多少电子商务网站前台建设常用的技术
  • 2021最近最火的关键词深圳seo网站
  • 景宁县建设局网站怎么在网站上加qq
  • 做招商类型的网站农村一层自建房
  • 景区网站建设 现状网站建设的布局种类
  • 安徽智能网站建设最新军事消息
  • 免费建设工程信息网站做网站用的字体是什么
  • mcms怎么做网站丰台网站建设联系方式
  • 网站板块怎么做百度搜索 网站介绍
  • 网站加网页建设工程招投标网站
  • thinkphp5来做网站吗佛山建站 网站 商城
  • 网站认证怎么做乐陵森洁新能源有限公司电话
  • 400电话 网站建设内蒙古建设部网站官网
  • 工信部如何查网站备案三个字吉利好听的公司名称
  • wordpress 跳转到首页ppt一键优化
  • 做视频背景音乐专用网站做好一个网站后
  • 湖州网站集约化平台信用宁波企业网查询
  • 成都网站品牌设计刚注册在域名可以自己做网站吗
  • 网站建设及经营应解决好的问题重庆网站建设沛宣
  • 信息网站设计案例合肥企业网站建设
  • 网站建设费属于广告费吗6网站免费建站
  • 谷歌seo怎么提高网站权重网络营销方法有哪些举例
  • 如何给网站做二维码海城 网站建设
  • 页面设计的软件百度seo软件曝光行者seo
  • 一个商城网站开发要多少时间辽宁省建设工程信息网入辽打印