修改依赖

master
TangZhaoZhen 2023-10-29 22:17:00 +08:00
parent b9f04fbf2a
commit fa8a3bf44b
7 changed files with 186 additions and 51 deletions

View File

@ -1,5 +1,68 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="AliAccessStaticViaInstance" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliArrayNamingShouldHaveBracket" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliControlFlowStatementWithoutBraces" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliDeprecation" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliEqualsAvoidNull" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliLongLiteralsEndingWithLowercaseL" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliMissingOverrideAnnotation" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AliWrapperTypeEquality" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaAbstractClassShouldStartWithAbstractNaming" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaAbstractMethodOrInterfaceMethodMustUseJavadoc" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaAvoidApacheBeanUtilsCopy" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaAvoidCallStaticSimpleDateFormat" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaAvoidCommentBehindStatement" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaAvoidComplexCondition" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaAvoidConcurrentCompetitionRandom" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaAvoidDoubleOrFloatEqualCompare" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaAvoidManuallyCreateThread" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaAvoidMissUseOfMathRandom" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaAvoidNegationOperator" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaAvoidNewDateGetTime" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaAvoidPatternCompileInMethod" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaAvoidReturnInFinally" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaAvoidStartWithDollarAndUnderLineNaming" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaAvoidUseTimer" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaBigDecimalAvoidDoubleConstructor" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaBooleanPropertyShouldNotStartWithIs" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaClassCastExceptionWithSubListToArrayList" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaClassCastExceptionWithToArray" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaClassMustHaveAuthor" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaClassNamingShouldBeCamel" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaCollectionInitShouldAssignCapacity" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaCommentsMustBeJavadocFormat" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaConcurrentExceptionWithModifyOriginSubList" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaConstantFieldShouldBeUpperCase" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaCountDownShouldInFinally" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaDontModifyInForeachCircle" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaEnumConstantsMustHaveComment" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaExceptionClassShouldEndWithException" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaIbatisMethodQueryForList" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaLockShouldWithTryFinally" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaLowerCamelCaseVariableNaming" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaMethodReturnWrapperType" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaMethodTooLong" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaPackageNaming" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaPojoMustOverrideToString" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaPojoMustUsePrimitiveField" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaPojoNoDefaultValue" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaRemoveCommentedCode" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaServiceOrDaoClassShouldEndWithImpl" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaSneakyThrowsWithoutExceptionType" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaStringConcat" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaSwitchExpression" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaSwitchStatement" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaTestClassShouldEndWithTestNaming" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaThreadLocalShouldRemove" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaThreadPoolCreation" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaThreadShouldSetName" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaTransactionMustHaveRollback" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaUndefineMagicConstant" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaUnsupportedExceptionWithModifyAsList" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaUseQuietReferenceNotation" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="AlibabaUseRightCaseForDateFormat" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="MapOrSetKeyShouldOverrideHashCodeEquals" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>

View File

@ -9,7 +9,15 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="f69f77d9-aff7-425d-bc6a-9c642bd4ab89" name="更改" comment="" />
<list default="true" id="f69f77d9-aff7-425d-bc6a-9c642bd4ab89" name="更改" comment="">
<change beforePath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/tzz/mvc/annaotation/EnjoyRequestParam.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/tzz/mvc/annaotation/EnjoyRequestParam.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/tzz/mvc/service/impl/DispatcherServlet.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/tzz/mvc/service/impl/JvmServiceIml.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/tzz/mvc/service/impl/JvmServiceIml.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/webapp/WEB-INF/web.xml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/webapp/WEB-INF/web.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -45,24 +53,28 @@
<option name="showMembers" value="true" />
<option name="showScratchesAndConsoles" value="false" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"WebServerToolWindowFactoryState": "false",
"last_opened_file_path": "D:/idea/thread-lock",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"project.structure.last.edited": "模块",
"project.structure.proportion": "0.0",
"project.structure.side.proportion": "0.0",
"vue.rearranger.settings.migration": "true"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
&quot;last_opened_file_path&quot;: &quot;D:/idea/spring-mvc/src/main/java/com/tzz/mvc/bb&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;project.structure.last.edited&quot;: &quot;模块&quot;,
&quot;project.structure.proportion&quot;: &quot;0.15&quot;,
&quot;project.structure.side.proportion&quot;: &quot;0.2&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;MavenSettings&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}]]></component>
}</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="D:\idea\spring-mvc\src\main\java\com\tzz\mvc\bb" />
</key>
<key name="MoveClassesOrPackagesDialog.RECENTS_KEY">
<recent name="" />
<recent name="com.tzz.mvc" />
@ -70,11 +82,11 @@
</component>
<component name="RunManager" selected="Tomcat 服务器.Tomcat 8.5.68">
<configuration name="DispatcherServlet" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.tzz.mvc.service.impl.DispatcherServlet" />
<option name="MAIN_CLASS_NAME" value="com.tzz.mvc.aa.servlet.DispatcherServlet" />
<module name="spring-mvc" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.tzz.mvc.service.impl.*" />
<option name="PATTERN" value="com.tzz.mvc.aa.servlet.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
@ -154,6 +166,10 @@
</option>
</method>
</configuration>
<list>
<item itemvalue="Tomcat 服务器.Tomcat 8.5.68" />
<item itemvalue="应用程序.DispatcherServlet" />
</list>
<recent_temporary>
<list>
<item itemvalue="应用程序.DispatcherServlet" />
@ -177,11 +193,27 @@
<workItem from="1698543065776" duration="65000" />
<workItem from="1698545821231" duration="7977000" />
<workItem from="1698567341576" duration="5048000" />
<workItem from="1698578123721" duration="1033000" />
<workItem from="1698578123721" duration="5035000" />
<workItem from="1698583592166" duration="183000" />
<workItem from="1698583850655" duration="47000" />
<workItem from="1698588486669" duration="508000" />
</task>
<task id="LOCAL-00001" summary="初始化">
<created>1698579199143</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1698579199143</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="VcsManagerConfiguration">
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
<MESSAGE value="初始化" />
<option name="LAST_COMMIT_MESSAGE" value="初始化" />
</component>
</project>

46
pom.xml
View File

@ -20,8 +20,54 @@
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
</dependencies>
<build>
<finalName>spring-mvc</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.0</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.4.0</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.1</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -9,7 +9,7 @@ import java.lang.annotation.*;
@Target({ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface EnjoyRequestParam {
public @interface EnjoyRequestParam {
String value() default "";
}

View File

@ -14,6 +14,6 @@ public class JvmServiceIml implements JvmService {
@Override
public String query(String name, String age) {
return "name==="+name+"age==="+age;
return "name==="+name + ";"+"age==="+age;
}
}

View File

@ -1,4 +1,5 @@
package com.tzz.mvc.service.impl;
package com.tzz.mvc.servlet;
import com.tzz.mvc.annaotation.*;
import com.tzz.mvc.controller.JvmController;
@ -27,14 +28,13 @@ import java.util.*;
public class DispatcherServlet extends HttpServlet {
public static List<String> classNames = new ArrayList<String>();
public static Map<String, Object> beans = new HashMap<String,Object>();
List<String> classNames = new ArrayList<String>();
Map<String, Object> beans = new HashMap<String,Object>();
public static Map<String, Object> handerMap = new HashMap<String,Object>();
Map<String, Object> handerMap = new HashMap<String,Object>();
@Override
public void init(ServletConfig config) {
public void init(ServletConfig config) throws ServletException {
//把所有的bean扫描---扫描所有的class文件
scanPackage("com.tzz");
//根据全类名创建bean
@ -73,7 +73,7 @@ public class DispatcherServlet extends HttpServlet {
for (String className : classNames) {
String cn = className.replace(".class","");
try {
Class<?> clazz = Class.forName(cn);//com.tzz.mvc.com.tzz.mvc.service.controller...
Class<?> clazz = Class.forName(cn);//com.tzz.mvc.com.tzz.mvc.aa.service.controller...
if (clazz.isAnnotationPresent(EnjoyController.class)) {
Object instace = clazz.newInstance(); //创建控制类
EnjoyRequestMapping requestMapping = clazz.getAnnotation(EnjoyRequestMapping.class);
@ -131,6 +131,7 @@ public class DispatcherServlet extends HttpServlet {
}
}
private void buildUrlMapping() {
@ -170,60 +171,54 @@ public class DispatcherServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//获取请求路径 spring-mvc/mvc/query
// 获取请求路径
String uri = req.getRequestURI();
System.out.println("路径URl为"+uri);
// String context = req.getContextPath(); //spring-mvc
// String path = uri.replaceAll(context, ""); //mvc/query
String result = uri.substring( 11);
Method method = (Method) handerMap.get(result);
String context = req.getContextPath();
String path = uri.replace(context, "");
Method method = (Method) handerMap.get(path);
int index = result.indexOf("/"); // 获取第一个斜杠的索引
String mvc = result.substring(index, result.indexOf("/", index + 1)); // 获取/mvc字符串
JvmController instance = (JvmController) beans.get("/"+path.split("/")[1]);
//根据 key=/mvc 到map去拿
JvmController instance = (JvmController) beans.get(mvc); //
//
Object[] hand = hand(req, resp, method);
Object[] args = hand(req, resp, method);
try {
method.invoke(instance, hand);
method.invoke(instance, args);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
e.printStackTrace();
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
e.printStackTrace();
}
}
private static Object[] hand(HttpServletRequest request, HttpServletResponse response, Method method) {
//拿到待执行的方法有哪些参数
Class<?>[] paramClazzs = method.getParameterTypes();
//根据参数的个数new 一个参数的数组将方法的所有参数赋值到args
Object[] args = new Object[paramClazzs.length];
int args_i = 0;
int index = 0;
for (Class<?> paramClazz : paramClazzs) {
if (ServletRequest.class.isAssignableFrom(paramClazz)) {
args[args_i++] = request;
}
if (ServletResponse.class.isAssignableFrom(paramClazz)) {
args[args_i++] = request;
args[args_i++] = response;
}
Annotation[] paramAns = method.getParameterAnnotations()[index];
if (paramAns.length > 0) {
for (Annotation paramAn : paramAns) {
if (EnjoyRequestParam.class.isAssignableFrom(paramAn.getClass())) {
EnjoyRequestParam rp = (EnjoyRequestParam) paramAn;
args[args_i++] = request.getParameter(rp.value());
}
}
}
index++;
}
return args;
}

View File

@ -5,11 +5,10 @@
<web-app>
<display-name>spring-mvc</display-name>
<!-- SpringMvc的核心控制器 -->
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>com.tzz.mvc.service.impl.DispatcherServlet</servlet-class>
<!-- 代表初始化的是否执行 IOC -->
<load-on-startup>0</load-on-startup>
<servlet-class>com.tzz.mvc.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>