• springmvc有哪些常用的注解


    1.@Controller

    @Controller 用于标记在一个类上,使用它标记的类就是一个SpringMVC Controller 对象。分发处理器将会扫描使用了该注解的类的方法,并检测该方法是否使用了@RequestMapping 注解。@Controller 只是定义了一个控制器类,而使用@RequestMapping 注解的方法才是真正处理请求的处理器。

    2.@RequsestMapping

    RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上。用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径。

          返回值会通过视图解析器解析为实际的物理视图,对于 InternalResourceViewResolver 视图解析器,会做如下的解析:
     

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/views/"></property>
            <property name="suffix" value=".jsp"></property>
            </bean>
            

    通过 prefix + returnVal + suffix 这样的方式得到实际的物理视图,然后做转发操作;

    RequsestMapping有六个属性‘

    1、 value

        value:指定请求的实际地址;

    2、method;

        method: 指定请求的method类型, GET、POST、PUT、DELETE等

    3、consumes

        consumes: 指定处理请求的提交内容类型(Content-Type),例如application/json, text/html;

    4、produces

        produces:    指定返回的内容类型,仅当request请求头中的(Accept)类型中包含该指定类型才返回;

    5、params

        params: 指定request中必须包含某些参数值是,才让该方法处理。

    6、headers

        headers: 指定request中必须包含某些指定的header值,才能让该方法处理请求。

    3.@ResponseBody

    把Java对象转化为json对象,用于ajax处,返回的不是一个页面而是一个某种格式的数据

    4.valid:标识校验该数据

     5.@PathVariable:接收uri地址传过来的参数

    6.@SessionAttribute(names=("","","",....))

    把转发数据的作用于改为Session

    7.@RequestParam

    @RequestParam用于将请求参数区数据映射到功能处理方法的参数上,用例:

    不加@RequestParam写法参数为非必传,加上参数为必传。参数名和传过来的参数名相同。

    加上@RequestParam可以通过@RequestParam(required = false)设置为非必传。因为required值默认是true,所以默认必传。

    @RequestParam可以通过@RequestParam("userId")或者@RequestParam(value = "userId")指定参数名。

    @RequestParam可以通过@RequestParam(defaultValue = "0")指定参数默认值

    8.@ExceptionAdvice:标识一个异常处理类

     9.@ExceptionHandler:标注一个方法为异常处理的方法

     10.InitBinder:处理时间参数

        @InitBinder
        public void initBinder(ServletRequestDataBinder binder){
            //只要网页中传来的数据格式为yyyy-MM-dd 就会转化为Date类型
            binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),
                    true));
        }
  • 相关阅读:
    040 Android TCP协议的Socket通信
    039 Android SQLite数据库(了解)
    Navicat 连接Sqlite数据库的方法和步骤
    038 Android File文件存储功能
    037 Android SharedPreferences应用实例(记录App的使用次数)
    036 Android SharedPreferences(数据存储,需掌握)
    035 Android 广播(BroadCastReceiver)
    SharePoint2013打印列表项对象
    SharePoint2013所有列表绑定到DropDownList1中
    通过主机标头实现多个SharePoint Web应用程序共用一个端口(
  • 原文地址:https://www.cnblogs.com/sh-0131/p/11470189.html
Copyright © 2020-2023  润新知