js获取url后缀参数
http://localhost:8080/ReadBank/pages/forum/forum_detail.jsp?forumId=2
利用以下方法可获取到2
var forumId=GetQueryString("forumId" );
//获取帖子Id
function GetQueryString(name)
{
var reg = new RegExp("(^|&)" + name +"=([^&]*)(&|$)" );
var r = window.location.search.substr(1).match(reg);
if(r!=null )
return unescape(r[2]);
return null ;
};
ajax上传文件:
var formData = new FormData();
formData.append( 'file', $('#file')[0].files[0]);
$.ajax({
type: 'POST',
url:' <%=basePath %>user/updateheadicon ',
data:formData,
dataType: 'json',
processData: false,
contentType: false,
success: function(data){
mui.alert( "头像更换成功" );
}
});
后台:
@RequestMapping(value="/updateheadicon" ,method={RequestMethod.GET,RequestMethod. POST})
public
@ResponseBody
Map<String, Object> updateheadiconMethod(@RequestParam (value="file" ) MultipartFile file,HttpServletRequest request,HttpServletResponse response ) throws IOException{
Map<String, Object> result= new HashMap<String, Object>();
HttpSession session=request.getSession();
User user1=(User) session.getAttribute( "user");
long userId =user1 .getUserId();
InputStream inputStream = file.getInputStream();
User user=new User();
user.setUserId( userId);
String fileType="Picture";
String url=UploadAliYunFile.UploadAliYunFileService( inputStream, file, fileType );
user.setUserHeadicon( url);
int flag=userService.changeUser( user);
if(flag==0){
result.put( "message","参数未传或数据库更新异常" );
result.put( "status", false );
}else{
result.put( "message", "修改成功。" );
result.put( "status", true );
}
return result;
}
java字符串去除开始的0
dataList .add(str.substring(6,8).replaceFirst( "^0*", "" ));
路径获取方法:
/**
* System.out.println("当前类所在包名的路径及名称: " + this.getClass());
* 当前类所在包名的路径及名称: class com.core.controller.UserController
*
* System.out.println("当前类的加载器器文件路径: " + this.getClass().getClassLoader().getResource(""));
* 当前类的加载器器文件路径: file:/绝对路径/WuTuoBang/Spring/Smart/out/artifacts/WuTuoBang/WEB-INF/classes/
*
* System.out.println("当前类的加载器器文件路径: " + this.getClass().getClassLoader().getResource("").getFile());
* 当前类的加载器器文件路径: /绝对路径/WuTuoBang/Spring/Smart/out/artifacts/WuTuoBang/WEB-INF/classes/
*
* System.out.println("服务端可访问的文件资源路径: " + this.getClass().getClassLoader().getResource("../").getFile());
* 服务端可访问的文件资源路径: /绝对路径/WuTuoBang/Spring/Smart/out/artifacts/WuTuoBang/WEB-INF/
*
* System.out.println("当前项目的根文件路径: " + this.getClass().getClassLoader().getResource("../../").getFile());
* 当前项目的根文件路径: /绝对路径/WuTuoBang/Spring/Smart/out/artifacts/WuTuoBang/
*/