spring框架学习过程的小知识

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” 
也就是两个都给上.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值