<dependency>
<groupId>javax.servletgroupId>
<artifactId>javax.servlet-apiartifactId>
<scope>providedscope>
dependency>
<dependency>
<groupId>javax.servletgroupId>
<artifactId>jstlartifactId>
<scope>providedscope>
dependency>
<dependency>
<groupId>org.apache.tomcat.embedgroupId>
<artifactId>tomcat-embed-jasperartifactId>
<scope>providedscope>
dependency>
<dependency>
<groupId>org.apache.tomcatgroupId>
<artifactId>tomcat-jsp-apiartifactId>
<scope>providedscope>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-tomcatartifactId>
<scope>providedscope>
dependency>
spring boot项目访问jsp出现cannot be resolved in either web.xml or the jar files deployed with this application错误,原因是c标签jstl的maven坐标未正确导入,可以先暂时删除jsp页面的c标签
spring boot项目访问jsp出现java.lang.ClassNotFoundException: org.apache.jsp.index_jsp错误,原因也是c标签jstl的maven坐标未正确导入,可以先暂时删除jsp页面的c标签
spring boot项目中mybatis的mapper找不到,Consider defining a bean of type ‘tang.poi_test.CarinfoMapper’ in your configuration,原因在于spring boot启动类上要加@MapperScan注解。
@MapperScan(“tang.poi_test”)
spring mvc项目接收数组参数解决办法:
后台:
Carinfo是实体类。
@ResponseBody
@RequestMapping("/save")
public List<Carinfo> save(HttpServletRequest request,@RequestBody List<Carinfo> carinfos) {
for (Carinfo carinfo : carinfos) {
myService.insert(carinfo);
}
return carinfos;
}
前端:
function save(){
var newrows=$(".newrow");
var jsondata=new Array();
newrows.each(function(){
var inputs=$(this).find("input");
var rowdata={};
for(var i=0;i<inputs.length;i++){
var name=$(inputs[i]).attr("name");
var value=inputs[i].value;
rowdata[name]=value;
}
jsondata.push(rowdata);
});
$.ajax({
type : "post",
data : JSON.stringify(jsondata),
url : "save",
contentType : "application/json; charset=utf8",
//contentType : "application/x-www-form-urlencoded; charset=utf8",
dateType : "json",
success : function(data) {
alert("保存成功");
},
error : function(err) {
alert("网络异常或系统错误,请稍后重试!");
}
});
}
spring mvc文件上传:
后台:
@ResponseBody
@RequestMapping("/upload")
public JsonResult upload(HttpServletRequest request,@RequestParam("uploadFile") MultipartFile file) {
JsonResult result=new JsonResult();
result.setCode("400");
if (!HttpUtils.isEmptyFile(file)) {
if (!HttpUtils.isAllowUploadFileExt(file.getOriginalFilename(), "xlsx")) {
result.setMsg("文件格式错误,只允许" + HttpUtils.extMap.get("xlsx") + "格式");
}else if (file.getSize() > HttpUtils.fileSize1mb) {// 文件上传大小
result.setMsg("文件最大不得超过1MB");
}else {
try {
Workbook workbook = WorkbookFactory.create(file.getInputStream());
String path = HttpUtils.getPath(request, "error", file.getOriginalFilename());
return taskHandle(request,workbook, file, path);
//
// String path = HttpUtils.uploadFile(request, file, "excel");
// String basePath = HttpUtils.getBasePath(request);
// String fullPath = basePath + path;
// result.setCode("200");
// result.setMsg("上传成功");
// result.setData(fullPath);
// System.out.println("上传成功>>>>>>>>>>>>>>>>>>>"+fullPath);
} catch (Exception e) {
e.printStackTrace();
result.setMsg("上传文件发生错误");
}
}
}else{
result.setMsg("上传的文件为空");
}
return result;
}
前端:
注释部分是非ajax提交,是能用的。
function upload(){
var formEle=document.getElementById("dataForm");
//formEle.method="post";
//formEle.enctype="multipart/form-data";
//formEle.action="upload";
//formEle.submit();
var form = new FormData(formEle);
$.ajax({
type : "post",
data : form,
url : "upload",
cache: false,
processData: false,
contentType: false,
dateType : "json",
success : function(data) {
if(data){
if(data.code=="200"){
alert(data.data);
}else{
alert(data.msg);
}
}else{
alert("网络异常或系统错误,请稍后重试!");
}
},
error : function(err) {
alert("网络异常或系统错误,请稍后重试!");
}
});
}
前端html:
将input file放入dataForm这个form中即可。