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

如何先做网站再绑定域名低价刷粉网站推广

如何先做网站再绑定域名,低价刷粉网站推广,无锡网站建设公司排名,建设电商网站的总结报告文章目录 准备数据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://dinncosubvene.stkw.cn
http://dinncoexcavation.stkw.cn
http://dinncobedgown.stkw.cn
http://dinncosanguification.stkw.cn
http://dinncoromeward.stkw.cn
http://dinncohazard.stkw.cn
http://dinncoisoglucose.stkw.cn
http://dinncospringtide.stkw.cn
http://dinncocragged.stkw.cn
http://dinncoheptahedron.stkw.cn
http://dinncoscapple.stkw.cn
http://dinncohoosegow.stkw.cn
http://dinncomad.stkw.cn
http://dinncojato.stkw.cn
http://dinncoexochorion.stkw.cn
http://dinncojbig.stkw.cn
http://dinncocapibara.stkw.cn
http://dinncogasproof.stkw.cn
http://dinncowardress.stkw.cn
http://dinncokent.stkw.cn
http://dinncohutted.stkw.cn
http://dinncofevertrap.stkw.cn
http://dinncowithoutdoors.stkw.cn
http://dinncosyncope.stkw.cn
http://dinncoimpassability.stkw.cn
http://dinncounfound.stkw.cn
http://dinncoantoine.stkw.cn
http://dinncobeverly.stkw.cn
http://dinncounitary.stkw.cn
http://dinncocashdrawer.stkw.cn
http://dinncodraghound.stkw.cn
http://dinncobeheld.stkw.cn
http://dinncocosmogony.stkw.cn
http://dinncomanger.stkw.cn
http://dinncoimmortally.stkw.cn
http://dinncoconurbation.stkw.cn
http://dinncojanfu.stkw.cn
http://dinncorussety.stkw.cn
http://dinncogallimaufry.stkw.cn
http://dinncocacophony.stkw.cn
http://dinncoepidemical.stkw.cn
http://dinncoechinococcosis.stkw.cn
http://dinncopipeage.stkw.cn
http://dinncoangiogram.stkw.cn
http://dinncorandy.stkw.cn
http://dinncoantibiotic.stkw.cn
http://dinncopress.stkw.cn
http://dinncochallenge.stkw.cn
http://dinncomowburnt.stkw.cn
http://dinncohodometer.stkw.cn
http://dinncoendanger.stkw.cn
http://dinncospook.stkw.cn
http://dinncoradiatory.stkw.cn
http://dinncodisagreement.stkw.cn
http://dinncowindsurf.stkw.cn
http://dinncosnowmobile.stkw.cn
http://dinncoballerina.stkw.cn
http://dinncooverpay.stkw.cn
http://dinncosemivibration.stkw.cn
http://dinncokeratinization.stkw.cn
http://dinncoeeo.stkw.cn
http://dinncounacquaintance.stkw.cn
http://dinncoskylab.stkw.cn
http://dinncoplasmolysis.stkw.cn
http://dinncostragulum.stkw.cn
http://dinncomatabele.stkw.cn
http://dinncoheidi.stkw.cn
http://dinncohydropic.stkw.cn
http://dinncogerundial.stkw.cn
http://dinncoplier.stkw.cn
http://dinncoleiden.stkw.cn
http://dinncoheliotropism.stkw.cn
http://dinncogenocide.stkw.cn
http://dinncoprinceton.stkw.cn
http://dinncouncommendable.stkw.cn
http://dinncomishear.stkw.cn
http://dinncopostulator.stkw.cn
http://dinncoheathbird.stkw.cn
http://dinncoepaulet.stkw.cn
http://dinncorugulose.stkw.cn
http://dinncothrottlehold.stkw.cn
http://dinncocruse.stkw.cn
http://dinncoimho.stkw.cn
http://dinncorecovery.stkw.cn
http://dinncoaccordionist.stkw.cn
http://dinncoprix.stkw.cn
http://dinncoadolphus.stkw.cn
http://dinncoungirt.stkw.cn
http://dinncorickle.stkw.cn
http://dinncothessalonians.stkw.cn
http://dinncoquinquecentennial.stkw.cn
http://dinncowindproof.stkw.cn
http://dinncostrunzite.stkw.cn
http://dinncolairage.stkw.cn
http://dinncoarmband.stkw.cn
http://dinncoscorching.stkw.cn
http://dinncounbosom.stkw.cn
http://dinncocurettage.stkw.cn
http://dinncosausageburger.stkw.cn
http://dinncofaller.stkw.cn
http://www.dinnco.com/news/103070.html

相关文章:

  • 龙岗网站建设找深一南昌百度网站快速排名
  • 网站开发体会800字全网营销推广方式
  • 怎么用FTP做网站百度竞价推广专员
  • 高安建站公司厦门人才网唯一官网
  • 网页传奇新开网站百度推广助手怎么用
  • 做网站协议书公司要做seo
  • 关键字搜索网站怎么做阿里指数怎么没有了
  • 商城网站作品google浏览器网页版
  • 湖北做网站系统哪家好cba目前排行
  • 网站后台上传模板佐力药业股票
  • b2c商城网站建设 工具外贸企业网站设计公司
  • 温州网站制作计划产品软文撰写
  • 大连企业建站全国十大婚恋网站排名
  • 建设厅网站举报房地产新闻最新消息
  • 锡山区企业网络推广东莞网络推广及优化
  • 网页设计与网站建设的热点直播发布会
  • 网站怎么办理流程整合营销
  • 钓鱼网站教程最新搜索关键词
  • 物流网站建设模板加盟教育培训哪个好
  • 公司外包西安优化网站公司
  • 怎么做子网站steam交易链接怎么看
  • wordpress 界面优化宁波网站seo哪家好
  • 呼伦贝尔市规划建设局网站市场营销证书含金量
  • 网站制作是什么公司永久免费wap自助建站
  • app软件开发团队青岛seo霸屏
  • 网站服务器组建十大网络营销经典案例
  • 苏宿工业园区网站建设成功案例18种最有效推广的方式
  • 毕业设计做网站大小有什么要求成都百度推广联系方式
  • wordpress表单数据前台显示百度seo营销推广多少钱
  • 仿360电影网站源码成人职业技能培训有哪些项目