use of com.blade.mvc.annotation.Route in project tale by otale.
the class CommentController method delete.
@Route(value = "status", method = HttpMethod.POST)
@JSON
public RestResponse delete(@QueryParam Integer coid, @QueryParam String status) {
try {
Comments comments = new Comments();
comments.setCoid(coid);
comments.setStatus(status);
commentsService.update(comments);
siteService.cleanCache(Types.C_STATISTICS);
} catch (Exception e) {
String msg = "操作失败";
if (e instanceof TipException) {
msg = e.getMessage();
} else {
LOGGER.error(msg, e);
}
return RestResponse.fail(msg);
}
return RestResponse.ok();
}
use of com.blade.mvc.annotation.Route in project tale by otale.
the class IndexController method upPwd.
/**
* 修改密码
*/
@Route(value = "password", method = HttpMethod.POST)
@JSON
public RestResponse upPwd(@QueryParam String old_password, @QueryParam String password, Request request) {
Users users = this.user();
if (StringKit.isBlank(old_password) || StringKit.isBlank(password)) {
return RestResponse.fail("请确认信息输入完整");
}
if (!users.getPassword().equals(Tools.md5(users.getUsername() + old_password))) {
return RestResponse.fail("旧密码错误");
}
if (password.length() < 6 || password.length() > 14) {
return RestResponse.fail("请输入6-14位密码");
}
try {
Users temp = new Users();
temp.setUid(users.getUid());
String pwd = Tools.md5(users.getUsername() + password);
temp.setPassword(pwd);
usersService.update(temp);
logService.save(LogActions.UP_PWD, null, request.address(), this.getUid());
return RestResponse.ok();
} catch (Exception e) {
String msg = "密码修改失败";
if (e instanceof TipException) {
msg = e.getMessage();
} else {
LOGGER.error(msg, e);
}
return RestResponse.fail(msg);
}
}
use of com.blade.mvc.annotation.Route in project tale by otale.
the class IndexController method index.
/**
* 仪表盘
*/
@Route(value = { "/", "index" }, method = HttpMethod.GET)
public String index(Request request) {
List<Comments> comments = siteService.recentComments(5);
List<Contents> contents = siteService.getContens(Types.RECENT_ARTICLE, 5);
Statistics statistics = siteService.getStatistics();
// 取最新的20条日志
List<Logs> logs = logService.getLogs(1, 20);
request.attribute("comments", comments);
request.attribute("articles", contents);
request.attribute("statistics", statistics);
request.attribute("logs", logs);
return "admin/index";
}
use of com.blade.mvc.annotation.Route in project blade by biezhi.
the class RouteBuilder method addRouter.
/**
* Parse all routing in a controller
*
* @param router resolve the routing class
*/
public void addRouter(final Class<?> router) {
Method[] methods = router.getMethods();
if (null == methods || methods.length == 0) {
return;
}
String nameSpace = null, suffix = null;
if (null != router.getAnnotation(Controller.class)) {
nameSpace = router.getAnnotation(Controller.class).value();
suffix = router.getAnnotation(Controller.class).suffix();
}
if (null != router.getAnnotation(RestController.class)) {
nameSpace = router.getAnnotation(RestController.class).value();
suffix = router.getAnnotation(RestController.class).suffix();
}
if (null == nameSpace) {
LOGGER.warn("Route [{}] not controller annotation", router.getName());
return;
}
for (Method method : methods) {
Route mapping = method.getAnnotation(Route.class);
//route method
if (null != mapping) {
// build multiple route
HttpMethod methodType = mapping.method();
String[] paths = mapping.values();
if (mapping.value().length > 1 || !mapping.value()[0].equals("/")) {
paths = mapping.value();
}
if (paths.length > 0) {
for (String path : paths) {
String pathV = getRoutePath(path, nameSpace, suffix);
this.buildRoute(router, method, pathV, methodType);
}
}
}
}
}
use of com.blade.mvc.annotation.Route in project tale by otale.
the class AttachController method delete.
@Route(value = "delete")
@JSON
public RestResponse delete(@QueryParam Integer id, Request request) {
try {
Attach attach = attachService.byId(id);
if (null == attach)
return RestResponse.fail("不存在该附件");
attachService.delete(id);
siteService.cleanCache(Types.C_STATISTICS);
String upDir = CLASSPATH.substring(0, CLASSPATH.length() - 1);
FileKit.delete(upDir + attach.getFkey());
logService.save(LogActions.DEL_ATTACH, attach.getFkey(), request.address(), this.getUid());
} catch (Exception e) {
String msg = "附件删除失败";
if (e instanceof TipException)
msg = e.getMessage();
else
LOGGER.error(msg, e);
return RestResponse.fail(msg);
}
return RestResponse.ok();
}
Aggregations