1. 授课安排
讲师:成恒
(微信号:chengheng0707
)
问题反馈:直接反馈到以上微信号,不接受其它方式的课堂反馈。请务必保证每个班至少有1名同学可以实时与我微信反馈信息。
授课时间:每周一,周二,周三,周五,周六,09:00~12:00,14:00~18:00
晚课时间:19:30~21:00(注意:晚课以练习为主,授课内容不会录相,所以也不会有回放,请认真参加)
课程安排:SSM系列框架(约8天),项目(约13天)。
必备软件:Eclipse
,Intellij IDEA
,MySQL
/ MariaDB
, Chrome
/ FireFox
, Typora
2. Spring框架的作用
Spring框架的主要作用是创建对象和管理对象。
创建对象:类似于User user = new User();
管理对象:随时可以通过Spring框架获取对象,甚至Spring框架还能够帮我们为对象的属性进行赋值等。
3. 通过Spring框架创建对象,并获取对象
在Eclipse中创建Maven Project,在创建过程中勾上Create a simple project,Group Id填为cn.tedu
,Artifact Id填为spring01
。
如果某个项目不会被其它项目所使用,只需要保证自身能独立运行,其实Group Id和Artifact Id的值是多少,并不重要。
创建成功后,先在pom.xml中添加以上配置:
<properties> <java.version>1.8</java.version> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties>
然后,对项目名称点击鼠标右键,选择Maven > Update Project以更新Maven,则当前环境会使用Java 1.8。
接下来,需要在pom.xml中添加Spring框架所需的spring-context
依赖的代码:
<dependencies> <!-- https://mvnrepository.com/artifact/org.springframework/spring-context --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.2.6.RELEASE</version> </dependency> </dependencies>
如果需要Spring管理某个类的对象,可以通过自定义的类进行配置!
例如存在需求:使得Spring框架管理Date
类的对象!
先在项目的cn.tedu.spring
包中创建Beans
类,并且,在这个类中自定义方法,方法的返回值类型必须是Date
,然后,自行在方法体中创建出Date
对象并返回即可:
package cn.tedu.spring; import java.util.Date; import org.springframework.context.annotation.Bean; public class Beans {