全部代码
This commit is contained in:
commit
910cb70d1b
|
@ -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
|
|
@ -0,0 +1,14 @@
|
|||
<component name="ArtifactManager">
|
||||
<artifact type="exploded-war" name="05-SpringMVC-Quick-Start:Web exploded">
|
||||
<output-path>$PROJECT_DIR$/out/artifacts/05_SpringMVC_Quick_Start_Web_exploded</output-path>
|
||||
<root id="root">
|
||||
<element id="javaee-facet-resources" facet="05-SpringMVC-Quick-Start/web/Web" />
|
||||
<element id="directory" name="WEB-INF">
|
||||
<element id="directory" name="classes">
|
||||
<element id="module-output" name="05-SpringMVC-Quick-Start" />
|
||||
</element>
|
||||
<element id="directory" name="lib" />
|
||||
</element>
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="true" />
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="02-Spring-Dependency-Injection-1" />
|
||||
<module name="04-Spring-Annotate" />
|
||||
<module name="03-Spring-Annotate" />
|
||||
<module name="01-Spring-Quick-Start" />
|
||||
<module name="05-SpringMVC-Quick-Start" />
|
||||
<module name="06-SpringBoot-Quick-Start" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
<bytecodeTargetLevel target="17" />
|
||||
</component>
|
||||
<component name="JavacSettings">
|
||||
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||
<module name="06-SpringBoot-Quick-Start" options="-parameters" />
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/01-Spring-Quick-Start/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/01-Spring-Quick-Start/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/02-Spring-Dependency-Injection-1/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/02-Spring-Dependency-Injection-1/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/03-Spring-Annotate/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/03-Spring-Annotate/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/04-Spring-Annotate/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/04-Spring-Annotate/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/05-SpringMVC-Quick-Start/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/05-SpringMVC-Quick-Start/src/main/resources" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/06-SpringBoot-Quick-Start/src/main/java" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://maven.aliyun.com/repository/public" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/01-Spring-Quick-Start/pom.xml" />
|
||||
<option value="$PROJECT_DIR$/02-Spring-Dependency-Injection-1/pom.xml" />
|
||||
<option value="$PROJECT_DIR$/03-Spring-Annotate/pom.xml" />
|
||||
<option value="$PROJECT_DIR$/04-Spring-Annotate/pom.xml" />
|
||||
<option value="$PROJECT_DIR$/05-SpringMVC-Quick-Start/pom.xml" />
|
||||
<option value="$PROJECT_DIR$/06-SpringBoot-Quick-Start/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/JavaEE-2024.iml" filepath="$PROJECT_DIR$/JavaEE-2024.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,124 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>stu.example</groupId>
|
||||
<artifactId>01-Spring-Quick-Start</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>6.1.11</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package stu.example.entity;
|
||||
|
||||
public class ArtStudent extends Student{
|
||||
public void art(){
|
||||
System.out.println("我爱画画");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package stu.example.entity;
|
||||
|
||||
public class SportsStudent extends Student{
|
||||
public void sport(){
|
||||
System.out.println("我爱运动");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package stu.example.entity;
|
||||
|
||||
public class Student {
|
||||
public void hello(){
|
||||
System.out.println("Hello");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<?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 http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<bean name="student" class="stu.example.entity.Student"></bean>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,7 @@
|
|||
<?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 http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<bean name="student" class="stu.example.entity.Student"></bean>
|
||||
|
||||
</beans>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>stu.example</groupId>
|
||||
<artifactId>02-Spring-Dependency-Injection-1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>6.1.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.26</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package edu.ytf.entity.entity;
|
||||
|
||||
public class ArtTeacher implements Teacher{
|
||||
@Override
|
||||
public void teach() {
|
||||
System.out.println("我爱画画");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package edu.ytf.entity.entity;
|
||||
|
||||
public class PETeacher implements Teacher{
|
||||
@Override
|
||||
public void teach() {
|
||||
System.out.println("我爱打球");
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
// }
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package edu.ytf.entity.entity;
|
||||
|
||||
public interface Teacher {
|
||||
void teach();
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?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 http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<bean name="teacher" class="edu.ytf.entity.entity.PETeacher"></bean>
|
||||
<bean name="student" class="edu.ytf.entity.entity.Student">
|
||||
<!-- <property name="teacher" ref="teacher"></property>-->
|
||||
<constructor-arg name="teacher" ref="teacher"></constructor-arg>
|
||||
<constructor-arg name="name" value="ytf"></constructor-arg>
|
||||
</bean>
|
||||
</beans>
|
|
@ -0,0 +1,11 @@
|
|||
<?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 http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<bean name="teacher" class="edu.ytf.entity.entity.PETeacher"></bean>
|
||||
<bean name="student" class="edu.ytf.entity.entity.Student">
|
||||
<!-- <property name="teacher" ref="teacher"></property>-->
|
||||
<constructor-arg name="teacher" ref="teacher"></constructor-arg>
|
||||
<constructor-arg name="name" value="ytf"></constructor-arg>
|
||||
</bean>
|
||||
</beans>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>stu.example</groupId>
|
||||
<artifactId>03-Spring-Annotate</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>6.1.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>stu.example</groupId>
|
||||
<artifactId>02-Spring-Dependency-Injection-1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?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 http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<bean name="teacher" class="edu.ytf.entity.ArtTeacher"></bean>
|
||||
<bean name="student" class="edu.ytf.entity.Student">
|
||||
<!-- <property name="teacher" ref="teacher"></property>-->
|
||||
<constructor-arg name="teacher" ref="teacher"></constructor-arg>
|
||||
<constructor-arg name="name" value="ytf"></constructor-arg>
|
||||
</bean>
|
||||
</beans>
|
|
@ -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 {
|
||||
}
|
|
@ -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("我是美术老师");
|
||||
}
|
||||
}
|
|
@ -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("我是体育老师!");
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
// }
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package edu.ytf.entity;
|
||||
|
||||
public interface Teacher {
|
||||
void teach();
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>stu.example</groupId>
|
||||
<artifactId>04-Spring-Annotate</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>6.1.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.26</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.annotation</groupId>
|
||||
<artifactId>jakarta.annotation-api</artifactId>
|
||||
<version>2.1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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...");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package edu.ytf.dao;
|
||||
|
||||
public interface TestDao {
|
||||
void save();
|
||||
}
|
|
@ -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 ...");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package edu.ytf.service;
|
||||
|
||||
public interface TestService {
|
||||
void save();
|
||||
|
||||
}
|
|
@ -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 ...");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<?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"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
|
||||
<context:component-scan base-package="edu.ytf"></context:component-scan>
|
||||
</beans>
|
|
@ -0,0 +1,7 @@
|
|||
<?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"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
|
||||
<context:component-scan base-package="edu.ytf"></context:component-scan>
|
||||
</beans>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,54 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>stu.example</groupId>
|
||||
<artifactId>05-SpringMVC-Quick-Start</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>05-SpringMVC-Quick-Start</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<junit.version>5.11.0-M2</junit.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>jakarta.servlet</groupId>
|
||||
<artifactId>jakarta.servlet-api</artifactId>
|
||||
<version>6.1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>6.1.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>3.4.0</version>
|
||||
</plugin> </plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -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!";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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/mvc
|
||||
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
|
||||
|
||||
<!--开启包扫描-->
|
||||
<context:component-scan base-package="stu.example.controller"/>
|
||||
<!--开启注解驱动,注册一些必要的Bean到SpringMVC容器里面-->
|
||||
<mvc:annotation-driven>
|
||||
<!-- 处理乱码 -->
|
||||
<mvc:message-converters register-defaults="true">
|
||||
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
|
||||
<constructor-arg value="UTF-8"/>
|
||||
</bean>
|
||||
</mvc:message-converters>
|
||||
</mvc:annotation-driven>
|
||||
<!-- 视图解析器
|
||||
作用:1.捕获后端控制器的返回值="index"
|
||||
2.解析: 在返回值的前后 拼接 ==> "/index.jsp"
|
||||
-->
|
||||
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||
<!-- 前缀 -->
|
||||
<property name="prefix" value="/WEB-INF/jsp/"></property>
|
||||
<!-- 后缀 -->
|
||||
<property name="suffix" value=".jsp"></property>
|
||||
</bean>
|
||||
</beans>
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
|
||||
version="4.0">
|
||||
<servlet>
|
||||
<!-- 配置SpringMVC的前端控制器 所有的请求都要经过这个Servlet-->
|
||||
<servlet-name>springmvc</servlet-name>
|
||||
<servlet-class>org.springframework.web.server.DispatcherServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>classpath:springmvc.xml</param-value>
|
||||
</init-param>
|
||||
<!-- 优先级配置数值越低 优先级越高 Tomcat启动的时候就把springmvc容器初始化-->
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>springmvc</servlet-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
</web-app>
|
|
@ -0,0 +1,12 @@
|
|||
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>JSP - Hello World</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1><%= "Hello World!" %></h1>
|
||||
<br/>
|
||||
<a href="hello-servlet">Hello Servlet</a>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,33 @@
|
|||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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/mvc
|
||||
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
|
||||
|
||||
<!--开启包扫描-->
|
||||
<context:component-scan base-package="stu.example.controller"/>
|
||||
<!--开启注解驱动,注册一些必要的Bean到SpringMVC容器里面-->
|
||||
<mvc:annotation-driven>
|
||||
<!-- 处理乱码 -->
|
||||
<mvc:message-converters register-defaults="true">
|
||||
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
|
||||
<constructor-arg value="UTF-8"/>
|
||||
</bean>
|
||||
</mvc:message-converters>
|
||||
</mvc:annotation-driven>
|
||||
<!-- 视图解析器
|
||||
作用:1.捕获后端控制器的返回值="index"
|
||||
2.解析: 在返回值的前后 拼接 ==> "/index.jsp"
|
||||
-->
|
||||
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||
<!-- 前缀 -->
|
||||
<property name="prefix" value="/WEB-INF/jsp/"></property>
|
||||
<!-- 后缀 -->
|
||||
<property name="suffix" value=".jsp"></property>
|
||||
</bean>
|
||||
</beans>
|
Binary file not shown.
|
@ -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/
|
|
@ -0,0 +1,76 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.3</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>edu.ytf</groupId>
|
||||
<artifactId>06-SpringBoot-Quick-Start</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>06-SpringBoot-Quick-Start</name>
|
||||
<description>06-SpringBoot-Quick-Start</description>
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.graalvm.buildtools</groupId>
|
||||
<artifactId>native-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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<String> hobby){
|
||||
System.out.println(hobby);
|
||||
return "Get 请求, hobby=" + hobby;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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!!!";
|
||||
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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 "通配符请求:*";
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
||||
}
|
||||
}
|
|
@ -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 ;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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 + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -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/**
|
|
@ -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() {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="GENERAL_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="jdk" jdkName="17" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
|
||||
version="4.0">
|
||||
</web-app>
|
|
@ -0,0 +1,12 @@
|
|||
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>JSP - Hello World</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1><%= "Hello World!" %></h1>
|
||||
<br/>
|
||||
<a href="hello-servlet">Hello Servlet</a>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
|
||||
version="4.0">
|
||||
</web-app>
|
Loading…
Reference in New Issue