Authored by mlge

选择当前页

... ... @@ -116,22 +116,33 @@ public class ShowCtrl {
@GetMapping("/updateSampleInfo")
public String updateSampleInfo(boolean flag, int currentIndex, String sampleDir){
File file = new File(sampleDir + "/update.info");
if(!file.exists()){
try {
FileUtils.forceMkdirParent(file);
} catch (IOException e) {
e.printStackTrace();
return "创建update.info文件失败!";
}
if(!showSer.checkFile(file)){
return "创建文件失败!";
}
if( !showSer.modifyFile(file, currentIndex, flag)){
return "更新失败!";
}
return "";
}
@GetMapping("/updateSamplesByBatch")
public String updateSamplesByBatch(boolean flag, String indexListStr, String sampleDir){
File file = new File(sampleDir + "/update.info");
if(!showSer.checkFile(file)){
return "创建文件失败!";
}
if( !showSer.modifyFile(file, indexListStr, flag)){
return "更新失败!";
}
return "";
}
@RequestMapping("/loadSingleImage")
public ModelAndView loadSingleImage(){
return new ModelAndView("loadSingleImage");
}
}
... ...
... ... @@ -276,7 +276,8 @@ public class ShowSer {
* @param flag --true ,当前行号写入文件 false --当前行 移出文件
*/
public boolean modifyFile(File file, int content, boolean flag) {
public synchronized boolean modifyFile(File file, int content, boolean flag) {
if(flag){
try {//追加写入文件
FileUtils.writeLines(file,"utf-8",Arrays.asList(content), true);
... ... @@ -284,7 +285,8 @@ public class ShowSer {
e.printStackTrace();
return false;
}
}/*else {//从文件中移出
};
/*else {//从文件中移出
LineIterator lineIterator = null;
try {
lineIterator = FileUtils.lineIterator(file);
... ... @@ -303,4 +305,37 @@ public class ShowSer {
}*/
return true;
}
public synchronized boolean modifyFile(File file, String contentListStr, boolean flag) {
if(flag){
try {//追加写入文件
String[] strings = StringUtils.split(contentListStr, ",");
FileUtils.writeLines(file,"utf-8",Arrays.asList(strings), true);
} catch (IOException e) {
e.printStackTrace();
return false;
}
};
return true;
}
public boolean checkFile(File file){
if(!file.exists()){
try {
FileUtils.forceMkdirParent(file);
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
return true;
}
}
... ...
... ... @@ -1046,12 +1046,15 @@
return "<img src='"+mData.npic+"'>";
}
},
{sTitle: "标识", mData: function(mData){
{sTitle: "<button onclick='chooseAll()' class='btn btn-xs mini green'>标识当前页</button>", mData: function(mData){
if(mData.flag){//已经做了标识的
return "&radic;";
}else {
return "<button class='btn btn-xs mini red' onclick='changeFlag(true,"+mData.currentIndex+")' >标识</button>";
var result = "<input type='hidden' name = 'currentIndex' value ="+mData.currentIndex+" >";
result +="<button class='btn btn-xs mini red' onclick='changeFlag(true,"+mData.currentIndex+")' >标识</button>";
return result;
}
}
}
],
... ... @@ -1111,6 +1114,38 @@
}
//选择当前页
function chooseAll() {
var indexList = new Array();
$("#sampleTable tbody").find("input[name='currentIndex']").each(function (index, item) {
console.log("选中的index:" + $(this).val());
var value = $(this).val();
indexList.push(value);
});
var indexListStr = indexList.join(",");
//发送ajax请求
$.ajax({
url: encodeURI("/show/updateSamplesByBatch?flag=true" + "&indexListStr=" + indexListStr + "&sampleDir=" + sampleDir),
type: "get",
success: function (data) {
if (data != "") {
alert(data);
} else {
sampleTable.fnDraw();
}
},
error: function (data) {
alert("更新失败");
}
});
}
... ...