zoukankan      html  css  js  c++  java
  • 知识点

    1、数据类型转换,String 转基本类型 Imteger.ValueOf(int i ).intValue()   基本类型转String  String a= int i +"";   Integer.ValueOf(int  i).toString()  String.valueOf(int i);

    2、日期类型的转换

      数据库:to_char   to_date

      hibernate xml配置  @Temporal(TemporalType.TIME)

      java端  simpleDateFormate

      jsp端 <fmt:formatDate value="${list[0].createTime}" pattern="yyyy-MM-dd HH:mm:ss">

      SpringMvc  表单数据绑定 @initBinder    binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), true)); 

    3、数据类型转换

      JSONObject.fromObject() 使用这个方法 需要 json-lib.jar、ezmorph-1.0.6.jarcommons-lang 2.4 、commons-beanutils 1.7.0 、commons-collections 3.2 、commons-logging 1.1.1  需要这些包

      转给前台的话两种方式一种是 response.getWriter    另一种是@responseBody 直接将object转成json  返回给前台,但是得在spring-mvc.xml 中配置

     

      Arrays.asList(str),数组——list

      list.toArray() list——数组

      Arrays.toString(array)  数组——字符串
      ArrayUtils.reverse(intArray); 数组逆向排列

       ArrayUtils.removeElement(array, “str”);   删除数据元素

      Collections.sort(list); // 顺序排列

      Collections.shuffle(list); // 混乱的意思

      Collections.reverse(list); // 倒序排列

     4‘、流

      基本的inputStream outputSream 字节流    Reader Writer 字符流

      处理流用 bufferedReader 缓存流 ,可以读一行数据, 

      new FileOutputStream(fileName,true)  增量存放数据

      也可以利用 byte buf=new byte【1024】 这种方式作为缓存流,效率会更高一些

      ObjectInputStream 序列化运用的流  所读写的对象必须实现Serializable接口

      ObjectOutputStream out=new ObjectOutputStream(fileOutputSream);

      out.writeObject(object)  写入对象   Object object=in.readObject();读取对象

      若要写入文件内容,必须关闭流才可以

    5、文件上传

      MultipartHttpServletRequest multiPart=(MultipartHttpServletRequest) request;
            MultipartFile multiPartFile=multiPart.getFile("file");
            String fileName=multiPartFile.getOriginalFilename();
            InputStream input=multiPartFile.getInputStream();
            serverPath=request.getServletContext().getRealPath("/");
            FileOutputStream out=new FileOutputStream(new File(serverPath+fileName));

      使用multipartHttpServletRequest  必须配置

      <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
            <property name="maxUploadSize">
                <value>102400000000</value>
            </property>
            <property name="defaultEncoding">
                <value>UTF-8</value>
            </property>
          </bean>

      也可以用  @RequestParam(name = "file") CommonsMultipartFile file来获得文件 但是没有 MultipartHttpServletRequest效率高

      详见 http://blog.csdn.net/itmyhome1990/article/details/27977329

      利用formData也可以上传文件

      @WebServlet("/Upload")
    @MultipartConfig
    public class Upload extends HttpServlet {
        private static final long serialVersionUID = 1L;
           
        public void service(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException{
            String serverPath=request.getServletContext().getRealPath("/");
            Collection<Part> files=request.getParts();
            String jim=request.getParameter("jim");
            for(Part file:files){
                file.write(serverPath+"/"+file.getName());
            }
        }
    }

    页面为

      function  test(){
                var formData = new FormData();
                formData.append('file', $('#file')[0].files[0]);
                formData.append('jim','789');
                $.ajax({
                    url: 'Upload',
                    type: 'POST',
                    cache: false,
                    data: formData,
                    contentType:'multipart/form-data',
                    processData: false,
                    contentType: false
                });           
            }

    6、文件下载

      public static void fileDownload(final HttpServletResponse response,HttpServletRequest request, String filePath, String fileName) throws Exception{  
                byte[] data = FileUtilReplenish.toByteArray2(filePath);  
                //fileName = URLEncoder.encode(fileName, "UTF-8");  
                if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) {  
                    fileName = URLEncoder.encode(fileName, "UTF-8");  
                } else {  
                    fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");  
                }  
                response.reset();  
                response.setHeader("Content-Disposition", "attachment; filename=" + fileName +".xls"+ "");  
                response.addHeader("Content-Length", "" + data.length);  
                response.setContentType("application/msexcel;charset=UTF-8");  
                OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());  
                outputStream.write(data);  
                outputStream.flush();  
                outputStream.close();
                response.flushBuffer();
            }   

    7、拦截器

      springmvc.xml中配置<mvc:interceptors>   类继承HandlerInterceptorAdapter 在preHandle来实现权限的验证,返回return false则后面的拦截器不在做验证,若为true继续验证,

      有request参数,可以通过url来进行拦截,有response,可以进行重定向,有handle参数,可以进行反射获得方法上的注解,来判断是否具有相应的权限

      afterCompletion可以利用handle通过注解来识别出来当前方法上主键的值,然后将相关的信息插入到loger表中,也可以在单独做一个模块,来查看每个用户具体的操作明细

    8、注解

      @interface 注解名 ,通过NoAuth noAuth=method.getMethodAnnotation(NotAuth.class)获得注解的对象 noAuth.属性获得注解时输入的值

  • 相关阅读:
    tkinter中entry输入控件(四)
    tkinter中button按钮控件(三)
    tkinter中lable标签控件(二)
    tkinter简介(一)
    selenium中的xpath定位
    python实现邮件的发送
    python发送手机动态验证码
    selenium提供的截图功能
    selenium中浏览器及对应的驱动(可下载)
    PHP实现微信提现功能
  • 原文地址:https://www.cnblogs.com/happy0120/p/7371538.html
Copyright © 2011-2022 走看看