• SpringMVC-三


    文件上传

    导入jar包

    commons-fileupload-1.3.1.jar
    commons-io-2.2.jar

    前端提交

     springmvc配置文件中配置

     控制层代码

    拦截器(拦截都是控制层的地址。在过滤器之后,可以共存 filter: )

    1. 创建一个类 实现接口 HandlerInterceptor

    2. 重写接口的中方法

    public class MyInterceptor implements HandlerInterceptor{
    
        @Override
        public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
                throws Exception {
            // TODO Auto-generated method stub
            
        }
    
        @Override
        public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
                throws Exception {
            // TODO Auto-generated method stub
            
        }
    
        @Override
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
            System.out.println("aaaaaaaaaaaaaaaaa");
            HttpSession session=request.getSession();
            Object obj=session.getAttribute("user");
            System.out.println(obj);
            if(obj==null) {
                request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(request, response);
                return false;
            }
            return true;
        }
    
    }

    3. 把创建的类配置到springmvc文件中。

     ##############################

     数据校验

     

     控制层用法

     遇到的错误

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean#0': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/ValidationException

    貌似是jdk版本较新

  • 相关阅读:
    elementui form 相关表单验证
    函数注释备注
    elementui elform 某一值为数组,各项必填验证
    selenium等待的三种方式(详细)
    什么是python
    pytest基础
    pymysql数据库操作
    自动化测试1
    allure生成测试报告
    python读取excel的文件
  • 原文地址:https://www.cnblogs.com/accc111/p/11463052.html
Copyright © 2020-2023  润新知