zoukankan      html  css  js  c++  java
  • 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()));
          }
      }

      

    Ride the wave as long as it will take you.
  • 相关阅读:
    时间差的计算
    时间差的计算第二篇
    并不能完全不编码完成Windows Service的安装和卸载
    今年是搜索引擎年吗?热!搜索引擎算法点击率火爆
    Virtual PC,我真的不敢用你!
    我理解的17种C#写的Hello World程序
    反搜索引擎
    如何保证Windows Serverice健壮长效运转?
    服务器是怎么做成的?
    超酷的超级DataGrid
  • 原文地址:https://www.cnblogs.com/jianpanaq/p/7218215.html
Copyright © 2011-2022 走看看