zoukankan      html  css  js  c++  java
  • 2021-4-17 周报博客

    个人博客

    1.学到的东西

    06-JdbcTemplate基本使用-spring产生模板对象代码实现(抽取jdbc.properties)(应用)

    将数据库的连接信息抽取到外部配置文件中,和spring的配置文件分离开,有利于后期维护

    jdbc.driver=com.mysql.jdbc.Driver
    jdbc.url=jdbc:mysql://localhost:3306/test
    jdbc.username=root
    jdbc.password=root
    

    配置文件修改为:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="
           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
    ">
    
        <!--加载jdbc.properties-->
        <context:property-placeholder location="classpath:jdbc.properties"/>
    
        <!--数据源对象-->
        <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <property name="driverClass" value="${jdbc.driver}"/>
            <property name="jdbcUrl" value="${jdbc.url}"/>
            <property name="user" value="${jdbc.username}"/>
            <property name="password" value="${jdbc.password}"/>
        </bean>
    
        <!--jdbc模板对象-->
        <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
            <property name="dataSource" ref="dataSource"/>
        </bean>
    
    </beans>
    

    07-JdbcTemplate基本使用-常用操作-更新操作(应用)

    package com.itheima.test;
    
    import com.itheima.domain.Account;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.jdbc.core.BeanPropertyRowMapper;
    import org.springframework.jdbc.core.JdbcTemplate;
    import org.springframework.test.context.ContextConfiguration;
    import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    
    import java.util.List;
    
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration("classpath:applicationContext.xml")
    public class JdbcTemplateCRUDTest {
    
        @Autowired
        private JdbcTemplate jdbcTemplate;
        
    	//修改更新
        @Test
        public void testUpdate(){
            jdbcTemplate.update("update account set money=? where name=?",10000,"tom");
        }
    	//删除
        @Test
        public void testDelete(){
            jdbcTemplate.update("delete from account where name=?","tom");
        }
    
    }
    
    

    2.明日计划

    继续学习

    3.遇到的问题

  • 相关阅读:
    [纯C#实现]基于BP神经网络的中文手写识别算法
    【转载】Jedis对管道、事务以及Watch的操作详细解析
    redis 缓存用户账单策略
    redis 通配符 批量删除key
    explain分析sql效率
    mysql 常用命令大全
    【转载】实战mysql分区(PARTITION)
    mysql表名忽略大小写配置
    【转】微服务架构的分布式事务解决方案
    【转载】Mysql中的Btree与Hash索引比较
  • 原文地址:https://www.cnblogs.com/gongyunlong-blogs/p/14912115.html
Copyright © 2011-2022 走看看