• Springboot集成JDBC


    1,pom.xml配置jar包

    1. <dependency>
    2. <groupId>org.springframework.bootgroupId>
    3. <artifactId>spring-boot-starter-jdbcartifactId>
    4. dependency>

    2,配置数据源信息 

    1. server:
    2. port: 8088
    3. spring:
    4. datasource:
    5. driver-class-name: com.mysql.cj.jdbc.Driver
    6. url: jdbc:mysql://127.0.0.1:3306/ssm_db?serverTimezone=Asia/Shanghai
    7. username: root
    8. password: 123456
    9. type: com.alibaba.druid.pool.DruidDataSource
    10. initialSize: 5 #初始化时建立物理连接的个数
    11. minIdle: 1 #最小连接池数量
    12. maxActive: 20 #最大连接池数量

     

    LoginDao.java

    1. package com.ffyc.news.dao;
    2. import com.ffyc.news.model.Admin;
    3. import org.junit.Test;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.jdbc.core.JdbcTemplate;
    6. import org.springframework.stereotype.Repository;
    7. import org.springframework.transaction.annotation.Transactional;
    8. @Repository
    9. public class LoginDao {
    10. @Autowired
    11. JdbcTemplate jdbcTemplate;
    12. @Transactional
    13. public void intsert(){
    14. jdbcTemplate.update("insert into admin(account,pwd) value (?,?)","王五","5555");
    15. System.out.println(10/0);
    16. jdbcTemplate.update("insert into admin(account,pwd) value (?,?)","ikun","666");
    17. }
    18. }

    LoginService.java

    1. package com.ffyc.news.service;
    2. import com.ffyc.news.dao.LoginDao;
    3. import org.junit.Test;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.stereotype.Service;
    6. @Service
    7. public class LoginService {
    8. @Autowired
    9. LoginDao loginDao;
    10. public void test(){
    11. loginDao.intsert();
    12. }
    13. }

    LoginController.java

    1. package com.ffyc.news.web;
    2. import com.ffyc.news.service.LoginService;
    3. import org.springframework.beans.factory.annotation.Autowired;
    4. import org.springframework.stereotype.Controller;
    5. import org.springframework.web.bind.annotation.PostMapping;
    6. import org.springframework.web.bind.annotation.RequestMapping;
    7. @Controller
    8. @RequestMapping("/admin/login/")
    9. public class LoginController {
    10. @Autowired
    11. LoginService loginService;
    12. @RequestMapping("/login/")
    13. public void Login(){
    14. loginService.test();
    15. System.out.println("success");
    16. }
    17. }

     

     

     

     

     

  • 相关阅读:
    idea怎么连接redis
    Intel IPP 和Opencv图像处理
    金仓数据库KingbaseES安全指南--5.2. 数据完整性保护
    速卖通商品详情API接口(标题|主图|SKU|价格|商品描述)
    linux操作系统中业务程序及服务的开机启动
    ubuntu20.04中安装mysql8.0步骤
    学习6大步
    聚观早报 |三星将在印度生产5G设备;马斯克邀请盖茨开特斯拉Semi
    安全狗入选2023年国产云原生安全技术代表厂商
    「学习笔记」AC 自动机
  • 原文地址:https://blog.csdn.net/m0_71385141/article/details/134480968