0.学习教程
http://www.cnblogs.com/jiekzou/p/9205117.html
https://github.com/crossoverJie/SSM
1.gradle没刷新导致的jar包不能解析:
点击View->Tool Window->Gradle->点击面板里第一个按钮Refresh All.重新运行即可.
2.打开gradle构建的项目,import找到build.gradle文件确定.
3.mybatis注解like(http://lavasoft.blog.51cto.com/62575/1386870/):
@Select("select * from girl where name like "%"#{name}"%"")
public List<Girl> likeName(String name);
4.mybatis insert 返回id自增的值
<insert id="register" useGeneratedKeys="true" keyProperty="memberId" parameterType="com.xxx.entity.Member">
insert into member (member_name,member_phone_no)values(#{memberName},#{memberPhoneNo})
</insert>
5.idea使用git版本控制
菜单 vcs ->Enable Version Control Integration选择git
6.git提示非空目录:先在目录内执行git init命令
7.eclipse: class path resource [applicationContext.xml] cannot be opened because it does not exist;
close项目,重新添加到eclipse,然后project->clean
20.java lambda linq
查找第一个(https://www.cnblogs.com/liguoyi/p/5899179.html)
Optional<WbCompany> tmpCompany = filteredCompanyList.stream().filter(s -> s.id.equals(wbCompany.getId())).findFirst();
if (tmpCompany.isPresent()) {
WbCompany company=tmpCompany.get();
}
ThreadLocal<Float> f=new ThreadLocal<Float>() ;
wbCompanyGzList.forEach(s->{
f.set(f.get()+s.getMoney());
});
21.jsp和js数组互操作
var c='<c:out value="${bp.title}"/>';
alert(c);
var ias=[];
alert('<c:out value="${atts.size()}"/>');
for(var i=0;i<${atts.size()};i++){
var fp='${atts[0].filePath}';
//alert(fp);
}
console.log(ias);
22.多文件上传
第一种需要input的name和requestparam里的value设置一直
<form method="post" action="issue/uploadFile.do?FileType=Photo" enctype="multipart/form-data">
<input name="uploadFiles" type="file" />
<button type="submit">submit</button>
</form>
@RequestMapping("/uploadFile")
public void uploadFile(@RequestParam(value = "uploadFiles") MultipartFile[] uploadFiles, HttpServletRequest request, HttpServletResponse response,
HttpSession session) {
JSONObject param = new JSONObject();
if (uploadFiles == null || uploadFiles.length <= 0) {
param.put("token", false);
param.put("datas", null);
param.put("msg", "请选择文件.");
ServletUtil.write(response, param.toString());
return;
}
for (MultipartFile file : uploadFiles) {
String filename = file.getOriginalFilename();
String oriName = file.getOriginalFilename();
String extName = oriName.substring(oriName.lastIndexOf(".")).toUpperCase();
if (!extension.contains(extName)) {
param.put("token", false);
param.put("datas", null);
param.put("msg", "不支持的文件格式.仅支持:" + extension);
ServletUtil.write(response, param.toString());
}
String savePath=serverPath+"\photo\"+UUID.randomUUID()+"--"+filename;
file.transferTo(new File(savePath));//保存
}
}
第二种 input的 name随便取
@RequestMapping("/uploadFile1")
public void uploadFile1(MultipartHttpServletRequest request, HttpServletResponse response, HttpSession session)throws IllegalStateException, IOException {
List<CommonsMultipartFile> uploadFiles = new ArrayList<>();
CommonsMultipartFile multipartFile = null;
Iterator<String> itr = request.getFileNames();
while (itr.hasNext()) {
String str = itr.next();
multipartFile = (CommonsMultipartFile) request.getFile(str);
String fileName = multipartFile.getOriginalFilename(); // 原文件名
CommonsMultipartFile mpf = (CommonsMultipartFile) request.getFile(str);
//// mpf.transferTo(new File("c:\upload\"+fileName));
uploadFiles.add(mpf);
}
}
23.ffmpeg将amr转mp3
(仅限window平台)将ffmpeg.exe放在webroot下
调用: ToMp3(request.getSession().getServletContext().getRealPath("/"), savePath);
https://blog.csdn.net/luqyu/article/details/43525795
/**
* 将上传的录音转为mp3格式
* @param webroot 项目的根目录
* @param sourcePath 文件的相对地址
*/
public static void ToMp3(String webroot, String sourcePath){
//File file = new File(sourcePath);
String targetPath = sourcePath+".mp3";//转换后文件的存储地址,直接将原来的文件名后加mp3后缀名
Runtime run = null;
try {
run = Runtime.getRuntime();
long start=System.currentTimeMillis();
Process p=run.exec(webroot+"/ffmpeg -i "+sourcePath+" -acodec libmp3lame "+ targetPath);//执行ffmpeg.exe,前面是ffmpeg.exe的地址,中间是需要转换的文件地址,后面是转换后的文件地址。-i是转换方式,意思是可编码解码,mp3编码方式采用的是libmp3lame
//释放进程
p.getOutputStream().close();
p.getInputStream().close();
p.getErrorStream().close();
p.waitFor();
long end=System.currentTimeMillis();
System.out.println(sourcePath+" convert success, costs:"+(end-start)+"ms");
//删除原来的文件
//if(file.exists()){
//file.delete();
//}
} catch (Exception e) {
e.printStackTrace();
}finally{
//run调用lame解码器最后释放内存
run.freeMemory();
}
}
(跨平台) http://www.sauronsoftware.it/projects/jave/download.php下载jave.jar导入
http://mfan.iteye.com/blog/2032454
public static void changeToMp3(String sourcePath, String targetPath) {
File source = new File(sourcePath);
File target = new File(targetPath);
AudioAttributes audio = new AudioAttributes();
Encoder encoder = new Encoder();
audio.setCodec("libmp3lame");
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("mp3");
attrs.setAudioAttributes(audio);
try {
encoder.encode(source, target, attrs);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InputFormatException e) {
e.printStackTrace();
} catch (EncoderException e) {
e.printStackTrace();
}
}
From:http://www.cnblogs.com/xuejianxiyang/p/7298303.html