1.@ResponseBody的区别
@RequestMapping(value = "/index")
@ResponseBody
public String helloworld(String json) {
String result = null;
return "index";
}
- 1
- 2
- 3
- 4
- 5
- 6
浏览器输入:http://localhost:8080/SpringTest/user/index
返回结果: index (字符串)
@RequestMapping(value = "/index")
public String helloworld(String json) {
String result = null;
return "index";
}
- 1
- 2
- 3
- 4
- 5
浏览器输入:http://localhost:8080/SpringTest/user/index
返回结果: index.jsp界面的内容
2.spring xml头文件xmlns和xsi的意思
<?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-2.0.xsd">
... ...
</beans>
说明如下:
beans —— xml文件的根节点
xmlns ——是XML NameSpace的缩写,因为XML文件的标签名称都是自定义的,自己写的和其他人定义的标签很有可能会重复命名,而功能却不一样,所以需要加上一个namespace来区分这个xml文件和其他的xml文件,类似于java中的package。
xmlns:xsi ——是指xml文件遵守xml规范,xsi全名:xml schema instance,是指具体用到的schema资源文件里定义的元素所准守的规范。即/spring-beans-2.0.xsd这个文件里定义的元素遵守什么标准
xsi:schemaLocation——是指,本文档里的xml元素所遵守的规范
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
即是说:我如果一个spring.xml需要用到标签 < mvc >,那么我需要先引入命名空间:
xmlns:mvc=”http://www.springframework.org/schema/mvc”
而后我需要规定遵循的规范:
xsi:schemaLocation=”
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd”
也就是两个都给上.