commit 910cb70d1b12ef9e4f812dc0590cbe0edc9a1bb0 Author: ytf <2183365846@qq.com> Date: Sun Sep 22 11:08:59 2024 +0800 全部代码 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/artifacts/05_SpringMVC_Quick_Start_Web_exploded.xml b/.idea/artifacts/05_SpringMVC_Quick_Start_Web_exploded.xml new file mode 100644 index 0000000..b4bc415 --- /dev/null +++ b/.idea/artifacts/05_SpringMVC_Quick_Start_Web_exploded.xml @@ -0,0 +1,14 @@ + + + $PROJECT_DIR$/out/artifacts/05_SpringMVC_Quick_Start_Web_exploded + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b4561d9 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..05804d5 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..abb532a --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d1a05df --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,19 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..90a498a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/01-Spring-Quick-Start/pom.xml b/01-Spring-Quick-Start/pom.xml new file mode 100644 index 0000000..32544c0 --- /dev/null +++ b/01-Spring-Quick-Start/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + stu.example + 01-Spring-Quick-Start + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + + org.springframework + spring-context + 6.1.11 + + + + \ No newline at end of file diff --git a/01-Spring-Quick-Start/src/main/java/stu/example/Main.java b/01-Spring-Quick-Start/src/main/java/stu/example/Main.java new file mode 100644 index 0000000..246bfe3 --- /dev/null +++ b/01-Spring-Quick-Start/src/main/java/stu/example/Main.java @@ -0,0 +1,14 @@ +package stu.example; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import stu.example.entity.Student; + +public class Main { + public static void main(String[] args) { + ApplicationContext context = new ClassPathXmlApplicationContext("application.xml"); + //默认使用单例模式 + Student student = (Student) context.getBean("student"); + student.hello(); + } +} diff --git a/01-Spring-Quick-Start/src/main/java/stu/example/entity/ArtStudent.java b/01-Spring-Quick-Start/src/main/java/stu/example/entity/ArtStudent.java new file mode 100644 index 0000000..e4a64ca --- /dev/null +++ b/01-Spring-Quick-Start/src/main/java/stu/example/entity/ArtStudent.java @@ -0,0 +1,7 @@ +package stu.example.entity; + +public class ArtStudent extends Student{ + public void art(){ + System.out.println("我爱画画"); + } +} diff --git a/01-Spring-Quick-Start/src/main/java/stu/example/entity/SportsStudent.java b/01-Spring-Quick-Start/src/main/java/stu/example/entity/SportsStudent.java new file mode 100644 index 0000000..e519dc7 --- /dev/null +++ b/01-Spring-Quick-Start/src/main/java/stu/example/entity/SportsStudent.java @@ -0,0 +1,7 @@ +package stu.example.entity; + +public class SportsStudent extends Student{ + public void sport(){ + System.out.println("我爱运动"); + } +} diff --git a/01-Spring-Quick-Start/src/main/java/stu/example/entity/Student.java b/01-Spring-Quick-Start/src/main/java/stu/example/entity/Student.java new file mode 100644 index 0000000..3204839 --- /dev/null +++ b/01-Spring-Quick-Start/src/main/java/stu/example/entity/Student.java @@ -0,0 +1,7 @@ +package stu.example.entity; + +public class Student { + public void hello(){ + System.out.println("Hello"); + } +} diff --git a/01-Spring-Quick-Start/src/main/resources/application.xml b/01-Spring-Quick-Start/src/main/resources/application.xml new file mode 100644 index 0000000..31bd7b7 --- /dev/null +++ b/01-Spring-Quick-Start/src/main/resources/application.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/01-Spring-Quick-Start/target/classes/application.xml b/01-Spring-Quick-Start/target/classes/application.xml new file mode 100644 index 0000000..31bd7b7 --- /dev/null +++ b/01-Spring-Quick-Start/target/classes/application.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/01-Spring-Quick-Start/target/classes/stu/example/Main.class b/01-Spring-Quick-Start/target/classes/stu/example/Main.class new file mode 100644 index 0000000..a0807c4 Binary files /dev/null and b/01-Spring-Quick-Start/target/classes/stu/example/Main.class differ diff --git a/01-Spring-Quick-Start/target/classes/stu/example/entity/ArtStudent.class b/01-Spring-Quick-Start/target/classes/stu/example/entity/ArtStudent.class new file mode 100644 index 0000000..68a6701 Binary files /dev/null and b/01-Spring-Quick-Start/target/classes/stu/example/entity/ArtStudent.class differ diff --git a/01-Spring-Quick-Start/target/classes/stu/example/entity/SportsStudent.class b/01-Spring-Quick-Start/target/classes/stu/example/entity/SportsStudent.class new file mode 100644 index 0000000..3ee4239 Binary files /dev/null and b/01-Spring-Quick-Start/target/classes/stu/example/entity/SportsStudent.class differ diff --git a/01-Spring-Quick-Start/target/classes/stu/example/entity/Student.class b/01-Spring-Quick-Start/target/classes/stu/example/entity/Student.class new file mode 100644 index 0000000..6aacdc1 Binary files /dev/null and b/01-Spring-Quick-Start/target/classes/stu/example/entity/Student.class differ diff --git a/02-Spring-Dependency-Injection-1/pom.xml b/02-Spring-Dependency-Injection-1/pom.xml new file mode 100644 index 0000000..1e9b452 --- /dev/null +++ b/02-Spring-Dependency-Injection-1/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + stu.example + 02-Spring-Dependency-Injection-1 + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + + org.springframework + spring-context + 6.1.11 + + + org.projectlombok + lombok + 1.18.26 + + + \ No newline at end of file diff --git a/02-Spring-Dependency-Injection-1/src/main/java/edu/ytf/entity/Main.java b/02-Spring-Dependency-Injection-1/src/main/java/edu/ytf/entity/Main.java new file mode 100644 index 0000000..ec824ef --- /dev/null +++ b/02-Spring-Dependency-Injection-1/src/main/java/edu/ytf/entity/Main.java @@ -0,0 +1,14 @@ +package edu.ytf.entity; + +import edu.ytf.entity.entity.Student; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class Main { + public static void main(String[] args) { + ApplicationContext context = new ClassPathXmlApplicationContext("application.xml"); + Student student = (Student) context.getBean("student"); + student.study(); + System.out.println(student); + } +} diff --git a/02-Spring-Dependency-Injection-1/src/main/java/edu/ytf/entity/entity/ArtTeacher.java b/02-Spring-Dependency-Injection-1/src/main/java/edu/ytf/entity/entity/ArtTeacher.java new file mode 100644 index 0000000..9198309 --- /dev/null +++ b/02-Spring-Dependency-Injection-1/src/main/java/edu/ytf/entity/entity/ArtTeacher.java @@ -0,0 +1,8 @@ +package edu.ytf.entity.entity; + +public class ArtTeacher implements Teacher{ + @Override + public void teach() { + System.out.println("我爱画画"); + } +} diff --git a/02-Spring-Dependency-Injection-1/src/main/java/edu/ytf/entity/entity/PETeacher.java b/02-Spring-Dependency-Injection-1/src/main/java/edu/ytf/entity/entity/PETeacher.java new file mode 100644 index 0000000..5031cee --- /dev/null +++ b/02-Spring-Dependency-Injection-1/src/main/java/edu/ytf/entity/entity/PETeacher.java @@ -0,0 +1,8 @@ +package edu.ytf.entity.entity; + +public class PETeacher implements Teacher{ + @Override + public void teach() { + System.out.println("我爱打球"); + } +} diff --git a/02-Spring-Dependency-Injection-1/src/main/java/edu/ytf/entity/entity/Student.java b/02-Spring-Dependency-Injection-1/src/main/java/edu/ytf/entity/entity/Student.java new file mode 100644 index 0000000..6e382fd --- /dev/null +++ b/02-Spring-Dependency-Injection-1/src/main/java/edu/ytf/entity/entity/Student.java @@ -0,0 +1,24 @@ +package edu.ytf.entity.entity; + +import lombok.Data; + +@Data +public class Student { +// private Teacher teacher = new PETeacher(); + private Teacher teacher; + private String name; + + public void study(){ + teacher.teach(); + } + //构造注入 + public Student(Teacher teacher,String name){ + this.teacher = teacher; + this.name = name; + + } + //要使用依赖注入 要提供一个set方法 +// public void setTeacher(Teacher teacher) { +// this.teacher = teacher; +// } +} diff --git a/02-Spring-Dependency-Injection-1/src/main/java/edu/ytf/entity/entity/Teacher.java b/02-Spring-Dependency-Injection-1/src/main/java/edu/ytf/entity/entity/Teacher.java new file mode 100644 index 0000000..e53f51a --- /dev/null +++ b/02-Spring-Dependency-Injection-1/src/main/java/edu/ytf/entity/entity/Teacher.java @@ -0,0 +1,5 @@ +package edu.ytf.entity.entity; + +public interface Teacher { + void teach(); +} diff --git a/02-Spring-Dependency-Injection-1/src/main/resources/application.xml b/02-Spring-Dependency-Injection-1/src/main/resources/application.xml new file mode 100644 index 0000000..c8279f2 --- /dev/null +++ b/02-Spring-Dependency-Injection-1/src/main/resources/application.xml @@ -0,0 +1,11 @@ + + + + + + + + + \ No newline at end of file diff --git a/02-Spring-Dependency-Injection-1/target/classes/application.xml b/02-Spring-Dependency-Injection-1/target/classes/application.xml new file mode 100644 index 0000000..c8279f2 --- /dev/null +++ b/02-Spring-Dependency-Injection-1/target/classes/application.xml @@ -0,0 +1,11 @@ + + + + + + + + + \ No newline at end of file diff --git a/02-Spring-Dependency-Injection-1/target/classes/edu/ytf/entity/Main.class b/02-Spring-Dependency-Injection-1/target/classes/edu/ytf/entity/Main.class new file mode 100644 index 0000000..6ce0cb6 Binary files /dev/null and b/02-Spring-Dependency-Injection-1/target/classes/edu/ytf/entity/Main.class differ diff --git a/02-Spring-Dependency-Injection-1/target/classes/edu/ytf/entity/entity/ArtTeacher.class b/02-Spring-Dependency-Injection-1/target/classes/edu/ytf/entity/entity/ArtTeacher.class new file mode 100644 index 0000000..96f6320 Binary files /dev/null and b/02-Spring-Dependency-Injection-1/target/classes/edu/ytf/entity/entity/ArtTeacher.class differ diff --git a/02-Spring-Dependency-Injection-1/target/classes/edu/ytf/entity/entity/PETeacher.class b/02-Spring-Dependency-Injection-1/target/classes/edu/ytf/entity/entity/PETeacher.class new file mode 100644 index 0000000..4b57d1f Binary files /dev/null and b/02-Spring-Dependency-Injection-1/target/classes/edu/ytf/entity/entity/PETeacher.class differ diff --git a/02-Spring-Dependency-Injection-1/target/classes/edu/ytf/entity/entity/Student.class b/02-Spring-Dependency-Injection-1/target/classes/edu/ytf/entity/entity/Student.class new file mode 100644 index 0000000..4648bb0 Binary files /dev/null and b/02-Spring-Dependency-Injection-1/target/classes/edu/ytf/entity/entity/Student.class differ diff --git a/02-Spring-Dependency-Injection-1/target/classes/edu/ytf/entity/entity/Teacher.class b/02-Spring-Dependency-Injection-1/target/classes/edu/ytf/entity/entity/Teacher.class new file mode 100644 index 0000000..89c0352 Binary files /dev/null and b/02-Spring-Dependency-Injection-1/target/classes/edu/ytf/entity/entity/Teacher.class differ diff --git a/03-Spring-Annotate/pom.xml b/03-Spring-Annotate/pom.xml new file mode 100644 index 0000000..0be214c --- /dev/null +++ b/03-Spring-Annotate/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + + stu.example + 03-Spring-Annotate + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + + org.springframework + spring-context + 6.1.11 + + + stu.example + 02-Spring-Dependency-Injection-1 + 1.0-SNAPSHOT + compile + + + + \ No newline at end of file diff --git a/03-Spring-Annotate/src/main/java/Main.java b/03-Spring-Annotate/src/main/java/Main.java new file mode 100644 index 0000000..41f6676 --- /dev/null +++ b/03-Spring-Annotate/src/main/java/Main.java @@ -0,0 +1,11 @@ +import edu.ytf.entity.Student; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class Main { + public static void main(String[] args) { + ApplicationContext context = new ClassPathXmlApplicationContext("application.xml"); + Student student = (Student) context.getBean("student"); + student.study(); + } +} \ No newline at end of file diff --git a/03-Spring-Annotate/src/main/java/edu/ytf/application.xml b/03-Spring-Annotate/src/main/java/edu/ytf/application.xml new file mode 100644 index 0000000..1a7b640 --- /dev/null +++ b/03-Spring-Annotate/src/main/java/edu/ytf/application.xml @@ -0,0 +1,11 @@ + + + + + + + + + \ No newline at end of file diff --git a/03-Spring-Annotate/src/main/java/edu/ytf/config/MainConfiguration.java b/03-Spring-Annotate/src/main/java/edu/ytf/config/MainConfiguration.java new file mode 100644 index 0000000..65adfec --- /dev/null +++ b/03-Spring-Annotate/src/main/java/edu/ytf/config/MainConfiguration.java @@ -0,0 +1,9 @@ +package edu.ytf.config; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan() +public class MainConfiguration { +} diff --git a/03-Spring-Annotate/src/main/java/edu/ytf/entity/ArtTeacher.java b/03-Spring-Annotate/src/main/java/edu/ytf/entity/ArtTeacher.java new file mode 100644 index 0000000..ef3d358 --- /dev/null +++ b/03-Spring-Annotate/src/main/java/edu/ytf/entity/ArtTeacher.java @@ -0,0 +1,11 @@ +package edu.ytf.entity; + +import org.springframework.stereotype.Component; + +@Component("artTeacher") +public class ArtTeacher implements Teacher { + @Override + public void teach() { + System.out.println("我是美术老师"); + } +} diff --git a/03-Spring-Annotate/src/main/java/edu/ytf/entity/PETeacher.java b/03-Spring-Annotate/src/main/java/edu/ytf/entity/PETeacher.java new file mode 100644 index 0000000..9edbb32 --- /dev/null +++ b/03-Spring-Annotate/src/main/java/edu/ytf/entity/PETeacher.java @@ -0,0 +1,11 @@ +package edu.ytf.entity; + +import org.springframework.stereotype.Component; + +@Component("PETeacher") +public class PETeacher implements Teacher{ + @Override + public void teach(){ + System.out.println("我是体育老师!"); + } +} diff --git a/03-Spring-Annotate/src/main/java/edu/ytf/entity/Student.java b/03-Spring-Annotate/src/main/java/edu/ytf/entity/Student.java new file mode 100644 index 0000000..608303a --- /dev/null +++ b/03-Spring-Annotate/src/main/java/edu/ytf/entity/Student.java @@ -0,0 +1,19 @@ +package edu.ytf.entity; + +public class Student { + + // private Teacher teacher = new PETeacher(); + private Teacher teacher; + private String name; + public void study(){ + teacher.teach(); + } + public Student(Teacher teacher, String name){ + this.teacher = teacher; + this.name = name; + } + // 要使用依赖注入 要提供一个set方法 + // public void setTeacher(Teacher teacher){ + // this.teacher = teacher; + // } +} diff --git a/03-Spring-Annotate/src/main/java/edu/ytf/entity/Teacher.java b/03-Spring-Annotate/src/main/java/edu/ytf/entity/Teacher.java new file mode 100644 index 0000000..9c75a9e --- /dev/null +++ b/03-Spring-Annotate/src/main/java/edu/ytf/entity/Teacher.java @@ -0,0 +1,5 @@ +package edu.ytf.entity; + +public interface Teacher { + void teach(); +} diff --git a/03-Spring-Annotate/target/classes/Main.class b/03-Spring-Annotate/target/classes/Main.class new file mode 100644 index 0000000..78c1e39 Binary files /dev/null and b/03-Spring-Annotate/target/classes/Main.class differ diff --git a/03-Spring-Annotate/target/classes/edu/ytf/config/MainConfiguration.class b/03-Spring-Annotate/target/classes/edu/ytf/config/MainConfiguration.class new file mode 100644 index 0000000..930eaa4 Binary files /dev/null and b/03-Spring-Annotate/target/classes/edu/ytf/config/MainConfiguration.class differ diff --git a/03-Spring-Annotate/target/classes/edu/ytf/entity/ArtTeacher.class b/03-Spring-Annotate/target/classes/edu/ytf/entity/ArtTeacher.class new file mode 100644 index 0000000..85b1c54 Binary files /dev/null and b/03-Spring-Annotate/target/classes/edu/ytf/entity/ArtTeacher.class differ diff --git a/03-Spring-Annotate/target/classes/edu/ytf/entity/PETeacher.class b/03-Spring-Annotate/target/classes/edu/ytf/entity/PETeacher.class new file mode 100644 index 0000000..9e56494 Binary files /dev/null and b/03-Spring-Annotate/target/classes/edu/ytf/entity/PETeacher.class differ diff --git a/03-Spring-Annotate/target/classes/edu/ytf/entity/Student.class b/03-Spring-Annotate/target/classes/edu/ytf/entity/Student.class new file mode 100644 index 0000000..6c8067e Binary files /dev/null and b/03-Spring-Annotate/target/classes/edu/ytf/entity/Student.class differ diff --git a/03-Spring-Annotate/target/classes/edu/ytf/entity/Teacher.class b/03-Spring-Annotate/target/classes/edu/ytf/entity/Teacher.class new file mode 100644 index 0000000..ab3af4d Binary files /dev/null and b/03-Spring-Annotate/target/classes/edu/ytf/entity/Teacher.class differ diff --git a/04-Spring-Annotate/pom.xml b/04-Spring-Annotate/pom.xml new file mode 100644 index 0000000..cbd8fd8 --- /dev/null +++ b/04-Spring-Annotate/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + stu.example + 04-Spring-Annotate + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + + org.springframework + spring-context + 6.1.11 + + + org.projectlombok + lombok + 1.18.26 + + + jakarta.annotation + jakarta.annotation-api + 2.1.1 + + + \ No newline at end of file diff --git a/04-Spring-Annotate/src/main/java/edu/ytf/Main.java b/04-Spring-Annotate/src/main/java/edu/ytf/Main.java new file mode 100644 index 0000000..701f22e --- /dev/null +++ b/04-Spring-Annotate/src/main/java/edu/ytf/Main.java @@ -0,0 +1,13 @@ +package edu.ytf; + +import edu.ytf.controller.TestController; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class Main { + public static void main(String[] args) { + ApplicationContext context = new ClassPathXmlApplicationContext("application.xml"); + TestController testController = (TestController) context.getBean("testController"); + testController.save(); + } +} diff --git a/04-Spring-Annotate/src/main/java/edu/ytf/controller/TestController.java b/04-Spring-Annotate/src/main/java/edu/ytf/controller/TestController.java new file mode 100644 index 0000000..4ff87a8 --- /dev/null +++ b/04-Spring-Annotate/src/main/java/edu/ytf/controller/TestController.java @@ -0,0 +1,15 @@ +package edu.ytf.controller; + +import edu.ytf.service.TestService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; + +@Controller +public class TestController { + @Autowired + private TestService testService; + public void save(){ + testService.save(); + System.out.println("TestController save..."); + } +} diff --git a/04-Spring-Annotate/src/main/java/edu/ytf/dao/TestDao.java b/04-Spring-Annotate/src/main/java/edu/ytf/dao/TestDao.java new file mode 100644 index 0000000..9576ed9 --- /dev/null +++ b/04-Spring-Annotate/src/main/java/edu/ytf/dao/TestDao.java @@ -0,0 +1,5 @@ +package edu.ytf.dao; + +public interface TestDao { + void save(); +} diff --git a/04-Spring-Annotate/src/main/java/edu/ytf/dao/TestDaoImpl.java b/04-Spring-Annotate/src/main/java/edu/ytf/dao/TestDaoImpl.java new file mode 100644 index 0000000..b3ce3b6 --- /dev/null +++ b/04-Spring-Annotate/src/main/java/edu/ytf/dao/TestDaoImpl.java @@ -0,0 +1,12 @@ +package edu.ytf.dao; + +import org.springframework.stereotype.Repository; + +//Data Access Object +@Repository("testDaoImpl")//用于标记数据访问层的类 +public class TestDaoImpl implements TestDao{ + @Override + public void save() { + System.out.println("TestDaoImpl save ..."); + } +} diff --git a/04-Spring-Annotate/src/main/java/edu/ytf/service/TestService.java b/04-Spring-Annotate/src/main/java/edu/ytf/service/TestService.java new file mode 100644 index 0000000..fd3e7b6 --- /dev/null +++ b/04-Spring-Annotate/src/main/java/edu/ytf/service/TestService.java @@ -0,0 +1,6 @@ +package edu.ytf.service; + +public interface TestService { + void save(); + +} diff --git a/04-Spring-Annotate/src/main/java/edu/ytf/service/TestServiceImpl.java b/04-Spring-Annotate/src/main/java/edu/ytf/service/TestServiceImpl.java new file mode 100644 index 0000000..372dff3 --- /dev/null +++ b/04-Spring-Annotate/src/main/java/edu/ytf/service/TestServiceImpl.java @@ -0,0 +1,16 @@ +package edu.ytf.service; + +import edu.ytf.dao.TestDao; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; + +@Service("testServiceImpl") +public class TestServiceImpl implements TestService{ + @Resource(name="testDaoImpl") + private TestDao testDao; + @Override + public void save() { + testDao.save(); + System.out.println("TestServiceImpl save ..."); + } +} diff --git a/04-Spring-Annotate/src/main/resources/application.xml b/04-Spring-Annotate/src/main/resources/application.xml new file mode 100644 index 0000000..1700dab --- /dev/null +++ b/04-Spring-Annotate/src/main/resources/application.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/04-Spring-Annotate/target/classes/application.xml b/04-Spring-Annotate/target/classes/application.xml new file mode 100644 index 0000000..1700dab --- /dev/null +++ b/04-Spring-Annotate/target/classes/application.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/04-Spring-Annotate/target/classes/edu/ytf/Main.class b/04-Spring-Annotate/target/classes/edu/ytf/Main.class new file mode 100644 index 0000000..39bce81 Binary files /dev/null and b/04-Spring-Annotate/target/classes/edu/ytf/Main.class differ diff --git a/04-Spring-Annotate/target/classes/edu/ytf/controller/TestController.class b/04-Spring-Annotate/target/classes/edu/ytf/controller/TestController.class new file mode 100644 index 0000000..722840d Binary files /dev/null and b/04-Spring-Annotate/target/classes/edu/ytf/controller/TestController.class differ diff --git a/04-Spring-Annotate/target/classes/edu/ytf/dao/TestDao.class b/04-Spring-Annotate/target/classes/edu/ytf/dao/TestDao.class new file mode 100644 index 0000000..c09eefe Binary files /dev/null and b/04-Spring-Annotate/target/classes/edu/ytf/dao/TestDao.class differ diff --git a/04-Spring-Annotate/target/classes/edu/ytf/dao/TestDaoImpl.class b/04-Spring-Annotate/target/classes/edu/ytf/dao/TestDaoImpl.class new file mode 100644 index 0000000..788ffab Binary files /dev/null and b/04-Spring-Annotate/target/classes/edu/ytf/dao/TestDaoImpl.class differ diff --git a/04-Spring-Annotate/target/classes/edu/ytf/service/TestService.class b/04-Spring-Annotate/target/classes/edu/ytf/service/TestService.class new file mode 100644 index 0000000..f227f6a Binary files /dev/null and b/04-Spring-Annotate/target/classes/edu/ytf/service/TestService.class differ diff --git a/04-Spring-Annotate/target/classes/edu/ytf/service/TestServiceImpl.class b/04-Spring-Annotate/target/classes/edu/ytf/service/TestServiceImpl.class new file mode 100644 index 0000000..c7e39a4 Binary files /dev/null and b/04-Spring-Annotate/target/classes/edu/ytf/service/TestServiceImpl.class differ diff --git a/05-SpringMVC-Quick-Start/pom.xml b/05-SpringMVC-Quick-Start/pom.xml new file mode 100644 index 0000000..b58d973 --- /dev/null +++ b/05-SpringMVC-Quick-Start/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + stu.example + 05-SpringMVC-Quick-Start + 1.0-SNAPSHOT + 05-SpringMVC-Quick-Start + war + + + UTF-8 + 17 + 17 + 5.11.0-M2 + + + + + jakarta.servlet + jakarta.servlet-api + 6.1.0 + provided + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + org.springframework + spring-webmvc + 6.1.6 + + + + + + + org.apache.maven.plugins + maven-war-plugin + 3.4.0 + + + \ No newline at end of file diff --git a/05-SpringMVC-Quick-Start/src/main/java/stu/example/controller/IndexController.java b/05-SpringMVC-Quick-Start/src/main/java/stu/example/controller/IndexController.java new file mode 100644 index 0000000..836245f --- /dev/null +++ b/05-SpringMVC-Quick-Start/src/main/java/stu/example/controller/IndexController.java @@ -0,0 +1,15 @@ +package stu.example.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +public class IndexController { + @RequestMapping("/hello") + @ResponseBody + public String hello(){ + System.out.println("Welcome to Spring MVC!"); + return "Welcome to Spring MVC!"; + } +} diff --git a/05-SpringMVC-Quick-Start/src/main/resources/springmvc.xml b/05-SpringMVC-Quick-Start/src/main/resources/springmvc.xml new file mode 100644 index 0000000..a29b5ae --- /dev/null +++ b/05-SpringMVC-Quick-Start/src/main/resources/springmvc.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/05-SpringMVC-Quick-Start/src/main/webapp/WEB-INF/web.xml b/05-SpringMVC-Quick-Start/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..ebf0483 --- /dev/null +++ b/05-SpringMVC-Quick-Start/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,21 @@ + + + + + springmvc + org.springframework.web.server.DispatcherServlet + + contextConfigLocation + classpath:springmvc.xml + + + 1 + + + springmvc + /* + + \ No newline at end of file diff --git a/05-SpringMVC-Quick-Start/src/main/webapp/index.jsp b/05-SpringMVC-Quick-Start/src/main/webapp/index.jsp new file mode 100644 index 0000000..3d6d7b9 --- /dev/null +++ b/05-SpringMVC-Quick-Start/src/main/webapp/index.jsp @@ -0,0 +1,12 @@ +<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> + + + + JSP - Hello World + + +

<%= "Hello World!" %>

+
+Hello Servlet + + \ No newline at end of file diff --git a/05-SpringMVC-Quick-Start/target/classes/springmvc.xml b/05-SpringMVC-Quick-Start/target/classes/springmvc.xml new file mode 100644 index 0000000..a29b5ae --- /dev/null +++ b/05-SpringMVC-Quick-Start/target/classes/springmvc.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/05-SpringMVC-Quick-Start/target/classes/stu/example/controller/IndexController.class b/05-SpringMVC-Quick-Start/target/classes/stu/example/controller/IndexController.class new file mode 100644 index 0000000..5068296 Binary files /dev/null and b/05-SpringMVC-Quick-Start/target/classes/stu/example/controller/IndexController.class differ diff --git a/06-SpringBoot-Quick-Start/.gitignore b/06-SpringBoot-Quick-Start/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/06-SpringBoot-Quick-Start/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/06-SpringBoot-Quick-Start/pom.xml b/06-SpringBoot-Quick-Start/pom.xml new file mode 100644 index 0000000..2a1abf5 --- /dev/null +++ b/06-SpringBoot-Quick-Start/pom.xml @@ -0,0 +1,76 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.3.3 + + + edu.ytf + 06-SpringBoot-Quick-Start + 0.0.1-SNAPSHOT + 06-SpringBoot-Quick-Start + 06-SpringBoot-Quick-Start + + + + + + + + + + + + + + + 17 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-devtools + true + + + + + + + org.graalvm.buildtools + native-maven-plugin + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/Application.java b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/Application.java new file mode 100644 index 0000000..75efdcb --- /dev/null +++ b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/Application.java @@ -0,0 +1,13 @@ +package edu.ytf.springbootquickstart; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/ArrayParamsController.java b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/ArrayParamsController.java new file mode 100644 index 0000000..a4a5985 --- /dev/null +++ b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/ArrayParamsController.java @@ -0,0 +1,27 @@ +package edu.ytf.springbootquickstart.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Arrays; +import java.util.List; + +@RestController +public class ArrayParamsController { + // 数组参数 + //URL: http://localhost:8080/arrayTest?hobby=LOL&hobby=WUKONG + @RequestMapping(value = "/arrayTest") + public String arrayTest(String[] hobby){ + System.out.println(Arrays.toString(hobby)); + return "Get 请求, hobby=" + Arrays.toString(hobby); + } + + //集合参数 + //URL: http://localhost:8080/listTest?hobby=LOL&hobby=WUKONG + @RequestMapping(value = "/listTest") + public String listTest(@RequestParam List hobby){ + System.out.println(hobby); + return "Get 请求, hobby=" + hobby; + } +} diff --git a/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/DateParamsController.java b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/DateParamsController.java new file mode 100644 index 0000000..745c4d1 --- /dev/null +++ b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/DateParamsController.java @@ -0,0 +1,20 @@ +package edu.ytf.springbootquickstart.controller; + +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +@RestController +public class DateParamsController { + + + @RequestMapping("/dateTest") + //URL: http://localhost:8080/dateTest?dateTime=2024-09-18 16:50:00 + public String dateTest(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")LocalDateTime dateTime){ + System.out.println(dateTime); + return dateTime.toString(); + } +} diff --git a/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/HelloController.java b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/HelloController.java new file mode 100644 index 0000000..b35c27e --- /dev/null +++ b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/HelloController.java @@ -0,0 +1,18 @@ +package edu.ytf.springbootquickstart.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HelloController { + // URL: 协议://ip:端口/路径 + //UR: http://localhost:8080/hello +// @GetMapping("/hello")//通过Get请求访问到方法 + @RequestMapping(value = "/hello",method = RequestMethod.GET) + public String hello(){ + return "你好,SpringBoot!!!"; + + } +} diff --git a/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/JsonParamsController.java b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/JsonParamsController.java new file mode 100644 index 0000000..486b07e --- /dev/null +++ b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/JsonParamsController.java @@ -0,0 +1,14 @@ +package edu.ytf.springbootquickstart.controller; + +import edu.ytf.springbootquickstart.pojo.User; +import org.springframework.web.bind.annotation.*; + +@RestController +public class JsonParamsController { + @RequestMapping(value = "/jsonTest1",method = RequestMethod.POST) + public String jsonTest1(@RequestBody User user){ + System.out.println(user); + return "Post 请求, name=" + user.getUsername() + ",password=" +user.getPassword() + + ",province=" +user.getAddress().getProvince() +",city="+user.getAddress().getCity(); + } +} diff --git a/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/PathParamsController.java b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/PathParamsController.java new file mode 100644 index 0000000..9889d47 --- /dev/null +++ b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/PathParamsController.java @@ -0,0 +1,35 @@ +package edu.ytf.springbootquickstart.controller; + + +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class PathParamsController { + @RequestMapping("/pathTest1/{id}") + //URL: http://localhost:8080/pathTest1/1 + public String pathTest1(@PathVariable Integer id){ + return "Path: id="+id; + } + + @RequestMapping("/pathTest2/{id}/{name}") + //URL: http://localhost:8080/pathTest2/1/ytf + public String pathTest2(@PathVariable Integer id,@PathVariable String name){ + return "Path: id="+id +",name="+name; + } + + // ** 任意路径(可以有多级路径) + @RequestMapping("/pathTest3/**") + //URL: http://localhost:8080/pathTest3 + public String pathTest3(){ + return "通配符请求:**"; + } + + // ** 只能有一级路径 + @RequestMapping("/pathTest4/*") + //URL: http://localhost:8080/pathTest4 + public String pathTest4(){ + return "通配符请求:*"; + } +} diff --git a/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/PojoParamsController.java b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/PojoParamsController.java new file mode 100644 index 0000000..8c44c2a --- /dev/null +++ b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/PojoParamsController.java @@ -0,0 +1,27 @@ +package edu.ytf.springbootquickstart.controller; + + +import edu.ytf.springbootquickstart.pojo.User; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class PojoParamsController { + //URL: http://localhost:8080/pojoTest1 + @RequestMapping(value = "/pojoTest1",method = RequestMethod.POST) + public String pojoTest1(User user){ + System.out.println(user); + return "Post 请求, name=" + user.getUsername() + ",password=" +user.getPassword(); + + } + + //URL: http://localhost:8080/pojoTest2 + @RequestMapping(value = "/pojoTest2",method = RequestMethod.POST) + public String pojoTest2(User user){ + System.out.println(user); + return "Post 请求, name=" + user.getUsername() + ",password=" +user.getPassword() + + ",province=" +user.getAddress().getProvince() +",city="+user.getAddress().getCity(); + + } +} diff --git a/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/SimpleParamsController.java b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/SimpleParamsController.java new file mode 100644 index 0000000..f1463c6 --- /dev/null +++ b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/controller/SimpleParamsController.java @@ -0,0 +1,48 @@ +package edu.ytf.springbootquickstart.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class SimpleParamsController { + //1.Get 无参数 + //URL: http://localhost:8080/getTest1 + @RequestMapping(value = "getTest1",method = RequestMethod.GET) + public String getTest1(){ + return "Get 请求"; + } + + //2. Get 有参数 + //URL: http://localhost:8080/getTest2?nickname=ytf&age=20 + @RequestMapping(value = "/getTest2",method = RequestMethod.GET) + public String getTest2(String nickname,int age){ + System.out.println("Get 请求, name=" +nickname+ ", age=" +age); + return "Get 请求, name=" +nickname+ ", age=" +age ; + } + + //3. Get 有参数 方法的参数与请求的参数不一致 + //URL: http://localhost:8080/getTest3?nickname=ytf&age=20 + @RequestMapping(value = "/getTest3",method = RequestMethod.GET) + public String getTest3(@RequestParam(value = "nickname",required = false) String nickName, int age){ + System.out.println("Get 请求, name=" +nickName+ ", age=" +age); + return "Get 请求, name=" +nickName+ ", age=" +age ; + } + + //4. Post 无参数 + //URL: http://localhost:8080/postTest1 + @RequestMapping(value = "/postTest1",method = RequestMethod.POST) + public String postTest1(){ + return "Post 请求"; + } + + //5. Post 有参数 + //URL: http://localhost:8080/postTest2 + @RequestMapping(value = "/postTest2",method = RequestMethod.POST) + public String postTest2(String nickname, int age){ + System.out.println("Get 请求, name=" +nickname+ ", age=" +age); + return "Get 请求, name=" +nickname+ ", age=" +age ; + } + +} diff --git a/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/pojo/Address.java b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/pojo/Address.java new file mode 100644 index 0000000..d385bc2 --- /dev/null +++ b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/pojo/Address.java @@ -0,0 +1,11 @@ +package edu.ytf.springbootquickstart.pojo; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Address { + private String province; + private String city; +} diff --git a/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/pojo/User.java b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/pojo/User.java new file mode 100644 index 0000000..e6aaf4a --- /dev/null +++ b/06-SpringBoot-Quick-Start/src/main/java/edu/ytf/springbootquickstart/pojo/User.java @@ -0,0 +1,20 @@ +package edu.ytf.springbootquickstart.pojo; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class User { + private String username; + private String password; + private Address address; + + @Override + public String toString() { + return "User{" + + "username='" + username + '\'' + + ", password='" + password + '\'' + + '}'; + } +} diff --git a/06-SpringBoot-Quick-Start/src/main/resources/application.properties b/06-SpringBoot-Quick-Start/src/main/resources/application.properties new file mode 100644 index 0000000..6bb97b8 --- /dev/null +++ b/06-SpringBoot-Quick-Start/src/main/resources/application.properties @@ -0,0 +1,7 @@ +spring.application.name=06-SpringBoot-Quick-Start +#????? +spring.devtools.restart.enabled=true +#?????? +spring.devtools.restart.additional-paths=src/main/java +#??cLasspath????WEB-INF??????????(????????? +spring.devtools.restart.exclude=static/** diff --git a/06-SpringBoot-Quick-Start/src/test/java/edu/ytf/springbootquickstart/ApplicationTests.java b/06-SpringBoot-Quick-Start/src/test/java/edu/ytf/springbootquickstart/ApplicationTests.java new file mode 100644 index 0000000..21f9203 --- /dev/null +++ b/06-SpringBoot-Quick-Start/src/test/java/edu/ytf/springbootquickstart/ApplicationTests.java @@ -0,0 +1,13 @@ +package edu.ytf.springbootquickstart; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/JavaEE-2024.iml b/JavaEE-2024.iml new file mode 100644 index 0000000..4ebfb83 --- /dev/null +++ b/JavaEE-2024.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/out/artifacts/05_SpringMVC_Quick_Start_Web_exploded/WEB-INF/web.xml b/out/artifacts/05_SpringMVC_Quick_Start_Web_exploded/WEB-INF/web.xml new file mode 100644 index 0000000..d80081d --- /dev/null +++ b/out/artifacts/05_SpringMVC_Quick_Start_Web_exploded/WEB-INF/web.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/out/artifacts/05_SpringMVC_Quick_Start_Web_exploded/index.jsp b/out/artifacts/05_SpringMVC_Quick_Start_Web_exploded/index.jsp new file mode 100644 index 0000000..3d6d7b9 --- /dev/null +++ b/out/artifacts/05_SpringMVC_Quick_Start_Web_exploded/index.jsp @@ -0,0 +1,12 @@ +<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> + + + + JSP - Hello World + + +

<%= "Hello World!" %>

+
+Hello Servlet + + \ No newline at end of file diff --git a/out/artifacts/05_SpringMVC_Quick_Start_Web_exploded/web/WEB-INF/web.xml b/out/artifacts/05_SpringMVC_Quick_Start_Web_exploded/web/WEB-INF/web.xml new file mode 100644 index 0000000..d80081d --- /dev/null +++ b/out/artifacts/05_SpringMVC_Quick_Start_Web_exploded/web/WEB-INF/web.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file