First, the jar packages required for IOC functionality, AOP functionality, JdbcTemplate functionality in the gathered up Spring framework, currently 13 jar packages
1. The four core jar packages in spring Compress package to achieve IOC control inversion based on an XML configuration file or annotation generation object
Beans, context, core, and expression
:
Https://pan.baidu.com/s/1qXLHzAW
2. And log jar package to view relevant execution details
Commons-logging and log4j
:
https://pan.baidu.com/s/1mimTW5i
3. Add one more
Spring-aop-5.0.1.release.jar (for annotations, included in the Spring-framework library)
4. Further increase
Spring-aspects-5.0.1.release.jar (included in the Spring-framework library)
Aspectjweaver-1.8.12.jar (Official Http://mvnrepository.com/artifact/org.aspectj/aspectjweaver)
Aopalliance-1.0.jar (Official http://mvnrepository.com/artifact/aopalliance/aopalliance/1.0)
Implement AOP functionality to enhance relevant pointcuts
5, JdbcTemplate function required jar Package
Spring-jdbc-4.2.4.release.jar
Spring-tx-4.2.4.release.jar
Spring Framework jar Package
Link: Https://pan.baidu.com/s/1bpydNGV Password: 2KVK
6. Connect MySQL Database jar package
Mysql-connector-java-5.1.7-bin.jar
: Link: https://pan.baidu.com/s/1geBRqqn Password: 8JXM
To remove data from a database by applying the JdbcTemplate method of the spring framework
PackageCom.swift;Importorg.springframework.jdbc.core.JdbcTemplate;ImportOrg.springframework.jdbc.datasource.DriverManagerDataSource;Importorg.springframework.stereotype.Component; @Component (Value= "Jdbctemplatedemo") Public classJdbctemplatedemo { Public BooleanDelete (String username) {Drivermanagerdatasource DataSource=NewDrivermanagerdatasource (); Datasource.setdriverclassname ("Com.mysql.jdbc.Driver"); Datasource.seturl ("Jdbc:mysql://localhost:3306/sw_database"); Datasource.setusername ("Root"); Datasource.setpassword ("Root"); JdbcTemplate JdbcTemplate=NewJdbcTemplate (DataSource); intCount=jdbctemplate.update ("Delete from Sw_user where username=?"), username); if(count!=0) { return true; } return false; }}
The annotation method generates the object with the required XML configuration file code:
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "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 "> <!--Turn on annotation scanning-objects and properties - <Context:component-scanBase-package= "Com.swift"></Context:component-scan> <!--Open the AOP annotation method - <Aop:aspectj-autoproxy></Aop:aspectj-autoproxy> </Beans>
Call JdbcTemplate to delete the database information from the Servlet class code:
PackageCom.swift;Importjava.io.IOException;Importjavax.servlet.ServletException;ImportJavax.servlet.annotation.WebServlet;ImportJavax.servlet.http.HttpServlet;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;ImportOrg.springframework.context.ApplicationContext;ImportOrg.springframework.context.support.ClassPathXmlApplicationContext; @WebServlet ("/test") Public classServlettestextendsHttpServlet {Private Static Final LongSerialversionuid = 1L; Publicservlettest () {Super(); } protected voidDoget (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException {response.getwriter (). Append ("Served at:"). Append (Request.getcontextpath ()); @SuppressWarnings ("Resource") ApplicationContext Context=NewClasspathxmlapplicationcontext ("Aop.xml"); Jdbctemplatedemo Jdbctemplatedemo= (Jdbctemplatedemo) context.getbean ("Jdbctemplatedemo"); if(Jdbctemplatedemo.delete ("Wangwu") {response.getwriter (). Append ("Delete success!"); }Else{response.getwriter (). Append ("Delete success!"); } } protected voidDoPost (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException {doget (request, response); }}
Spring Framework for DAO layer jdbctemplate operations crud Delete Remove database operations Spring related jar package download