首页
归档
关于
Search
1
C服务器端
9 阅读
2
1.数据流图(下午题)
8 阅读
3
管道处理模型
8 阅读
4
数据结构与算法
8 阅读
5
3.面向对象设计
7 阅读
软件设计师笔记
.Net
Java
数据库
PHP
运维
前端
Python
中间件相关
云原生
架构设计
Search
标签搜索
websocket
科技新闻
Bi8bo
累计撰写
267
篇文章
累计收到
2
条评论
首页
栏目
软件设计师笔记
.Net
Java
数据库
PHP
运维
前端
Python
中间件相关
云原生
架构设计
页面
归档
关于
搜索到
267
篇与
的结果
2025-04-03
RESTful风格URL
@RequestMapping("/user/{id}") 方法参数用 @PathVariable("id") 将URL参数id中的值取出
2025年04月03日
1 阅读
0 评论
0 点赞
2025-04-03
Formatter 自定义数据绑定 Date类型
<!-- 自定义类型格式化转换器配置 --> <bean id="convertionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"> <property name="formatters"> <set> <bean class="com.My.Controller.Fomatter"></bean> </set> </property> </bean>java代码import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import org.springframework.format.Formatter; public class Fomatter implements Formatter<Date> { private String datePattern="yyyy-MM-dd HH:mm:ss"; //声明SimpleDateFormat对象 SimpleDateFormat simpleDateFormat; @Override public String print(Date date, Locale locale) { return new SimpleDateFormat().format(date); } @Override public Date parse(String souce, Locale locale) throws ParseException { simpleDateFormat = new SimpleDateFormat(datePattern); return simpleDateFormat.parse(souce); } }
2025年04月03日
0 阅读
0 评论
0 点赞
2025-04-03
Cros 跨域拦截器
@Configuration @EnableWebMvc public class ConfigurerAdapter implements WebMvcConfigurer { @Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = new CorsConfiguration(); // 允许cookies跨域 config.setAllowCredentials(true); // #允许向该服务器提交请求的URI,*表示全部允许,在SpringMVC中,如果设成*,会自动转成当前请求头中的Origin config.addAllowedOriginPattern("*"); // #允许访问的头信息,*表示全部 config.addAllowedHeader("*"); // 预检请求的缓存时间(秒),即在这个时间段里,对于相同的跨域请求不会再预检了 config.setMaxAge(18000L); // 允许提交请求的方法类型,*表示全部允许 config.addAllowedMethod("OPTIONS"); config.addAllowedMethod("HEAD"); config.addAllowedMethod("GET"); config.addAllowedMethod("PUT"); config.addAllowedMethod("POST"); config.addAllowedMethod("DELETE"); config.addAllowedMethod("PATCH"); source.registerCorsConfiguration("/**", config); return new CorsFilter(source); } }
2025年04月03日
0 阅读
0 评论
0 点赞
2025-04-03
Convert 自定义数据绑定 (日期转换器为例)
mvc.xml配置<!-- 显示的装配自定义类型转换器 --> <mvc:annotation-driven conversion-service="convertionService" /> <!-- 自定义类型转换器配置 --> <bean id="convertionService" class="org.springframework.context.support.ConversionServiceFactoryBean"> <property name="converters"> <set> <bean class="com.My.Convert.DateConverter"></bean> </set> </property> </bean>java代码package com.My.Convert; import java.text.SimpleDateFormat; import java.util.Date; import org.springframework.core.convert.converter.Converter; /** * 自定义日期转换器 * */ public class DateConverter implements Converter<String, Date> { private String datePattern="yyyy-MM-dd HH:mm:ss"; @Override public Date convert(String source) { //格式化日期 SimpleDateFormat sdf = new SimpleDateFormat(datePattern); try { return sdf.parse(source); } catch (Exception e) { throw new IllegalArgumentException("无效日期格式,请使用:"+datePattern); } } }
2025年04月03日
3 阅读
0 评论
0 点赞
2025-04-03
AJAX 提交表单混合文件
今天做一个SSM框架项目的时候碰到一个问题,ajax表单混合文件提交如何实现,整半天终于弄出来了HTML部分<form id="formData"> <div class="form-row"> <div class="form-group col-md-6"> <label>商品名称</label> <input type="text" name="name" class="form-control"> </div> <div class="form-group col-md-6"> <label>商品外部编号</label> <input type="number" name="externalId" class="form-control"> </div> </div> <div class="form-row"> <div class="form-group col-md-6"> <label>所属分类</label> <select name="categoryId" class="custom-select"> <c:forEach var="items" items="${categories}"> <option value="${items.id}">${items.name}</option> </c:forEach> </select> </div> <div class="form-group col-md-6"> <label>市场价格</label> <input type="text" name="price" class="form-control"> </div> </div> <div class="form-row"> <div class="form-group col-md-6"> <label>店内价格</label> <input name="shopPrice" type="text" class="form-control"> </div> <div class="form-group col-md-6"> <label>商品库存</label> <input type="number" name="quantity" class="form-control"> </div> </div> <div class="form-row"> <div class="form-group col-md-6"> <label>是否记录库存</label> <div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="inventoryFlag" id="quantityyes" value="0" checked> <label class="form-check-label" for="quantityyes">是</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="inventoryFlag" id="quantityno" value="1"> <label class="form-check-label" for="quantityno">否</label> </div> </div> </div> <div class="form-group col-md-6"> <label>是否热销</label> <div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="hot" id="hotno" value="1"> <label class="form-check-label" for="hotno">非热门商品</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="hot" id="hotyes" value="0" checked> <label class="form-check-label" for="hotyes">热门商品</label> </div> </div> </div> </div> <div class="form-row"> <div class="form-group col-md-6"> <label>状态</label> <select name="productStatus" class="custom-select"> <option selected value="0">上架</option> <option value="1">下架</option> </select> </div> <div class="form-group col-md-6"> <label>商品概要说明</label> <input type="text" name="generalExplain" class="form-control"> </div> </div> <div class="form-row"> <div class="form-group col-md-6"> <label>上传图片</label> <div class="custom-file"> <input type="file" name="file" class="custom-file-input" id="imagefile"> <label class="custom-file-label" for="inputGroupFile03">上传图片</label> <small class="form-text text-muted">上传图片的最佳尺寸:300像素*300像素,其他尺寸会影响页面效果,格式png,jpeg,jpg,gif。大小不超过1M</small> </div> </div> </div> <div class="form-row"> <div> <button type="button" style="margin-right:10px" id="save" class="btn btn-success">保存</button> </div> <div> <button type="button" class="btn btn-success">返回</button> </div> </div> </form>JS 代码 $(function () { //提交 $("#save").click(function () { //创建表单数据容器 var formData = new FormData() //获取文件数据 file = $('#imagefile')[0].files[0]; //检查文件上传 if (!file) { alert('请先上传文件'); return; } //添加表单数据 formData.append('file', file); //得到页面所有表单数据,Array转Object var AllInputData = $("#formData").serializeArray(); AllInputData.forEach(function (e) { formData.append(e['name'], e['value']); }); //发送请求 $.ajax({ url: 'addProduct?${_csrf.parameterName}=${_csrf.token}', type: 'post', data: formData, contentType: false, processData: false, success: function (resp) { console.log(resp); } }) }) })注意:如果JQury出现Illegal invocation异常是因为没有取消表单处理,ajax里面添加processData: false属性就OK了后台接收部分包含的文件用 MultipartFile接收 并且 必须加上@RequestParam注解,不然不能正常接收! /** * 添加商品 */ @RequestMapping(value="addProduct",method=RequestMethod.POST) //Product是我自己定义的一个包装类, public String addProduct(Product product,@RequestParam("file")MultipartFile file){ System.out.println(product.getName()); System.out.println(file.getOriginalFilename()); return null; }
2025年04月03日
4 阅读
0 评论
0 点赞
1
...
6
7
8
...
54