Spring

基本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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">


<bean id="mysqlImpl" class="com.chen.dao.UserDaoMysqlImpl"></bean>

<bean id="UserServiceImpl" class="com.chen.service.UserServiceImpl">

</beans>





C/P命名空间

<?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:p="http://www.springframework.org/schema/p"
xmlns:c="http://www.springframework.org/schema/c"
xsi:schemaLocation="http://www.springframework.org/schema/beans

https://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="user" class="com.chen.pojo.User" p:name="辰呀" p:age="18"/>


<!-- c 命名空间注入,通过构造器注入:construct-args -->
<bean id="user2" class="com.chen.pojo.User" c:age="22" c:name="辰呀cc" scope="singleton"/>
</beans>





注解开发

<?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:contex="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd">

<!-- 指定要扫描的包 ,这个包下的注解就会生效 -->
<contex:component-scan base-package="com.chen.pojo"/>
<!-- 注解驱动 -->
<context:annotation-config/>
</beans>





AOP

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:aop="http://www.springframework.org/schema/aop"
xmlns:contex="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
https://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 指定要扫描的包 ,这个包下的注解就会生效 -->
<contex:component-scan base-package="c"/>
<!-- <bean id="userDao" class="c.annotation.UserDaoImpl"/>-->
<!-- 采用自定义类实现SOP -->
<bean id="diy" class="c.aspectj.log.MyPointCut"/>
<aop:config>
<!-- 自定义切面,ref: 要引用的类 -->
<aop:aspect ref="diy">
<!-- 切入点 -->
<aop:pointcut id="point" expression="execution(* c.annotation.UserDaoImpl.*(..))"/>
<!-- 通知 -->
<aop:before method="before" pointcut-ref="point"/>
<aop:after method="after" pointcut-ref="point"/>
<aop:around method="around" pointcut-ref="point"/>
<aop:after-throwing method="AfterThrowing" pointcut-ref="point" throwing="exception"/>
</aop:aspect>
</aop:config>
</beans>


annotation方式:

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:contex="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
https://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd">

<contex:component-scan base-package="c"/>
<!-- 注解实现AOP -->
<!-- 切面类 -->
<bean id="annotationPointCut" class="c.aspectj.annotaion.SpringJUnit4ClassRunner"/>
<!-- 开启注解支持 JDK(默认:proxy-target-class="true") -->
<aop:aspectj-autoproxy />

</beans>





jdbc驱动

  • jar包
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.44</version>
</dependency>


//1.加载驱动
Class.forName("com.mysql.jdbc.Driver");

//2.url
String url = "jdbc:mysql://localhost:3306/c2c?useUnicode=true&characterEncoding=utf8&useSSL=false";
String username = "root";
String password = "123456";