Aooms 极速微服务开发,像 JFinal 一样简单 1.0.0-alpha

栏目: Java · 发布时间: 5年前

内容简介:一款基于SpringCloud的微服务基础开发平台,旨在降低SpringCloud的复杂度,像使用JFinal一样简单(本人是JFinal用户,从1.9版本开始现在也一直在使用,因此部分实现思路会借鉴JFinal的一些模式,感谢@JFinal作者波总提供这么优秀的框架),包含微服务相关的完整解决方案同时附加有权限管理、报表自定义、工作流、Cms等套件,可直接使用,Aooms基于Apache Licence 2.0开源协议,关于编写此框架的一些初衷,可通过此处[(1)极简Controller(2)基于sha

Aooms 极速微服务开发,像JFinal一样简单

一、Aooms

一款基于SpringCloud的微服务基础开发平台,旨在降低SpringCloud的复杂度,像使用JFinal一样简单(本人是JFinal用户,从1.9版本开始现在也一直在使用,因此部分实现思路会借鉴JFinal的一些模式,感谢@JFinal作者波总提供这么优秀的框架),包含微服务相关的完整解决方案同时附加有权限管理、报表自定义、工作流、Cms等套件,可直接使用,Aooms基于Apache Licence 2.0开源协议,关于编写此框架的一些初衷,可通过此处[ 诞生 ]了解。

二、1.0.0-alpha版功能

(1)极简Controller

(2)基于sharding-sphere的多数据源支持

(3)基于Mybatis 实现的 Db + Record 极简模式,附带物理分页实现

(4)基于Consul的服务注册、发现

(5)服务熔断、限流

(6)服务客户端、http客户端

(7)内置各种ID生成器(UUID、snowflake)

(8)穿透一切的数据对象DataBoss

(9)基于J2Cache的缓存

(10) 其他更多功能,等你发现.......

三、简单Demo

(1)一睹helloworld

package net.aooms.example.controller;

import net.aooms.core.web.AoomsAbstractController;
import net.aooms.example.vo.UserVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

/**
 * HelloWorld
 * Created by 风象南(cheereebo) on 2018-09-12
 */
@RestController
public class HelloWorldController extends AoomsAbstractController {

    /**
     * 基础访问
     */
    @RequestMapping("/hello")
    public void hello(){
        String str = "hello world !";
        this.renderText(str);
    };

    /**
     * 获取基本参数
     */
    @RequestMapping("/hello2")
    public void hello2(){
        String id = getParaString("id");
        logger.info("id = {}" , id);
        this.renderText(id);
    };


    /**
     * 获取路径参数
     */
    @RequestMapping("/hello/{id}")
    public void hello3(){
        String id = getPathString("id");
        logger.info("id = {}" , id);
        this.renderText(id);
    };

    /**
     * 上传文件
     */
    @RequestMapping("/hello4")
    public void hello4(){
        MultipartFile multipartFile = this.getParaFile("upload");
        logger.info("fileName = {}", multipartFile.getName());
        this.renderText("success");
    };

    /**
     * json输出
     */
    @RequestMapping("/hello5")
    public void hello5(){
        UserVo userVo = new UserVo();
        userVo.setName("zhangsan");
        setResultValue("userVo",userVo);

        // 输出json
        this.renderJson();
        // this.renderJson(); 也可省略不写,默认会使用JSONRender
    };

    /**
     * json输出
     */
    @RequestMapping("/hello6")
    public void hello6(){
        UserVo userVo = new UserVo();
        userVo.setName("zhangsan");
        this.renderJson(userVo);
    };

    /**
     * 文件下载
     */
    @RequestMapping("/hello7")
    public void hello7(){
        this.renderFile("application.yml", this.getClass().getResourceAsStream("/application.yml"));
    };

    /**
     * 图片输出
     * @return
     */
    @RequestMapping("/hello8")
    public void hello8(){
        this.renderImage("F:/1.png","F:/default.png");
    };

    /**
     * html输出
     * @return
     */
    @RequestMapping("/hello9")
    public void hello9(){
        this.renderHtml("<html><h1>标题</h1> <script>alert('hello world !');</script> </html>");
    };

    /**
     * 模版页面输出
     * @return
     */
    @RequestMapping("/hello10")
    public void hello10(){
        ModelAndView mv = new ModelAndView();
        mv.addObject("name","lisi");
        mv.setViewName("/demo.html");
        this.renderThymeleaf(mv);
    };

    /**
     * 重定向
     * @return
     */
    @GetMapping("/hello11")
    public void hello11(){
        this.redirect("https://www.oschina.net");
    };

}

(2)一个简单的CRUD

package net.aooms.example.controller;

import net.aooms.core.web.AoomsAbstractController;
import net.aooms.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * simple crud
 * Created by 风象南(cheereebo) on 2018-09-12
 */
@RestController
public class CRUDController extends AoomsAbstractController {

    @Autowired
    private UserService userService;

    /**
     * 查询
     * @return
     */
    @RequestMapping("/findList")
    public void findList(){
        userService.findList();
    };

    /**
     * 新增
     * @return
     */
    @RequestMapping("/insert")
    public void insert(){
        userService.insert();
    };

    /**
     * 修改
     * @return
     */
    @RequestMapping("/update")
    public void update(){
        userService.update();
    };

    /**
     * 删除
     * @return
     */
    @RequestMapping("/delete")
    public void delete(){
        userService.delete();
    };


}
package net.aooms.example.service;

import net.aooms.core.AoomsConstants;
import net.aooms.core.id.IDGenerator;
import net.aooms.core.module.mybatis.Db;
import net.aooms.core.module.mybatis.SqlPara;
import net.aooms.core.module.mybatis.record.PagingRecord;
import net.aooms.core.module.mybatis.record.Record;
import net.aooms.core.service.GenericService;
import net.aooms.example.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * simple crud service
 * Created by 风象南(cheereebo) on 2018-09-17
 */
@Service
public class UserService extends GenericService {

    @Autowired
    private Db db;

    public void findList() {
        PagingRecord pagingRecord = db.findList("UserMapper.findList", SqlPara.fromDataBoss());

        {
            // 返回值
            this.setResultValue(AoomsConstants.Result.DATA,pagingRecord);
        }
    }

    @Transactional
    public void insert() {

        // record 模式
        Record record1 = Record.NEW();
        record1.set(AoomsConstants.ID,IDGenerator.getLongValue());
        record1.set("name","lisi3");
        db.insert("user",record1);

        UserVo userVo = new UserVo();
        userVo.setId(IDGenerator.getLongValue());
        userVo.setName("wangwu");
        Record record2 = Record.NEW().fromBean(userVo);
        // fromDataBoss(prefix) 该方法可将参数 满足model.xxx 规则的参数构造成record属性
        // 例:http://xxx/insert?record.id=1&record.name=zhangsan&model.role=3&code=02,
        // 通过 fromDataBoss 将提取id,name,role三个属性的值,不会提取code值
        record2.fromDataBoss("model");  // model为参数prefix 格式:model.role , 将会通过model取到role值

        db.insert("user",record2);
    }

    @Transactional
    public void update() {
        // record 模式
        Record record = db.findByPrimaryKey("user","root");
        if(record != null){
    	    record.set("name","zhaoliu");
	    db.update("user",record);
       	}
    }

    @Transactional
    public void delete() {
        db.deleteByPrimaryKey("user","root1");
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="UserMapper">

    <!-- 二级缓存 -->
    <cache type="net.aooms.core.module.mybatis.J2CacheSupport" eviction="LRU" flushInterval="60000" size="512" readOnly="true"/>

    <sql id="columns">
         id,name
    </sql>

    <select id="findList" resultType="net.aooms.core.module.mybatis.record.Record">
        SELECT <include refid="columns" /> FROM USER
    </select>

    <select id="updateById" resultType="int">
        update user set name = '123' where id = #{id}
    </select>

    <select id="findAll" resultType="net.aooms.core.module.mybatis.record.Record">
        select * from t_order
    </select>

</mapper>

四、更多功能特性

请查看 https://gitee.com/cyb-javaer/Aooms -> aooms-example-quickstart


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

首席产品官2 从白领到金领

首席产品官2 从白领到金领

车马 / 机械工业出版社 / 79元

《首席产品官》共2册,旨在为产品新人成长为产品行家,产品白领成长为产品金领,最后成长为首席产品官(CPO)提供产品认知、能力体系、成长方法三个维度的全方位指导。 作者在互联网领域从业近20年,是中国早期的互联网产品经理,曾是周鸿祎旗下“3721”的产品经理,担任CPO和CEO多年。作者将自己多年来的产品经验体系化,锤炼出了“产品人的能力杠铃模型”(简称“杠铃模型”),简洁、直观、兼容性好、实......一起来看看 《首席产品官2 从白领到金领》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具