当前位置: 首页>>代码示例>>Java>>正文


Java Db.findFirst方法代码示例

本文整理汇总了Java中com.jfinal.plugin.activerecord.Db.findFirst方法的典型用法代码示例。如果您正苦于以下问题:Java Db.findFirst方法的具体用法?Java Db.findFirst怎么用?Java Db.findFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jfinal.plugin.activerecord.Db的用法示例。


在下文中一共展示了Db.findFirst方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validate

import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
@Override
protected void validate(Controller c) {
	validateRequiredString("user.username", "category_error", "用户名不能为空");
	int userId = 0;

	String email = c.getPara("user.email");
	String username = c.getPara("user.username");
	Integer[] is = c.getParaValuesToInt("user_role");
	int id = 0;
	if (email.length() != 0) {
		validateEmail("user.email", "text_error", "email格式不正确");
	}
	if (is == null) {
		addError("role_error", "必须选择一个角色");
	}
	if (userId == 0) {
		validateRequiredString("user.password", "text_error", "密码不能为空");
		validateEqualField("user.password", "vpassword", "text_error", "密码与确认密码不匹配");
	}

	if (username.length() != 0) {
		Record count = null;
		count = Db
				.findFirst("select count(id) as count from user where username='"
						+ username + "' and id<>" + id);
		if (count.getLong("count") != 0) {
			addError("codeRepeat_error", "已存在此用户");
		}
		;
	}
}
 
开发者ID:yaokwok,项目名称:loveabc,代码行数:32,代码来源:UserFormValidator.java

示例2: CheckCount

import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
/**
 * 判断是否count 是否为0
 * 
 * @param tableName
 * @param whereSql
 * @param Object
 *            ...parameter
 */
protected boolean CheckCount(String tableName, String whereSql,
		Object... parameter) {
	boolean counts = false;
	String sql = "select count(id) as count from " + tableName + " where "
			+ whereSql;
	Record count = Db.findFirst(sql, parameter);
	if (count.getLong("count") == 0) {
		counts = true;
	}
	return counts;
}
 
开发者ID:yaokwok,项目名称:loveabc,代码行数:20,代码来源:BasicController.java

示例3: checkUser

import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
/**
 * 检查用户账号是否被注册*
 */
@ClearInterceptor
public void checkUser() {
    String loginName = getPara("loginName");
    if (StringUtils.isEmpty(loginName)) {
        renderArgumentError("loginName can not be null");
        return;
    }
    //检查手机号码是否被注册
    boolean exists = Db.findFirst("SELECT * FROM t_user WHERE loginName=?", loginName) != null;
    renderJson(new BaseResponse(exists ? Code.SUCCESS:Code.FAIL, exists ? "registered" : "unregistered"));
}
 
开发者ID:kevin09002,项目名称:jfinal-api-scaffold,代码行数:15,代码来源:AccountAPIController.java

示例4: getNews

import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
public static Record getNews(int id){
//修改消息状态为已读
Db.update("update news set status=1 where id="+id);
Record news = Db.findFirst("select p.name as projectName,n.* from project p join news n on p.identifier = n.identifier where n.id="+id);
return news;
}
 
开发者ID:yaokwok,项目名称:loveabc,代码行数:7,代码来源:NewsService.java

示例5: findFirst

import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
public Record findFirst(String sql, Object... params)
{
	return Db.findFirst(asterisk(sql, params), unpack(params));
}
 
开发者ID:glaciall,项目名称:jfinal-dbx,代码行数:5,代码来源:DbEx.java

示例6: sendCode

import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
/**
 * 1. 检查是否被注册*
 * 2. 发送短信验证码*
 */
@ClearInterceptor
public void sendCode() {
    String loginName = getPara("loginName");
    if (StringUtils.isEmpty(loginName)) {
        renderArgumentError("loginName can not be null");
        return;
    }

    //检查手机号码有效性
    if (!SMSUtils.isMobileNo(loginName)) {
        renderArgumentError("mobile number is invalid");
        return;
    }

    //检查手机号码是否被注册
    if (Db.findFirst("SELECT * FROM t_user WHERE loginName=?", loginName) != null) {
        renderJson(new BaseResponse(Code.ACCOUNT_EXISTS,"mobile already registered"));
        return;
    }

    String smsCode = SMSUtils.randomSMSCode(4);
    //发送短信验证码
    if (!SMSUtils.sendCode(loginName, smsCode)) {
        renderFailed("sms send failed");
        return;
    }
    
    //保存验证码数据
    RegisterCode registerCode = new RegisterCode()
            .set(RegisterCode.MOBILE, loginName)
            .set(RegisterCode.CODE, smsCode);

    //保存数据
    if (Db.findFirst("SELECT * FROM t_register_code WHERE mobile=?", loginName) == null) {
        registerCode.save();
    } else {
        registerCode.update();
    }
    
    renderJson(new BaseResponse("sms sended"));
    
}
 
开发者ID:kevin09002,项目名称:jfinal-api-scaffold,代码行数:47,代码来源:AccountAPIController.java

示例7: register

import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
/**
 * 用户注册
 */
   @ClearInterceptor()
public void register(){
	//必填信息
	String loginName = getPara("loginName");//登录帐号
       int code = getParaToInt("code", 0);//手机验证码
       int sex = getParaToInt("sex", 0);//性别
       String password = getPara("password");//密码
	String nickName = getPara("nickName");//昵称
   	//头像信息,为空则使用默认头像地址
   	String avatar = getPara("avatar", AppProperty.me().defaultUserAvatar());

       //校验必填项参数
	if(!notNull(Require.me()
               .put(loginName, "loginName can not be null")
               .put(code, "code can not be null")//根据业务需求决定是否使用此字段
               .put(password, "password can not be null")
               .put(nickName, "nickName can not be null"))){
		return;
	}

       //检查账户是否已被注册
       if (Db.findFirst("SELECT * FROM t_user WHERE loginName=?", loginName) != null) {
           renderJson(new BaseResponse(Code.ACCOUNT_EXISTS, "mobile already registered"));
           return;
       }
       
       //检查验证码是否有效, 如果业务不需要,则无需保存此段代码
       if (Db.findFirst("SELECT * FROM t_register_code WHERE mobile=? AND code = ?", loginName, code) == null) {
           renderJson(new BaseResponse(Code.CODE_ERROR,"code is invalid"));
           return;
       }
       
	//保存用户数据
	String userId = RandomUtils.randomCustomUUID();

	new User()
               .set("userId", userId)
               .set(User.LOGIN_NAME, loginName)
	        .set(User.PASSWORD, StringUtils.encodePassword(password, "md5"))
               .set(User.NICK_NAME, nickName)
	        .set(User.CREATION_DATE, DateUtils.getNowTimeStamp())
	        .set(User.SEX, sex)
               .set(User.AVATAR, avatar)
               .save();
	
       //删除验证码记录
       Db.update("DELETE FROM t_register_code WHERE mobile=? AND code = ?", loginName, code);
       
	//返回数据
	renderJson(new BaseResponse("success"));
}
 
开发者ID:kevin09002,项目名称:jfinal-api-scaffold,代码行数:55,代码来源:AccountAPIController.java

示例8: findOne

import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
/**
 * Query a data record.
 *
 * @param sqlSelect SqlNode Select
 * @return query result.
 * @see SqlSelect
 * @see FindBy
 */
public static Record findOne(SqlSelect sqlSelect) {
    Preconditions.checkNotNull(sqlSelect, "The Query SqlNode is must be not null.");
    return Db.findFirst(sqlSelect.toString(), sqlSelect.getParams().toArray());
}
 
开发者ID:GojaFramework,项目名称:goja,代码行数:13,代码来源:Dao.java


注:本文中的com.jfinal.plugin.activerecord.Db.findFirst方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。