com.ajaxjs.website.controller.ArticleAdminController Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ajaxjs-framework2 Show documentation
Show all versions of ajaxjs-framework2 Show documentation
AJAXJS aims to full-stack, not only the server-side framework,
but also integrates the front-end library. It's written in HTML5 + Java, a successor to the JVM platform, efficient, secure, stable, cross-platform and many other advantages, but it abandoned the traditional enterprise architecture brought about by the large and bloated,
emphasizing the lightweight, and fast, very suitable for the Internet fast application.
The newest version!
package com.ajaxjs.website.controller;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ajaxjs.framework.BaseController;
import com.ajaxjs.framework.CommonConstant;
import com.ajaxjs.framework.filter.DataBaseFilter;
import com.ajaxjs.net.http.PicDownload;
import com.ajaxjs.sql.SnowflakeId;
import com.ajaxjs.sql.orm.PageResult;
import com.ajaxjs.web.mvc.MvcRequest;
import com.ajaxjs.website.model.Article;
import com.ajaxjs.website.service.ArticleService;
@Controller
@RequestMapping("/admin/entity/article")
public class ArticleAdminController extends BaseController {
@Autowired
private ArticleService service;
@DataBaseFilter
@GetMapping(LIST)
// @MvcFilter(filters = { DataBaseFilter.class, XslMaker.class })
public String adminList(int start, int limit, @RequestParam(required = false) Integer catalogId, ModelMap mv) {
if (catalogId == null || catalogId == 0)
catalogId = service.getDomainCatalogId();
PageResult list = service.list(catalogId, start, limit, CommonConstant.OFF_LINE);
// if (list.get(0).get("catalogId").getClass() == Integer.class) {
// // SQLite 配合 Map 不会出现期望的 Long。还是建议不要使用 Map
// for (Map map : list)
// map.put("catalogId", Long.parseLong(map.get("catalogId").toString()));
// }
//
// mv.put(XslMaker.XSL_TEMPLATE_PATH, "website/article-xsl");
prepareData(mv, service);
return output(mv, service, list, "entity/article-admin-list");
}
@GetMapping
public String createUI(ModelMap mv) {
prepareData(mv, service);
return "website/article-edit";
}
@ResponseBody
@DataBaseFilter
@PostMapping(produces = JSON)
public String create(Article entity) {
return create(service, entity);
}
@DataBaseFilter
@GetMapping(ID_INFO)
public String editUI(@PathVariable(ID) Long id, ModelMap mv) {
mv.put("isCreate", false);
return output(mv, service, id, "website/article-edit");
}
@ResponseBody
@DataBaseFilter
@PutMapping(value = ID_INFO, produces = JSON)
public String update(@PathVariable(ID) Long id, Article entity) {
return update(service, id, entity);
}
@ResponseBody
@DataBaseFilter
@DeleteMapping(value = ID_INFO, produces = JSON)
public String delete(@PathVariable(ID) Long id) {
return delete(service, id, new Article());
}
// @POST
// @Path("/admin/{root}/{id}/uploadCover/")
// @MvcFilter(filters = DataBaseFilter.class)
// @Produces(MediaType.APPLICATION_JSON)
// public String uploadCover(MvcRequest req, @PathParam(ID) Long id) {
// LOGGER.info("上传封面图片");
//
// // 必须先有实体才能上传其图片
// if (service.findById(id) == null)
// throw new NullPointerException("请保存记录后再上传图片");
//
// UploadFileInfo info = new UploadFileInfo();
//
// // 约束上传
// info.maxSingleFileSize = 512 * 1000;
// info.allowExtFilenames = new String[] { "jpeg", "jpg", "png", "gif" };
//
// String filename = "cover/" + SnowflakeIdWorker.getIdStr();
//
// return AttachmentController.upload(req, _filename -> {
// Map article = new HashMap<>(); // 保存字段
// article.put("id", id);
// article.put("cover", Encode.urlDecode(info.saveFileName));
// service.update(article);
// }, info, filename);
// }
// @POST
// @Path("/admin/{root}/{id}/uploadContentImg/")
// @MvcFilter(filters = DataBaseFilter.class)
// @Produces(MediaType.APPLICATION_JSON)
// public String uploadContentImg(MvcRequest req, @PathParam(ID) Long id) {
// LOGGER.info("上传正文图片");
//
// UploadFileInfo info = new UploadFileInfo();
// // 约束上传
// info.maxSingleFileSize = 512 * 1000;
// info.allowExtFilenames = new String[] { "jpeg", "jpg", "png", "gif" };
//
// String filename = "contentImg/" + SnowflakeIdWorker.getIdStr();
// return AttachmentController.upload(req, null, info, filename);
// }
// 下载远程图片到本地服务器
@ResponseBody
@PostMapping(value = "downAllPics", produces = JSON)
public String downAllPics(String pics, HttpServletRequest req) {
String[] arr = pics.split("\\|");
MvcRequest r = (MvcRequest) req;
new PicDownload(arr, r.mappath("/images"), () -> SnowflakeId.get() + "").start();
return toJson(new Object() {
@SuppressWarnings("unused")
public String[] pics = arr;
});
}
}