playframework2框架介绍

1.play项目的结构

 

  app中主要的包有controllers,filters,models,service,utils.

  • 其中controllers是控制器,相当于springMVC中的Controller
  • filter是拦截器,可以理解为springMVC中的HandlerInterceptor
  • models相当去SSM框架的dao层,持久层
  • services相当于SSM框架的service层,业务层

  conf的文件主要有mysql.conf,application.conf,routes;

  • mysql.conf主要配置一些与MySQL数据库有关的设置
  • application.conf配置一些redis,cache,h2db之类的配置
  • routes这个配置文件相当去springmvc的前端处理器,比如

  POST    /v1/tasks/:taskId/reward   controllers.TaskApplicantsController.reward(taskId : Int)

  分别对应http方法   url    类中的方法

  play2框架的构建工具用的是sbt,build.sbt是其构建工具

 

2.play框架的增删改查

  •    @Inject
        private MyCacheApi cache; 
    public Result create() {
            JsonNode body = request().body().asJson();
            String title = ApplicationHelper.getParamsInPath(body, Constants.TITLE, true);
            Users user = Users.getUser(cache.getUserId(request()));
            try {
                checkPermission(user);
            } catch (Exception e) {
                return badRequest(ApplicationHelper.getErrorJson(CodeConstants.INVALID_PARAM_ERROR,
                        e.getMessage()));
            }
            Council council = new Council();
            council.setTitle(title);
            council.insert();
            return ok(Json.toJson(council));
        }
  • public Result delete(int sectionId) {
        Sections sections = Sections.getSection(sectionId);
        if (sections != null) {
            sections.delete();
        }
        return ok();
    }
  • public Result update(Integer councilId) {
        JsonNode body = request().body().asJson();
        String title = null;
        try {
            title = ApplicationHelper.getParamsInPath(body, Constants.TITLE, true);
        } catch (Exception e) {
            return badRequest(ApplicationHelper.getErrorJson(CodeConstants.INVALID_PARAM_ERROR,
                    e.getMessage()));
        }
    
        Council council = Council.get(councilId);
        council.setTitle(title);
        council.update();
        return ok(Json.toJson(council));
    }
  • public Result get(Integer level) {
        Levels levels = Levels.get(level);
        try {
            return ok(Json.toJson(levels));
        } catch (Exception e) {
            return badRequest(ApplicationHelper.getErrorJson(CodeConstants.INVALID_PARAM_ERROR,
                    e.getMessage()));
        }
    }

     

  

 

转载于:https://www.cnblogs.com/jianpanaq/p/7218215.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值