com.jfinal.kit.Kv Java Examples

The following examples show how to use com.jfinal.kit.Kv. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: _JFCodeGenerator.java    From sdb-mall with Apache License 2.0 6 votes vote down vote up
/**
 * 生成Dao
 *
 * @param className 类名称
 * @param tableName 表名
 */
public void dao(String className, String tableName) {
    String packages = toPackages();

    String classNameSmall = toClassNameSmall(className);

    jfEngine.render("/java/dao.html",
            Kv.by("package", packages)
                    .set("className", className)
                    .set("classNameSmall", classNameSmall)
                    .set("tableName", tableName)
            ,
            new StringBuilder()
                    .append(System.getProperty("user.dir"))
                    .append("/")
                    .append(srcFolder)
                    .append("/")
                    .append(packages.replace(".", "/"))
                    .append("/dao/")
                    .append(className)
                    .append("Dao.java")
    );
}
 
Example #2
Source File: _JFCodeGenerator.java    From sdb-mall with Apache License 2.0 6 votes vote down vote up
/**
 * 生成ServiceImpl
 *
 * @param className 类名称
 * @param tableName 表名
 */
public void serviceImpl(String className, String tableName) {
    String packages = toPackages();

    String classNameSmall = toClassNameSmall(className);

    jfEngine.render("/java/serviceImpl.html",
            Kv.by("package", packages)
                    .set("className", className)
                    .set("classNameSmall", classNameSmall)
                    .set("tableName", tableName)
            ,
            new StringBuilder()
                    .append(System.getProperty("user.dir"))
                    .append("/")
                    .append(srcFolder)
                    .append("/")
                    .append(packages.replace(".", "/"))
                    .append("/service/impl/")
                    .append(className)
                    .append("ServiceImpl.java")
    );
}
 
Example #3
Source File: _JFCodeGenerator.java    From sdb-mall with Apache License 2.0 6 votes vote down vote up
/**
 * 生成Service
 *
 * @param className 类名称
 * @param tableName 表名
 */
public void service(String className, String tableName) {
    String packages = toPackages();

    String classNameSmall = toClassNameSmall(className);

    jfEngine.render("/java/service.html",
            Kv.by("package", packages)
                    .set("className", className)
                    .set("classNameSmall", classNameSmall)
                    .set("tableName", tableName)
            ,
            new StringBuilder()
                    .append(System.getProperty("user.dir"))
                    .append("/")
                    .append(srcFolder)
                    .append("/")
                    .append(packages.replace(".", "/"))
                    .append("/service/")
                    .append(className)
                    .append("Service.java")
    );
}
 
Example #4
Source File: _JFCodeGenerator.java    From sdb-mall with Apache License 2.0 6 votes vote down vote up
public TableMeta getTableMeta(String tableName) {
    if (tablemetaMap == null) {

        DataSource dataSource = _JFinalGenerator.getDataSource();

        MetaBuilder metaBuilder = new MetaBuilder(dataSource);
        metaBuilder.setDialect(new MysqlDialect());
        metaBuilder.addExcludedTable(_JFinalGenerator.excludedTable);
        List<TableMeta> tableMetas = metaBuilder.build();
        new DataGenerator(dataSource, null).rebuildColumnMetas(tableMetas);

        if (tableMetas.size() == 0) {
            System.out.println("TableMeta 数量为 0,不生成任何文件");
            return null;
        }
        Kv kv = Kv.create();
        for (TableMeta tableMeta : tableMetas) {
            kv.set(tableMeta.name, tableMeta);
        }
        tablemetaMap = kv;
    }
    return (TableMeta) tablemetaMap.get(tableName);
}
 
Example #5
Source File: ServiceProviderGenerator.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void genBaseModelContent(TableMeta tableMeta) {
    Kv data = Kv.by("serviceImplPackageName", baseModelPackageName);
    data.set("generateChainSetter", generateChainSetter);
    data.set("tableMeta", tableMeta);
    data.set("basePackage", basePackage);
    data.set("modelPackage", modelPackage);

    Engine engine = Engine.use("forServiceImpl");
    tableMeta.baseModelContent = engine.getTemplate(template).renderToString(data);
}
 
Example #6
Source File: AppJbootServiceImplGenerator.java    From jboot-admin with Apache License 2.0 5 votes vote down vote up
@Override
protected void genBaseModelContent(TableMeta tableMeta) {
    Kv data = Kv.by("serviceImplPackageName", baseModelPackageName);
    data.set("generateChainSetter", generateChainSetter);
    data.set("tableMeta", tableMeta);
    data.set("basePackage", servicePackage);
    data.set("modelPackage", modelPacket);

    Engine engine = Engine.use("forServiceImpl");
    tableMeta.baseModelContent = engine.getTemplate(template).renderToString(data);
}
 
Example #7
Source File: ModuleUIGenerator.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ModuleUIGenerator(String moduleName, String modelPackage, List<TableMeta> tableMetaList) {

        this.tableMetaList = tableMetaList;
        this.moduleName = moduleName;
        this.modelPackage = modelPackage;
        modulePackage = modelPackage.substring(0, modelPackage.lastIndexOf("."));

        basePath = PathKit.getWebRootPath() + "/../module-" + moduleName;
        webPath = basePath + "/module-" + moduleName + "-web";

        String upcasedModuleName = StrKit.firstCharToUpperCase(moduleName);

        String moduleListenerPakcage = modelPackage.substring(0, modelPackage.lastIndexOf("."));
        String controllerPackage = modelPackage.substring(0, modelPackage.lastIndexOf(".")) + ".controller";


        moduleListenerOutputDir = webPath + "/src/main/java/" + moduleListenerPakcage.replace(".", "/");
        controllerOutputDir = webPath + "/src/main/java/" + controllerPackage.replace(".", "/");
        htmlOutputDir = webPath + "/src/main/webapp/WEB-INF/views/admin/" + moduleName;

        data = Kv.by("moduleName", moduleName);//product
        data.set("upcasedModuleName", upcasedModuleName);//Product
        data.set("modulePackage", modulePackage);//io.jpress.module.product
        data.set("modelPackage", modelPackage);//io.jpress.module.product.model
        data.set("moduleListenerPakcage", moduleListenerPakcage);//io.jpress.module.product
        data.set("controllerPackage", controllerPackage);//io.jpress.module.product.controller

        engine.setSourceFactory(new ClassPathSourceFactory());
        engine.addSharedMethod(new StrKit());

    }
 
Example #8
Source File: ServiceApiGenerator.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void genBaseModelContent(TableMeta tableMeta) {
    Kv data = Kv.by("baseModelPackageName", baseModelPackageName);
    data.set("generateChainSetter", generateChainSetter);
    data.set("tableMeta", tableMeta);
    data.set("modelPacket", modelPacket);
    data.set("basePackage", basePackage);

    Engine engine = Engine.use("forService");
    tableMeta.baseModelContent = engine.getTemplate(template).renderToString(data);
}
 
Example #9
Source File: AddonUIGenerator.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public AddonUIGenerator(String basePath, String moduleName, String modelPackage, List<TableMeta> tableMetaList) {

        this.basePath = basePath;

        this.tableMetaList = tableMetaList;
        this.moduleName = moduleName;
        this.modelPackage = modelPackage;
        this.modulePackage = modelPackage.substring(0, modelPackage.lastIndexOf("."));

        modulePackage = modelPackage.substring(0, modelPackage.lastIndexOf("."));

        String moduleListenerPakcage = modelPackage.substring(0, modelPackage.lastIndexOf("."));
        String controllerPackage = modelPackage.substring(0, modelPackage.lastIndexOf(".")) + ".controller";


        controllerOutputDir = basePath + "/src/main/java/" + controllerPackage.replace(".", "/");
        htmlOutputDir = basePath + "/src/main/webapp/views/";

        data = Kv.by("moduleName", moduleName);//product
        data.set("upcasedModuleName", StrKit.firstCharToUpperCase(moduleName));//Product
        data.set("modulePackage", modulePackage);//io.jpress.module.product
        data.set("modelPackage", modelPackage);//io.jpress.module.product.model
        data.set("moduleListenerPakcage", moduleListenerPakcage);//io.jpress.module.product
        data.set("controllerPackage", controllerPackage);//io.jpress.module.product.controller

        engine.setSourceFactory(new ClassPathSourceFactory());
        engine.addSharedMethod(new StrKit());

    }
 
Example #10
Source File: JbootServiceInterfaceGenerator.java    From jboot with Apache License 2.0 5 votes vote down vote up
@Override
protected void genBaseModelContent(TableMeta tableMeta) {
    Kv data = Kv.by("baseModelPackageName", baseModelPackageName);
    data.set("generateChainSetter", generateChainSetter);
    data.set("tableMeta", tableMeta);
    data.set("modelPacket", modelPacket);
    data.set("basePackage", basePackage);

    Engine engine = Engine.use("forService");
    tableMeta.baseModelContent = engine.getTemplate(template).renderToString(data);
}
 
Example #11
Source File: JbootServiceImplGenerator.java    From jboot with Apache License 2.0 5 votes vote down vote up
protected void genBaseModelContent(TableMeta tableMeta) {
        Kv data = Kv.by("serviceImplPackageName", basePackage + "." + implName);
//        data.set("generateChainSetter", generateChainSetter);
        data.set("tableMeta", tableMeta);
        data.set("basePackage", basePackage);
        data.set("modelPackage", modelPackage);
        data.set("implName", implName);

        Engine engine = Engine.use("forServiceImpl");
        tableMeta.baseModelContent = engine.getTemplate(template).renderToString(data);
    }
 
Example #12
Source File: WechatApis.java    From jboot with Apache License 2.0 5 votes vote down vote up
/**
 * 网页授权获取用户信息,必须是最新的token,才能获得完整的用户资料
 *
 * @param token
 * @param openId
 * @return
 */
public static ApiResult getUserInfo(String token, String openId) {
    Kv pm = Kv.by("access_token", token).set("openid", openId).set("lang", "zh_CN");
    String jsonResult = HttpUtil.httpGet("https://api.weixin.qq.com/sns/userinfo", pm);

    if (jsonResult == null)
        return null;

    return new ApiResult(jsonResult);
}
 
Example #13
Source File: SysUserDaoTest.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    List<Filter> filterList = new ArrayList<>();
    Filter filter = new Filter();
    filter.setProperty("aaa");
    filter.setOperator(Filter.Operator.eq);
    filter.setValue("123");
    filterList.add(filter);

    filter = new Filter();
    filter.setProperty(null);
    filter.setOperator(Filter.Operator.eq);
    filter.setValue("111");
    filterList.add(filter);

    filter = new Filter();
    filter.setProperty("bbb");
    filter.setOperator(Filter.Operator.eq);
    filter.setValue("321");
    filterList.add(filter);

    filter = new Filter();
    filter.setProperty("intest");
    filter.setOperator(Filter.Operator.in);
    filter.setValue(new ArrayList<String>() {
        {add("aaa");add("bbb");}
    });
    filterList.add(filter);
    SqlPara sqlPara = Db.getSqlPara("common.findList", Kv.by("tableName", "aaa").set("filters", filterList));
    List<Record> record = Db.find(sqlPara);
    log.info("{}", record);
}
 
Example #14
Source File: _JFCodeGenerator.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
public void htmlList(String className, TableMeta tablemeta) {
    String packages = toPackages();
    String classNameSmall = toClassNameSmall(className);
    String basePathUrl = basePath.replace('.', '/');

    Map<String, String> columnMap = new HashMap<>();

    for (ColumnMeta columnMeta :tablemeta.columnMetas
         ) {

        String desc = StringUtils.substringBetween(columnMeta.remarks, "[", "]");
        columnMap.put(columnMeta.attrName, desc);
    }

    String primaryKey = StrKit.toCamelCase(tablemeta.primaryKey);

    jfEngine.render("/html/index.vue",
            Kv.by("tablemeta", tablemeta)
                    .set("package", packages)
                    .set("className", className)
                    .set("columnMap", columnMap)
                    .set("primaryKey", primaryKey)
                    .set("classNameSmall", classNameSmall)
                    .set("basePath", basePathUrl)
            ,
            new StringBuilder()
                    .append(viewFolder)
                    .append("/")
                    .append(classNameSmall)
                    .append("List.html")
    );
}
 
Example #15
Source File: _JFCodeGenerator.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
/**
 * 生成Controller
 *
 * @param className 类名称
 */
public void controller(String className) {
    for (String excluded:excludedControllerClass
         ) {
        if (excluded.equalsIgnoreCase(className)) {
            return;
        }
    }

    String packages = toPackages();

    String classNameSmall = toClassNameSmall(className);

    String controllerPathName = "/controller/";
    if (!StringUtils.startsWith(className.toLowerCase(), "sys")) {
        controllerPathName = "/controller/Sys";
    }

    jfEngine.render("/java/controller.html",
            Kv.by("package", packages)
                    .set("className", className)
                    .set("classNameSmall", classNameSmall)
                    .set("basePath", basePath)
            ,
            new StringBuilder()
                    .append(System.getProperty("user.dir"))
                    .append("/")
                    .append(srcFolder)
                    .append("/")
                    .append(packages.replace(".", "/"))
                    .append(controllerPathName)
                    .append(className)
                    .append("Controller.java")
    );
}
 
Example #16
Source File: CartServiceImpl.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
@Override
public List<CartDTO> listDetail(String userId) {
    SqlPara sqlPara =  Db.getSqlPara("cart.listDetail", Kv.by("userId", userId));
    List<Record> recordList = Db.find(sqlPara);
    List<CartDTO> cartDTOList = RecordUtils.converModel(recordList, CartDTO.class);
    return cartDTOList;
}
 
Example #17
Source File: ProductServiceImpl.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
@Override
public List<ProductDTO> listDetailByProductIds(String productIds) {
    String[] productIdArr = productIds.split(",");
    SqlPara sqlPara = Db.getSqlPara("product.listDetailByProductIds", Kv.by("productIds", productIdArr));
    List<Record> recordList = Db.find(sqlPara);
    List<ProductDTO> productDTOList = RecordUtils.converModel(recordList, ProductDTO.class);

    return productDTOList;
}
 
Example #18
Source File: FavoriteGoodsServiceImpl.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
@Override
public List<FavoriteGoodsDTO> list(String userId) {
    SqlPara sqlPara =  Db.getSqlPara("favoriteGoods.list", Kv.by("userId", userId));
    List<Record> recordList = Db.find(sqlPara);
    List<FavoriteGoodsDTO> favoriteGoodsDTOList = RecordUtils.converModel(recordList, FavoriteGoodsDTO.class);
    return favoriteGoodsDTOList;
}
 
Example #19
Source File: SysConfigServiceImpl.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
@Override
@JFinalTx
public void updateValueByKey(String key, String value) {
	SqlPara sqlPara = Db.getSqlPara("sysConfig.updateValueByKey", Kv.by("paramValue", value).set("paramKey", key));
	Db.update(sqlPara);
	sysConfigRedis.delete(key);
}
 
Example #20
Source File: BaseDao.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
public boolean deleteBatch(String[] columns, Object[]... ids) {
	String[] primaryKeys = columns;
	if (columns == null) {
		primaryKeys = this.getPrimaryKeys();
	}

	SqlPara sqlPara = Db.getSqlPara("common.deleteBatch", Kv.by("ids", ids).set("primaryKeys", primaryKeys).set("tableName", this.getTableName()));
	return Db.update(sqlPara) > 0;
}
 
Example #21
Source File: SysUserDao.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
public List<Long> queryAllMenuId(Long userId) {
    SqlPara sqlPara = Db.getSqlPara("sysUser.queryAllMenuId", Kv.by("userId", userId));
    List<Record> sysMenuList = Db.find(sqlPara);
    List<Long> menuIds = new ArrayList<>();
    for (Record r:sysMenuList
         ) {
        if(r == null || r.get("menu_id") == null) {
            continue;
        }
        menuIds.add(r.get("menu_id"));
    }

    return menuIds;
}
 
Example #22
Source File: SysUserDao.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
public List<String> queryAllPerms(Long userId) {
    SqlPara sqlPara = Db.getSqlPara("sysUser.queryAllPerms", Kv.by("userId", userId));
    List<Record> sysUserList = Db.find(sqlPara);
    List<String> perms = new ArrayList<>();
    for (Record r:sysUserList
         ) {
        if(r == null || r.get("perms") == null) {
            continue;
        }
        perms.add(r.get("perms"));
    }

    return perms;
}
 
Example #23
Source File: OrderMasterServiceImpl.java    From sdb-mall with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean updateByGrouponId(String grouponId,Integer status) {
    SqlPara sqlPara = Db.getSqlPara("order.updateByGrouponId", Kv.by("orderStatus", status).set("grouponId", grouponId));
    return Db.update(sqlPara) > 0;
}
 
Example #24
Source File: _JFCodeGenerator.java    From sdb-mall with Apache License 2.0 4 votes vote down vote up
public void vue(String className, TableMeta tablemeta) {
    boolean includeFlag = false;
    for (String includeClass:includedVueClass
            ) {
        if (includeClass.equalsIgnoreCase(className)) {
            includeFlag = true;
            break;
        }
    }

    if (!includeFlag) {
        return;
    }

    String packages = toPackages();
    String classNameSmall = toClassNameSmall(className);
    String basePathUrl = basePath.replace('.', '/');

    Map<String, String> columnMap = new HashMap<>();

    for (ColumnMeta columnMeta :tablemeta.columnMetas
         ) {

        String desc = StringUtils.substringBetween(columnMeta.remarks, "[", "]");
        columnMap.put(columnMeta.attrName, desc);
    }

    String primaryKey = StrKit.toCamelCase(tablemeta.primaryKey);

    jfEngine.render("/html/index.html",
            Kv.by("tablemeta", tablemeta)
                    .set("package", packages)
                    .set("className", className)
                    .set("columnMap", columnMap)
                    .set("primaryKey", primaryKey)
                    .set("classNameSmall", classNameSmall)
                    .set("basePath", basePathUrl)
            ,
            new StringBuilder()
                    .append(viewFolder)
                    .append("/")
                    .append(classNameSmall)
                    .append(".vue")
    );
}
 
Example #25
Source File: _JFCodeGenerator.java    From sdb-mall with Apache License 2.0 4 votes vote down vote up
public void vueAddUpdate(String className, TableMeta tablemeta) {
    boolean includeFlag = false;
    for (String includeClass:includedVueClass
            ) {
        if (includeClass.equalsIgnoreCase(className)) {
            includeFlag = true;
            break;
        }
    }

    if (!includeFlag) {
        return;
    }

    String packages = toPackages();
    String classNameSmall = toClassNameSmall(className);
    String basePathUrl = basePath.replace('.', '/');

    Map<String, String> columnMap = new HashMap<>();

    for (ColumnMeta columnMeta :tablemeta.columnMetas
         ) {

        String desc = StringUtils.substringBetween(columnMeta.remarks, "[", "]");
        columnMap.put(columnMeta.attrName, desc);
    }

    String primaryKey = StrKit.toCamelCase(tablemeta.primaryKey);

    jfEngine.render("/html/add-or-update.html",
            Kv.by("tablemeta", tablemeta)
                    .set("package", packages)
                    .set("className", className)
                    .set("columnMap", columnMap)
                    .set("primaryKey", primaryKey)
                    .set("classNameSmall", classNameSmall)
                    .set("basePath", basePathUrl)
            ,
            new StringBuilder()
                    .append(viewFolder)
                    .append("/")
                    .append(classNameSmall)
                    .append("-add-or-update")
                    .append(".vue")
    );
}
 
Example #26
Source File: BaseDao.java    From sdb-mall with Apache License 2.0 4 votes vote down vote up
public Page<M> paginate(Integer pageNum, Integer pageSize, List<Filter> filters, List<Order> orders) {
	SqlPara sqlPara = Db.getSqlPara("common.findList", Kv.by("filters", filters).set("orders", orders).set("tableName", this.getTableName()));
	Page<M> pr = this.modelManager.paginate(pageNum, pageSize, sqlPara);
	return pr;
}
 
Example #27
Source File: BaseDao.java    From sdb-mall with Apache License 2.0 4 votes vote down vote up
public boolean deleteByModel(M model){
	Record record = model.toRecord();
	SqlPara sqlPara = Db.getSqlPara("common.deleteByModel", Kv.by("record", record.getColumns()).set("tableName", this.getTableName()));
	return Db.update(sqlPara) > 0;
}
 
Example #28
Source File: BaseDao.java    From sdb-mall with Apache License 2.0 4 votes vote down vote up
public List<M> findByFilters(List<Filter> filters){
	SqlPara sqlPara = Db.getSqlPara("common.findList", Kv.by("filters", filters).set("tableName", this.getTableName()));
	List<M> modelList = this.modelManager.find(sqlPara);
	return modelList;
}
 
Example #29
Source File: BaseDao.java    From sdb-mall with Apache License 2.0 4 votes vote down vote up
public List<M> findByModel(M model){
	Record record = model.toRecord();
	SqlPara sqlPara = Db.getSqlPara("common.findByModel", Kv.by("record", record.getColumns()).set("tableName", this.getTableName()));
	return this.modelManager.find(sqlPara);
}
 
Example #30
Source File: BaseDao.java    From sdb-mall with Apache License 2.0 4 votes vote down vote up
public M findFirstByModel(M model){
	Record record = model.toRecord();
	SqlPara sqlPara = Db.getSqlPara("common.findByModel", Kv.by("record", record.getColumns()).set("tableName", this.getTableName()));
	return this.modelManager.findFirst(sqlPara);
}