首先,找齐Spring框架中IoC功能、aop功能、JdbcTemplate功能所需的jar包,当前13个Jar包

1、Spring压缩包中的四个核心JAR包,实现IoC控制反转的根据xml配置文件或注解生成对象

beans 、context、core 和expression

下载地址:

https://pan.baidu.com/s/1qXLHzAW

2、以及日志jar包,以便查看相关执行细节

commons-logging 和log4j

下载地址:

https://pan.baidu.com/s/1mimTW5i

3、再增加一个

spring-aop-5.0.1.RELEASE.jar (用于注解,在Spring-framework库中包含)

4、再增加

spring-aspects-5.0.1.RELEASE.jar (在Spring-framework库中包含)

aspectjweaver-1.8.12.jar (官方下载地址 http://mvnrepository.com/artifact/org.aspectj/aspectjweaver)

aopalliance-1.0.jar            (官方下载地址 http://mvnrepository.com/artifact/aopalliance/aopalliance/1.0)

实现aop功能,增强相关的切入点

5、JdbcTemplate功能所需Jar包

spring-jdbc-4.2.4.RELEASE.jar

spring-tx-4.2.4.RELEASE.jar

spring 框架jar包下载地址

链接: https://pan.baidu.com/s/1bpydNGV 密码: 2kvk

6、连接mysql数据库jar包

mysql-connector-java-5.1.7-bin.jar

下载地址:链接: https://pan.baidu.com/s/1geBRqqn 密码: 8jxm


应用Spring框架的JdbcTemplate方法删除数据库中数据

package com.swift;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.stereotype.Component; @Component(value="jdbcTemplateDemo")
public class JdbcTemplateDemo { public boolean delete(String username) {
DriverManagerDataSource dataSource=new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/sw_database");
dataSource.setUsername("root");
dataSource.setPassword("root"); JdbcTemplate jdbcTemplate=new JdbcTemplate(dataSource);
int count=jdbcTemplate.update("delete from sw_user where username=?", username);
if(count!=0) {
return true;
}
return false;
}
}

注解方法生成对象,所需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" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
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
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 开启注解扫描——对象和属性 -->
<context:component-scan base-package="com.swift"></context:component-scan>
<!-- 开启aop注解方法 -->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy> </beans>

调用JdbcTemplate删除数据库信息的Servlet类代码:

package com.swift;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; @WebServlet("/test")
public class ServletTest extends HttpServlet {
private static final long serialVersionUID = 1L; public ServletTest() {
super();
} protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().append("Served at: ").append(request.getContextPath());
@SuppressWarnings("resource")
ApplicationContext context=new ClassPathXmlApplicationContext("aop.xml");
JdbcTemplateDemo jdbcTemplateDemo=(JdbcTemplateDemo) context.getBean("jdbcTemplateDemo");
if(jdbcTemplateDemo.delete("wangwu")) {
response.getWriter().append("delete success!");
}else {
response.getWriter().append("delete success!");
}
} protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
} }

Spring框架针对dao层的jdbcTemplate操作crud之delete删除数据库操作 Spring相关Jar包下载的更多相关文章

  1. Spring框架针对dao层的jdbcTemplate操作之jdbc数据库连接原始操作方法 所需安装包下载

    crud指数据库或者持久层的基本操作,包括 增加(Create).读取查询(Retrieve 取回).更新(Update)和删除(Delete) Spring不仅对JDBC进行了封装,也对Hibern ...

  2. Spring框架针对dao层的jdbcTemplate操作crud之query查询数据操作

    查询目标是完成3个功能: (1)查询表,返回某一个值.例如查询表中记录的条数,返回一个int类型数据 (2)查询表,返回结果为某一个对象. (3)查询表,返回结果为某一个泛型的list集合. 一.查询 ...

  3. Spring框架针对dao层的jdbcTemplate操作crud之update修改数据库操作

    使用jdbcTemplate 原理是把加载驱动Class.forName("com.mysql.jdbc.Driver"); 和连接数据库Connection conn=Drive ...

  4. Spring框架针对dao层的jdbcTemplate操作crud之add添加数据库操作

    使用jdbcTemplate 原理是把加载驱动Class.forName("com.mysql.jdbc.Driver"); 和连接数据库Connection conn=Drive ...

  5. Spring框架针对dao层的jdbcTemplate操作crud之query查询数据操作 —— 查询表,返回结果为对象的list集合

    用JdbcTemplate的方法完成, 查询数据库表,把用户表sw_user所有数据以List<User>集合返回 在JdbcTemplateDemo类中增加查询返回所有对象集合的方法qu ...

  6. 解决Spring框架的Dao层改用@Repository注解,无法使用JdbcDaoSupport的问题

    解决Spring框架的Dao层改用@Repository注解,无法使用JdbcDaoSupport的问题 Alternatively, create an own implementation of ...

  7. ssh整合思想 Spring与Hibernate的整合ssh整合相关JAR包下载 .MySQLDialect方言解决无法服务器启动自动update创建表问题

    除之前的Spring相关包,还有structs2包外,还需要Hibernate的相关包 首先,Spring整合其他持久化层框架的JAR包 spring-orm-4.2.4.RELEASE.jar  ( ...

  8. Spring、MyBatis和SpringMVC整合的jar包下载

    spring mvc的jar包下载:http://repo.springsource.org/libs-release-local/org/springframework/spring/我下载的5.0 ...

  9. Spring配置连接池和 Dao 层使用 jdbcTemplate

    1.Spring 配置 c3p0 连接池 (1)导入jar包(Maven项目) <dependency> <groupId>com.mchange</groupId> ...

随机推荐

  1. C 语言实例 - 使用结构体(struct)

    C 语言实例 - 使用结构体(struct) C 语言实例 C 语言实例 使用结构体(struct)存储学生信息. 实例 #include <stdio.h> struct student ...

  2. python异常之ModuleNotFoundError: No module named 'test01inner02'

    当我们使用sys.path.append(args) 指令向程序中导入模块时其实本次append操作只是在内存中完成的,如果要永久性的添加需要修改环境变量. 我们发现当我们使用print(sys.pa ...

  3. JS的this原理

    转载阮一峰博客: www.ruanyifeng.com/blog/2018/06/javascript-this.html 一.问题的由来   学懂 JavaScript 语言,一个标志就是理解下面两 ...

  4. Django (八) 中间件&验证码&富文本&缓存

    中间件&验证码&富文本&缓存 1. 中间件&AOP   中间件:是一个轻量级的,底层的插件,可以介入Django的请求和响应过程(面向切面编程) ​ 中间件的本质就是一 ...

  5. 洛谷 P1578 奶牛浴场

    https://www.luogu.org/problemnew/show/P1578 题解 另外这题有一些小坑,洛谷的题解里面有讲 #pragma GCC optimize("Ofast& ...

  6. morhpia(4)-更新

    更新由2部分组成:一个查询和一组更新操作符.本例是跟所有薪水小于等于2000的员工涨工资500. @Test public void update() throws Exception { //第一步 ...

  7. python入门之运算符

    计算运算符 + 加 - 减 * 乘 / 除 % 取模,返回余数 ** 幂 // 取整除,返回商的整数部分 比较运算符 == 比较是否相等 != 比较是否不等于 <> 比较是否不等于 > ...

  8. Problem D. What a Beautiful Lake dp

    Problem D. What a Beautiful Lake Description Weiming Lake, also named "Un-named Lake", is ...

  9. 一些JS基本小内容

    获取select选中内容: 1.获取select表单内容 <select id="sel"> <option value="v1">1& ...

  10. WPF学习04:2D绘图 使用Shape绘基本图形

    我们将使用Shape进行基本图形绘制. 例子 一个可移动的矩形方框: XAML代码: <Window x:Class="Shape.MainWindow" xmlns=&qu ...