long stime=System.currentTimeMillis();
for(int i=0;i<500000;i++)
{
String s1="Hello";
String s2="Hello";
}
long etime=System.currentTimeMillis();
System.out.println("Time diff"+(etime-stime));
long stime1=System.currentTimeMillis();
for(int i=0;i<500000;i++)
{
String s3=new String("Hello");
String s4=new String("Hello");
}
long etime1=System.currentTimeMillis();
System.out.println("Time diff"+(etime1-stime1));
Run Code Online (Sandbox Code Playgroud)
实际上我在这两种情况下得到的答案都是0.在这两种情况下为什么为零
似乎dispatcher-servlet无法使用执行组件扫描.
<context:component-scan base-package="abc" />
Run Code Online (Sandbox Code Playgroud)
在我的控制器文件(HelloController.java)下包abc.代码编写如下:
@Controller
@RequestMapping("/hello")
public class HelloController {
@RequestMapping(method = RequestMethod.GET)
public String printHello(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!");
return "hello"; //I have already made hello.jsp in web-inf/jsp/
}
}
Run Code Online (Sandbox Code Playgroud)
我的应用程序名称是SpringMiddle.当尝试url为:
http://localhost:8080/SpringMiddle/hello.htm
Run Code Online (Sandbox Code Playgroud)
我在web.xml中有以下url模式
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
它显示我找不到HTTP 404错误.
编辑::它告诉我警告
WARNING: No mapping found for HTTP request with URI [/SpringMiddle/hello.htm] in DispatcherServlet with name 'dispatcher'
Run Code Online (Sandbox Code Playgroud)