ORA-01658: unable to create INITIAL extent for segment in tablespace string用Navicat操作oracle建表时候发生如上错误,百度搜了下也有类似解决方法,例如:https://blog.csdn.net/j080624/article/details/78731412但是我操作的oracle有自己的表空间,应该不能给现有表空间扩容,于是,我了解到数据表应该存在其中某个表空间。立马操作:Navicat打开刚刚建好的表,右键点“设计”,然后在tab上点“选项”,然后切换到自己需要的表空间即可,实体属性如果不知道切勿修改,乱改的话可能会保存不了。如何避免这种错误?在建表时就对表空间进行指定,其中NAMES指代指定的表空间,按实际情况修改,以下参数也是根据实际情况改:tablespace NAMES pctfree 10 initrans 1 maxtrans 255 storage ( initial 64K next 8K minextents 1 maxextents unlimited )
我们在用idea写ssm的mapper文件的时候,经常会发现有一大块黄色区域标记的字符,并且使用idea自带的格式化功能sql语句也不能正确得格式化,使得mapper文件看起来杂乱无章。那么怎么能让sql能正确格式化呢?1、第一种方式,光标放在xml文件中一行sql中,按alt+enter,弹出的对话框选择第一个选项,然后在里面选择合适的SQL类型,例如oracle或mysql2、第二种,如果设置错了方言造成没有第一种的选项:同样打开某个mapper.xml文件,再打开Setting设置,搜索SQL Dialect,然后将SQL语言改成合适的版本即可然后你再用idea快捷键格式化就会发现SQL按照标准格式化好了3、第三种,同第二种一样,可以双机shift,然后在搜索框输入“sql dia”搜索相关功能打开也可以拓展:SQL Dialect中Dialect即方言的意思,上面操作意图很明了,更改SQL的方言。
https://acg.toubiec.cn/random.phphttp://img.xjh.me/random_img.php?type=bg&ctype=nature&return=302(自然)http://img.xjh.me/random_img.php?tctype=acg&return=302 (竖屏)http://img.xjh.me/random_img.php?type=bg&ctype=acg&return=302https://uploadbeta.com/api/pictures/random/http://api.mtyqx.cn/tapi/random.phphttp://api.mtyqx.cn/api/random.phphttps://random.52ecy.cn/randbg.phphttps://api.ixiaowai.cn/api/api.phphttps://api.ixiaowai.cn/mcapi/mcapi.php一言Api:https://api.ixiaowai.cn/api/ylapi.php
SpringMVC拦截器SpringMVC框架中的拦截器用于对处理器进行预处理和后处理的技术。可以定义拦截器链,连接器链就是将拦截器按着一定的顺序结成一条链,在访问被拦截的方法时,拦截器链中的拦截器会按着定义的顺序执行。拦截器和过滤器的功能比较类似,有区别1. 过滤器是Servlet规范的一部分,任何框架都可以使用过滤器技术。 2. 拦截器是SpringMVC框架独有的,因此只对控制器方法产生作用。 3. 过滤器配置了/*,可以拦截任何资源,因此静态资源需要在配置中排除。springmvc.xml配置静态资源过滤<!-- location 表示路径,mapping 表示文件,**表示该目录下的文件以及子目录的文件 --><mvc:resources location="/css/" mapping="/css/**"/><mvc:resources location="/images/" mapping="/images/**"/><mvc:resources location="/scripts/" mapping="/javascript/**"/>拦截器只会对控制器中的方法进行拦截。拦截器也是AOP思想的一种实现方式想要自定义拦截器,需要实现HandlerInterceptor接口,然后根据需要重写里面方法。简而言之拦截器就是对控制层执行前后进行处理的工具,之前学过的@ModelAttribute注解也可以对Controller参数进行预处理,只是@ModelAttribute只是将处理好参数返给控制器了。拦截器明显可以做更多事,例如看请求中是否包含某信息,不包含则跳转到错误页面,包含则正常执行控制层。自定义拦截器步骤创建类,实现HandlerInterceptor接口,idea按ctrl+o重写需要方法,返回true放行,反之拦截。可以做登录前的验证,未登录预处理重定向或转发跳转到登录页面。public class MyInterceptor1 implements HandlerInterceptor { /** * controller方法执行前,进行拦截的方法 * return true放行 * return false拦截 * 可以使用转发或者重定向直接跳转到指定的页面。 */ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { System.out.println("拦截器执行了..."); return true; }}配置springmvc.xml,以下配置了两拦截器,执行顺序,12->Controller->21->JSP->21<!-- 配置拦截器 --><mvc:interceptors> <mvc:interceptor> <!-- 哪些方法进行拦截 --> <mvc:mapping path="/user/*"/> <!-- 哪些方法不进行拦截 <mvc:exclude-mapping path=""/> --> <!-- 注册拦截器对象 --> <bean class="cn.cheng.demo1.MyInterceptor1"/> </mvc:interceptor> <mvc:interceptor> <!-- 哪些方法进行拦截 --> <mvc:mapping path="/**"/> <!-- 哪些方法不进行拦截 <mvc:exclude-mapping path=""/> --> <!-- 注册拦截器对象 --> <bean class="cn.cheng.demo1.MyInterceptor2"/> </mvc:interceptor></mvc:interceptors>preHandle方法是controller方法执行前拦截的方法可以使用request或者response跳转到指定的页面return true放行,执行下一个拦截器,如果没有拦截器,执行controller中的方法。return false不放行,不会执行controller中的方法。postHandle是controller方法执行后执行的方法,在JSP视图执行前。可以使用request或者response跳转到指定的页面如果指定了跳转的页面,那么controller方法跳转的页面将不会显示。afterHandle方法是在JSP执行后执行request或者response不能再跳转页面了
异常处理系统的 dao、service、controller 出现都通过 throws Exception 向上抛出,最后由 springmvc 前端控制器交由异常处理器进行异常处理。编写异常类public class CustomException extends Exception { private String message; public CustomException(String message) { this.message = message; } public String getMessage() { return message; }}自定义异常处理器设置如果是指定错误跳转到指定错误页面,并返回相应错误信息public class CustomExceptionResolver implements HandlerExceptionResolver { @Override public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { ex.printStackTrace(); CustomException customException = null;//如果抛出的是系统自定义异常则直接转换 if (ex instanceof CustomException) { customException = (CustomException) ex; } else {//如果抛出的不是系统自定义异常则重新构造一个系统错误异常。 customException = new CustomException("系统错误,请与系统管理 员联系!"); } ModelAndView modelAndView = new ModelAndView(); //存入错误信息 modelAndView.addObject("message", customException.getMessage()); //跳转错误页面 modelAndView.setViewName("error"); return modelAndView; }}配置异常处理器<!-- 配置异常处理器 --><bean id="sysExceptionResolver" class="com.cheng.exception.CustomExceptionResolver"/>异常处理在控制层使用在控制层的try...catch中throw new CustomException("系统错误")即可
响应数据与视图返回字符串Controller方法返回字符串可以指定逻辑视图的名称,根据视图解析器为物理视图的地址。 @RequestMapping(value="/hello") public String sayHello() { // 跳转到success页面 return "success"; }返回void1、默认会跳转到同mapping同名的页面,如@RequestMapping(value="/hello") 默认跳转到hello页面,不存在报4042、已知道Servlet 原始 API 可以作为控制器中方法的参数,可使用其做转发或重定向 @RequestMapping(value = "/initAdd") public void initAdd(HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("请求转发或者重定向");// 请求转发 转发网址栏地址不变 页面变// request.getRequestDispatcher("/WEB-INF/pages/add.jsp").forward(request,response);// 重定向 跳转网址会产生变化// response.sendRedirect(request.getContextPath()+"/add2.jsp"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8");// 用getWriter()直接响应数据 response.getWriter().print("你好"); return; }3、使用SpringMVC关键字进行转发与重定向如下重定向与转发不仅仅可以跳页面也能跳到其他Controller的mapping//"forward:转发的JSP路径",不走视图解析器了,所以需要编写完整的路径//转发 @RequestMapping("/delete") public String delete() throws Exception {// return "forward:/WEB-INF/pages/success.jsp"; return "forward:/user/findAll"; }//重定向 到本机不需要完整路径 @RequestMapping("/count") public String count() throws Exception { return "redirect:/add.jsp";// return "redirect:/user/findAll"; }Model与ModelAndViewModelModel作为参数可调用其addAttribute方法添加数据到request域,如下: @RequestMapping(value = "/initUpdate") public String initUpdate(Model model) {// 模拟从数据库中查询的数据 User user = new User(); user.setUsername("张三"); model.addAttribute("user", user); return "update"; }在jsp页面可通过${ requestScope }或${ user.username }调用request中内容。ModelAndViewModelAndView对象是Spring提供的一个对象,可以用来调整具体的JSP视图。它可以同时传入跳转页面名与数据对象,与上方Model功能差不多。只是Model将数据存在Model中,返回String页面名称,一般作为参数,但ModelAndView是作为返回值的。 /** * 返回ModelAndView对象 * 可以传入视图的名称(即跳转的页面),还可以传入对象。 * * @return * @throws Exception */ @RequestMapping(value = "/findAll") public ModelAndView findAll() throws Exception { ModelAndView mv = new ModelAndView();// 跳转到list.jsp的页面 mv.setViewName("list");// 模拟从数据库中查询所有的用户信息 List<User> users = new ArrayList<>(); User user1 = new User(); user1.setUsername("张三"); user1.setPassword("123"); User user2 = new User(); user2.setUsername("赵四"); user2.setPassword("456"); users.add(user1); users.add(user2);// 添加对象 mv.addObject("users", users); return mv; }JSP页面开启c标签调用<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>获取集合中值通过forEach遍历<c:forEach items="${ users }" var="user">${ user.username }</c:forEach>ResponseBody返回json@ResponseBody注解写在方法上或者方法返回的类型前,或者写在类上或者使用@RestCotroller注解public @ResponseBody Address testJson(@RequestBody String body) {}RequestBody转对象上述代码如果@RequestBody注解修饰的String变量封装成JavaBean对象public @ResponseBody Address testJson(@RequestBody Address address) {}使用jackson添加jar包即可,Springmvc 默认用 MappingJacksonHttpMessageConverter 对 json 数据进行转换<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.9.0</version></dependency><dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.9.0</version></dependency><dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.9.0</version></dependency>
太平洋电脑:https://whois.pconline.com.cn/ipJson.jsp?ip=127.0.0.1淘宝:http://ip.taobao.com/service/getIpInfo.php?ip=127.0.0.1淘宝的对请求间隔时间有要求短时间请求可能会报错。
地址:http://hik.win目前仅支持百度贴吧自动签到。使用方法: 点击页面添加任务按钮添加任务,输入你的QQ作为今后查询修改任务的条件,任务名可自定义,bduss获取方式如下方说明。 提交后系统会在每天特定时间执行签到,你可以通过输入QQ查询你名下的任务,状态有“有效”跟“无效”,如果是“无效”就说明你要重新更新bduss了,可以点击修改键入新的bduss提交给服务器。bduss获取方法:登录百度账号,可以是百度的任意产品,例如百度搜索、贴吧、知道等bduss都一样,登录成功浏览器后按F12,点上头Application再点Cookie,点击Cookie下的百度域名,找到BDUSS字段双击右边长字符串,Ctrl+C复制即可。以下图片是用Chrome浏览器,其他浏览器也可以大同小异。
SpringMVC简介 SpringMVC 是一种基于 Java 的实现 MVC 设计模型的请求驱动类型的轻量级 Web 框架,属于 SpringFrameWork 的后续产品,已经融合在 Spring Web Flow 里面。SpringMVC优势:1、清晰的角色划分:前端控制器(DispatcherServlet)请求到处理器映射(HandlerMapping)处理器适配器(HandlerAdapter)视图解析器(ViewResolver)处理器或页面控制器(Controller)验证器( Validator)命令对象(Command 请求参数绑定到的对象就叫命令对象)表单对象(Form Object 提供给表单展示和提交到的对象就叫表单对象)。2、分工明确,而且扩展点相当灵活,可以很容易扩展,虽然几乎不需要。3、由于命令对象就是一个 POJO,无需继承框架特定 API,可以使用命令对象直接作为业务对象。4、和 Spring 其他框架无缝集成,是其它 Web 框架所不具备的。5、可适配,通过 HandlerAdapter 可以支持任意的类作为处理器。6、可定制性,HandlerMapping、ViewResolver 等能够非常简单的定制。7、功能强大的数据验证、格式化、绑定机制。8、利用 Spring 提供的 Mock 对象能够非常简单的进行 Web 层单元测试。9、本地化、主题的解析的支持,使我们更容易进行国际化和主题的切换。10、强大的 JSP 标签库,使 JSP 编写更容易。………………还有比如RESTful风格的支持、简单的文件上传、约定大于配置的契约式编程支持、基于注解的零配置支持等等。SpringMVC配置坐标依赖 <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <spring.version>5.0.2.RELEASE</spring.version> </properties> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> </dependencies>web.xml<web-app> <display-name>Archetype Created Web Application</display-name> <!-- 配置前端控制器servlet跟mapping--> <servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 配置Servlet的初始化参数,读取springmvc的配置文件,创建spring容器 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc.xml</param-value> </init-param> <!-- 配置servlet启动时加载对象 而不是请求时候才加载 --> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcherServlet</servlet-name> <!-- /表示所有请求都经过它--> <url-pattern>/</url-pattern> </servlet-mapping>springmvc.xml配置文件该xml文件名称可自定义,需要在web.xml中指定,详见上方web.xml配置<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd"> <!-- 配置所需要的名称空间后 配置注解扫描--> <context:component-scan base-package="com.cheng"></context:component-scan> <!-- 配置视图解析器 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!-- 配置视图解析器解析的前缀目录--> <property name="prefix" value="/WEB-INF/pages/"></property> <!-- 配置解析的后缀 下列也就是只解析到jsp文件--> <property name="suffix" value=".jsp"></property> </bean> <!-- 配置spring开启注解mvc的支持 该注解包含SpringMVC中的其他处理器--> <mvc:annotation-driven></mvc:annotation-driven></beans><mvc:annotation-driven />解析用 自动加载 RequestMappingHandlerMapping(处理映射器)和RequestMappingHandlerAdapter ( 处理适配器 ),如果不使用这种写法,可以使用下列配置,下载配置其实就是细化,可让你根据适合场景使用适合的处理器,而非全部加载。 <!-- Begin --> <!-- HandlerMapping --> <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"></bean> <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"></bean> <!-- HandlerAdapter --> <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"></bean> <bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter"></bean> <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"></bean> <!-- HadnlerExceptionResolvers --> <bean class="org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver"></bean> <bean class="org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver"></bean> <bean class="org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver"></bean> <!-- End -->小流程启动Tomcat->加载web.xml->由于配置load-on-startup启动即创建前端控制器->加载springmvc.xml->开启注解扫描->扫描@Controller注解的类创建对象前端jsp页面发请求->到前端控制器->根据@RequestMapping找具体方法执行->根据方法返回结果->根据视图解析器->查找指定的页面->Tomcat渲染页面->响应给页面常用注解@RequestMapping作用:建立请求URL与方法之间对应关系。写法:可以写在类与方法上,value值为 / 表示根目录属性:path/value 指定请求路径的url例:@RequestMapping(path ="/hello")、@RequestMapping(value="/hello")其中如果只有value一个属性的话可以省略不写,即@RequestMapping("/hello")mthod 指定该方法的请求方式@RequestMapping(value="/saveAccount",method=RequestMethod.POST)可以配置多种方式,在{}中写params 指定限制请求参数的条件RequestMapping(value="/remove",params= {"accountName","money>100"})//限制传来参数中必须有accountName、money参数,money还需要>100headers 发送的请求中必须包含的请求头RequestMapping(value="/remove",header= {"Accept"})//限制header中必须有Accept在jsp中可以采用绝对与相对URL访问mapping<a href="${pageContext.request.contextPath}/account/findAccount">绝对</a><a href="account/findAccount">相对</a>${pageContext.request.contextPath}取的是虚拟目录的名称@RequestParam与前台传递参数不一致,用它进行与形参关联,例如下列前台传的参数username,但后台必须用name时public String sayHello(@RequestParam(value="username",required=false)String name) {}@RequestBody用于获取请求体的内容(注意:get方法不适用,适用于post或ajax异步请求)required:是否必须有请求体,默认值是truepublic String sayHello(@RequestBody String body) {}@PathVariable拥有绑定url中的占位符的。例如:url中有/delete/{id},{id}就是占位符<a href="user/hello/1">入门案例</a>/*** 接收请求* @return*/@RequestMapping(path="/hello/{id}")public String sayHello(@PathVariable(value="id") String id) { System.out.println(id); return "success";}Restful风格的URL请求路径一样,可以根据不同的请求方式去执行后台的不同方法restful风格的URL优点结构清晰符合标准易于理解扩展方便@RequestHeader获取指定请求头的值public String sayHello(@RequestHeader(value="Accept") String header) {}@CookieValue获取指定cookie的名称的值@RequestMapping(path="/hello")public String sayHello(@CookieValue(value="JSESSIONID") String cookieValue) { System.out.println(cookieValue); return "success";}@ModelAttribute出现在方法上:表示当前方法会在控制器方法执行前线执行。出现在参数上:获取指定的数据给参数赋值。应用场景:当提交表单数据不是完整的实体数据时,保证没有提交的字段使用数据库原来的数据。 /** *假设User对象中有name跟password字段,前端只传了name * 要知道password 第一种在该Controller中写读数据库操作 * 第二种在@ModelAttribute修饰的方法中写数据库操作 因为它优先执行 */ @RequestMapping(path = "/updateUser") public String updateUser(User user) { System.out.println(user); return "success"; } /** * 作用在方法,先执行 * 通过前端传的name查询password并返回给user */ @ModelAttribute public User showUser(String name) { System.out.println("showUser执行了...");// 模拟从数据库中查询对象,此处为演示直接设置对象属性 User user = new User(); user.setName("哈哈"); user.setPassword("123"); return user; }假设@ModelAttribute修饰的先行方法没返回值怎么办?可在方法参数中加合适类型Map,然后将数据库查询的对象put进去,在需要的Controller方法的参数上再加@ModelAttribute注解把值再赋给user @RequestMapping(path = "/updateUser") public String updateUser(@ModelAttribute(value = "abc") User user) { System.out.println(user); return "success"; } @ModelAttribute public void showUser(String name, Map<String, User> map) { System.out.println("showUser执行了...");// 模拟从数据库中查询对象 User user = new User(); user.setName("哈哈"); user.setPassword("123"); map.put("abc", user); }@SessionAttributes用于多次执行控制器方法间的参数共享。只能写在类上。@Controller@RequestMapping(path = "/user")@SessionAttributes(value = {"username", "password", "age"}, types = {String.class, Integer.class}) // 把数据存入到session域对象中public class HelloController { /** * 向session中存入值 * * @return */ @RequestMapping(path = "/save") public String save(Model model) { System.out.println("向session域中保存数据");// 会向Request域中添加数据// 加SessionAttributes注解会再次向Session域中 model.addAttribute("username", "root"); model.addAttribute("password", "123"); model.addAttribute("age", 20); return "success"; } /** * 从session中获取值 * * @return */ @RequestMapping(path = "/find") public String find(ModelMap modelMap) {// ModelMap是Model的实现类,可以取数据 String username = (String) modelMap.get("username"); String password = (String) modelMap.get("password"); Integer age = (Integer) modelMap.get("age"); System.out.println(username + " : " + password + " : " + age); return "success"; } /** * 清除值 * * @return */ @RequestMapping(path = "/delete") public String delete(SessionStatus status) {// 将session状态设置为完成则清除session status.setComplete(); return "success"; }}参数绑定1、传什么接收什么<a href="account/findAccount?accountId=10">查询账户</a>后端:public String findAccount(Integer accountId){}2、实体类User实体类中有name跟age属性,前台传uname、age,后台用实体类直接接收后台:public String findAccount(User user){}3、关联实体类(类中有类),例如Account类中含User类:public class Account implements Serializable{ private String username; private String password; private Double money; private User user; ... } 那它前端就是:<form action="param/saveAccount" method="post"> 姓名:<input type="text" name="username" /><br/> 密码:<input type="text" name="password" /><br/> 金额:<input type="text" name="money" /><br/> 用户姓名:<input type="text" name="user.uname" /><br/> 用户年龄:<input type="text" name="user.age" /><br/> <input type="submit" value="提交" /> </form>4、数组和集合类型参数,实体类中包含List于Map <form action="param/saveAccount" method="post"> 姓名:<input type="text" name="username" /><br/> 密码:<input type="text" name="password" /><br/> 金额:<input type="text" name="money" /><br/> 用户姓名:<input type="text" name="list[0].uname" /><br/> 用户年龄:<input type="text" name="list[0].age" /><br/> 用户姓名:<input type="text" name="map['one'].uname" /><br/> 用户年龄:<input type="text" name="map['one'].age" /><br/> <input type="submit" value="提交" /> </form>过滤器解决中文乱码Get情况下乱码web.xml中加入: <!-- 配置过滤器,解决中文乱码的问题 --> <filter> <filter-name>characterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <!-- 启动过滤器 可不加--> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>在springmvc.xml中可以配置静态资源不过滤<!-- location 表示路径,mapping 表示文件,**表示该目录下的文件以及子目录的文件 --><mvc:resources location="/css/" mapping="/css/**"/><mvc:resources location="/images/" mapping="/images/**"/><mvc:resources location="/scripts/" mapping="/javascript/**"/>Post情况下乱码tomacat 对 GET 和 POST 请求处理方式是不同的,GET 请求的编码问题,要改 tomcat 的 server.xml配置文件,如下:<Connector connectionTimeout="20000" port="8080"protocol="HTTP/1.1" redirectPort="8443"/>改为:<Connector connectionTimeout="20000" port="8080"protocol="HTTP/1.1" redirectPort="8443"useBodyEncodingForURI="true"/>如果遇到 ajax 请求仍然乱码,请把:useBodyEncodingForURI="true"改为 URIEncoding="UTF-8"HiddentHttpMethodFilter由于浏览器 form 表单只支持 GET 与 POST 请求,而 DELETE、PUT 等 method 并不支持,Spring3.0 添加了一个过滤器,可以将浏览器请求改为指定的请求方式,发送给我们的控制器方法,使得支持 GET、POST、PUT 与 DELETE 请求。使用方法:第一步:在 web.xml 中配置该过滤器。第二步:请求方式必须使用 post 请求。第三步:按照要求提供_method 请求参数,该参数的取值就是我们需要的请求方式。 <filter> <filter-name>hiddenHttpMethodFilter</filter-name> <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> </filter> <filter-mapping> <filter-name>hiddenHttpMethodFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>此时,前端就要改成如下: <!-- 保存 --> <form action="springmvc/testRestPOST" method="post"> 用户名称:<input type="text" name="username"><br /> <!-- <input type="hidden" name="_method" value="POST"> --> <input type="submit" value="保存"> </form> <hr /> <!-- 更新 --> <form action="springmvc/testRestPUT/1" method="post"> 用户名称:<input type="text" name="username"><br /> <input type="hidden" name="_method" value="PUT"> <input type="submit" value="更新"> </form>说白了就是在表单中加入了<input type="hidden" name="_method" value="PUT">持续更新中……
坐标:https://mvnrepository.com/artifact/commons-io/commons-io说明: 1.由于是一个工具类使用都非常的简单 所以本文只是将其分类,展示它能够提供给我们什么。 2.习惯看api的可以直接看官方的api 传送门 3.可以看一看官方的指引 指引传送门 4.FileUtils只是commons-io的其中一个工具类分类说明演示: 1.写 文件/文件夹/* 写文件 * 1.这里只列出3种方式全参数形式,api提供部分参数的方法重载 * 2.最后一个布尔参数都是是否是追加模式 * 3.如果目标文件不存在,FileUtils会自动创建 * */ //static void:write(File file, CharSequence data, String encoding, boolean append) FileUtils.write(new File("D:/a/b/cxyapi.txt"), "程序换api","UTF-8",true); //static void:writeLines(File file, Collection<?> lines, boolean append) List<String> lines=new ArrayList<String>(); lines.add("欢迎访问:");lines.add("www.cxyapi.com"); FileUtils.writeLines(new File("D:/a/b/cxyapi.txt"),lines,true); //static void:writeStringToFile(File file, String data, String encoding, boolean append) FileUtils.writeStringToFile(new File("D:/a/b/cxyapi.txt"), "作者:cxy", "UTF-8",true); 2.读 文件/文件夹//读文件 //static String:readFileToString(File file, String encoding) System.out.println(FileUtils.readFileToString(new File("D:/a/b/cxyapi.txt"), "UTF-8")); //static List<String>:readLines(File file, String encoding) System.out.println(FileUtils.readLines(new File("D:/a/b/cxyapi.txt"), "UTF-8")); //返回一个list 3.删除 文件/文件夹//删除目录 //static void:deleteDirectory(File directory) FileUtils.deleteDirectory(new File("D:/not/cxyapi")); //static boolean:deleteQuietly(File file) FileUtils.deleteQuietly(new File("D:/not/cxyapi")); //文件夹不是空任然可以被删除,永远不会抛出异常移动 文件/文件夹//移动文件 或 文件夹 //static void:moveDirectory(File srcDir, File destDir) FileUtils.moveDirectory(new File("D:/cxyapi1"), new File("D:/cxyapi2")); //注意这里 第二个参数文件不存在会引发异常 //static void:moveDirectoryToDirectory(File src, File destDir, boolean createDestDir) FileUtils.moveDirectoryToDirectory(new File("D:/cxyapi2"), new File("D:/cxyapi3"), true); /* 上面两个方法的不同是: * moveDirectory:D:/cxyapi2里的内容是D:/cxyapi1的内容。 * moveDirectoryToDirectory:D:/cxyapi2文件夹移动到到D:/cxyapi3里 * * 下面的3个都比较简单没提供示例,只提供了api * 其中moveToDirectory和其他的区别是 它能自动识别操作文件还是文件夹 */ //static void:moveFileToDirectory(srcFile, destDir, createDestDir) //static void:moveFile(File srcFile, File destFile) //static void:moveToDirectory(File src, File destDir, boolean createDestDir)5.copy//结果是cxyapi和cxyapi1在同一目录 FileUtils.copyDirectory(new File("D:/cxyapi"), new File("D:/cxyapi1")); //结果是将cxyapi拷贝到cxyapi2下 FileUtils.copyDirectoryToDirectory(new File("D:/cxyapi"), new File("D:/cxyapi2")); //拷贝文件 FileUtils.copyFile(new File("d:/cxyapi.xml"), new File("d:/cxyapi.xml.bak")); //拷贝文件到目录中 FileUtils.copyFileToDirectory(new File("d:/cxyapi.xml"), new File("d:/cxyapi")); //拷贝url到文件 FileUtils.copyURLToFile(new URL("http://www.cxyapi.com/rss/cxyapi.xml"), new File("d:/cxyapi.xml")); 6.其他//判断是否包含文件或者文件夹 boolean b=FileUtils.directoryContains(new File("D:/cxyapi"), new File("D:/cxyapi/cxyapi.txt")); System.out.println(b); //获得临时目录 和 用户目录 System.out.println(FileUtils.getTempDirectoryPath()); System.out.println(FileUtils.getUserDirectoryPath()); //打开流,如果不存在创建文件及其目录结构 //第二个参数表示 文件流是否是追加方式 FileOutputStream fos=FileUtils.openOutputStream(new File("D:/cxyapi/cxyapi.txt"),true); fos.write(new String("欢迎访问:www.cxyapi.com\r\n").getBytes()); fos.close(); //文件 或 文件夹大小 System.out.println(FileUtils.sizeOf(new File("D:/cxyapi"))); System.out.println(FileUtils.sizeOfDirectory(new File("D:/cxyapi")));原文:http://snkcxy.iteye.com/blog/1845862