经过三个月的完善与修复,经过几个项目的检验,SpringBlade稳定版终于发布啦! SpringBlade是基于多个优秀的开源项目,高度整合封装而成的快速开发平台。 鸣谢 1.JFinal 内置功能
代码示例 实体类 @Table(name = "notice")@BindID(name = "id")@SuppressWarnings("serial")public class Notice extends BaseModel { private String id; private Integer creater; private String content; private String title; private Date createTime; @AutoID public String getId() { return id; } public void setId(String id) { this.id = id; } .....................} 新增 @ResponseBody @RequestMapping(KEY_SAVE) public AjaxResult save() { Notice notice = mapping(PREFIX, Notice.class); boolean temp = Blade.create(Notice.class).save(notice); if (temp) { return success(SAVE_SUCCESS_MSG); } else { return error(SAVE_FAIL_MSG); } } 修改 @ResponseBody @RequestMapping(KEY_UPDATE) public AjaxResult update() { Notice notice = mapping(PREFIX, Notice.class); boolean temp = Blade.create(Notice.class).update(notice); if (temp) { return success(UPDATE_SUCCESS_MSG); } else { return error(UPDATE_FAIL_MSG); } } 删除 @ResponseBody @RequestMapping(KEY_REMOVE) public AjaxResult remove(@RequestParam String ids) { int cnt = Blade.create(Notice.class).deleteByIds(ids); if (cnt > 0) { return success(DEL_SUCCESS_MSG); } else { return error(DEL_FAIL_MSG); } } 自定义sql查询 List<Map> list = Db.selectList("select * form news where title = #{title}", Paras.create().set("title", "标题测试")); String editor = Db.init("otherDb").queryStr("select editor form news where newsId = #{newsId}", Paras.create().set("newsId", 123)); 根据md文件执行修改操作 int cnt = Md.update("news.update", Paras.create().set("title", "标题测试").set("id", "1")); 根据条件修改 boolean temp = Blade.create(News.class).updateBy("editor = #{editor}", "title = #{title}", Paras.create().set("title", "测试标题").set("editor", "编辑一")); 根据条件删除 String ids = "1,2,3,4,5"; String[] idArr = ids.split(","); int cnt = Blade.create(News.class).deleteBy("status in (#{join(ids)})", Paras.create().set("ids", idArr)); 通用service public interface NoticeService extends IService<Notice> { } @Service public class NoticeServiceImpl extends BaseService<Notice> implements NoticeService { } @Autowired NoticeService service; @ResponseBody @RequestMapping(KEY_SAVE) public AjaxResult save() { Notice notice = mapping(PREFIX, Notice.class); boolean temp = service.save(notice); if (temp) { return success(SAVE_SUCCESS_MSG); } else { return error(SAVE_FAIL_MSG); } } 分页封装 @ResponseBody @RequestMapping(KEY_LIST) public Object list() { Object grid = paginate(LIST_SOURCE, new IQuery() { @Override public void queryBefore(AopContext ac) { if (ShiroKit.lacksRole(ConstShiro.ADMINISTRATOR)) { String condition = "and creater = #{creater}"; ac.setCondition(condition); ac.getParam().put("creater", ShiroKit.getUser().getId()); } } @Override public void queryAfter(AopContext ac) { @SuppressWarnings("unchecked") BladePage<Map<String, Object>> page = (BladePage<Map<String, Object>>) ac.getObject(); List<Map<String, Object>> list = page.getRows(); for (Map<String, Object> map : list) { map.put("createrName", SysCache.getDictName(102, map.get("creater"))); } } }); return grid; } 后台界面 注:前端UI为ACE-ADMIN,如果商用请购买ACE-ADMIN的授权。 git地址:http://git.oschina.net/smallc/SpringBlade |