You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.3 KiB
75 lines
2.3 KiB
package web.controller;
|
|
|
|
import db.form.DBAction;
|
|
import db.form.PageResult;
|
|
import db.model.bilibili.DataModel;
|
|
import org.apache.commons.io.IOUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.hibernate.criterion.DetachedCriteria;
|
|
import org.hibernate.criterion.MatchMode;
|
|
import org.hibernate.criterion.Property;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import web.model.DataModelForm;
|
|
import web.service.DataService;
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
import java.io.IOException;
|
|
import java.nio.charset.Charset;
|
|
import java.util.EnumSet;
|
|
import java.util.List;
|
|
|
|
@Controller
|
|
@RequestMapping("/data")
|
|
public class DataController extends TableController<DataModel, DataModelForm,DataService> {
|
|
|
|
private final String regionJson=IOUtils.toString(DataController.class.getResourceAsStream("/region.json"), Charset.forName("UTF-8"));
|
|
|
|
public DataController() throws IOException {
|
|
}
|
|
|
|
|
|
@RequestMapping
|
|
public String find(HttpSession session,Model model) {
|
|
session.setAttribute("regionJson",regionJson);
|
|
return super.find(model,new DataModelForm(),new PageResult(0,10));
|
|
}
|
|
|
|
@RequestMapping("start/{size}")
|
|
public void start(@PathVariable Integer size){
|
|
stop();
|
|
service.start(size);
|
|
}
|
|
|
|
@RequestMapping("stop")
|
|
public void stop(){
|
|
service.stop();
|
|
}
|
|
|
|
@Override
|
|
public boolean checkAction(DBAction action) {
|
|
return !EnumSet.of(DBAction.D).contains(action);
|
|
}
|
|
|
|
@Override
|
|
protected DetachedCriteria getDetachedCriteria(DataModelForm queryCommand) {
|
|
DetachedCriteria criteria= super.getDetachedCriteria(queryCommand);
|
|
if(StringUtils.isNotEmpty(queryCommand.getTitle())){
|
|
criteria.add(Property.forName("title").like(queryCommand.getTitle(),MatchMode.ANYWHERE));
|
|
}
|
|
|
|
return criteria;
|
|
}
|
|
|
|
@Override
|
|
protected List find(DataModelForm command, Integer firstResult, Integer maxResults) {
|
|
return service.find(command, firstResult, maxResults);
|
|
}
|
|
|
|
@Override
|
|
protected long rowCount(DataModelForm command) {
|
|
return service.rowCount(command);
|
|
}
|
|
}
|
|
|