本文整理汇总了Java中com.jfinal.plugin.activerecord.Db.update方法的典型用法代码示例。如果您正苦于以下问题:Java Db.update方法的具体用法?Java Db.update怎么用?Java Db.update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jfinal.plugin.activerecord.Db
的用法示例。
在下文中一共展示了Db.update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteByIds
import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
/**
* 根据多个数据通过主键批量删除数据
*
* @param ids 要删除的数据值数组
* @param modelClass 对应的Model的Class
* @return 是否删除成功
*/
public static <M extends Model> boolean deleteByIds(Serializable[] ids, Class<M> modelClass) {
final Table table = TableMapping.me().getTable(modelClass);
final String[] primaryKey = table.getPrimaryKey();
if (primaryKey == null || primaryKey.length < 1 || ids == null) {
throw new IllegalArgumentException("需要删除的表数据主键不存在,无法删除!");
}
// 暂时支持单主键的,多主键的后续在说吧。
final String question_mark =
StringUtils.repeat(StringPool.QUESTION_MARK, StringPool.COMMA, ids.length);
String deleteSql = "DELETE FROM "
+ table.getName()
+ " WHERE "
+ primaryKey[0]
+ " IN ("
+ question_mark
+ ")";
return Db.update(deleteSql, ids) >= 0;
}
示例2: save
import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
public void save(JSONObject json,String ip)
{
if(json==null) throw new NullParamException();
if(json.getString("start").equals("-1")){
json.put("start", ip);
json.put("end", ip);
}
Db.update("insert into ip(start,end,nation,province,city) values(inet_aton(?),inet_aton(?),?,?,?) ", json.getString("start"),
json.getString("end"), json.getString("country"), json.getString("province"),json.getString("city"));
}
示例3: saveOrUpdate
import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
public void saveOrUpdate(String fromUserId,String toUserId,String state){
Db.update(String.format("delete from wx_contact where fromUserId='%1$s' and toUserId='%2$s'",fromUserId,toUserId));
if(state.equals("1")){
Contact model=new Contact();
model.set("fromUserId", fromUserId);
model.set("toUserId", toUserId);
model.set("createTime", new Date().getTime());
model.save();
}
}
示例4: update
import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
public UpdateRecordResponse update() {
UpdateRecordResponse updateRecordResponse = new UpdateRecordResponse();
Integer userId = AdminTokenThreadLocal.getUserId();
Db.update("update user set header=?,email=?,userName=? where userId=?", getPara("header"), getPara("email"), getPara("userName"), userId);
getRequest().setAttribute("user", User.dao.findById(userId));
updateRecordResponse.setMessage(I18NUtil.getStringFromRes("updatePersonInfoSuccess", getRequest()));
return updateRecordResponse;
}
示例5: updateByKV
import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
public boolean updateByKV(String name, String value) {
if (Db.queryInt("select siteId from website where name=?", name) != null) {
Db.update("update website set value=? where name=?", value, name);
} else {
Db.update("insert website(`value`,`name`) value(?,?)", value, name);
}
return true;
}
示例6: generateDB
import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
/**
* 生成db数据库文件
* <p>
* 默认模板路径: gen/db/4mysqldb.btl
*
* @param model
* @param templatePath 代码生成的模板路径
* @param dbName 需要创建表的数据库名
*/
public void generateDB(DbModel model, String templatePath, String dbName) {
if ( model == null || model.getId() == null )
throw new GenerateException("Oop~ model is null.");
if ( StrKit.isBlank(templatePath) ) templatePath = MAVEN_BASE + "gen/db/4mysqldb.btl";
Object id = model.getId();
List<DbModelItem> columns = DbModelItem.dao.find("select * from w_db_model_item where w_model_id = ? order by serial", id);
List<DbModelMapping> slaves = DbModelMapping.dao.find("select * from w_db_model_mapping where master_id = ?", id);
// List<Record> master = Db.find("select t1.*, b.length, b.type from (select * from w_db_model_mapping where slaves_id = ?) t1, w_db_model_item b where b.w_model_id = t1.master_id and b.`name` = t1.mapping_foreign_key", id);
// 修改数据结构,现在所有的关系,均使用中间表来表示
// 当且仅当相关从表中含有ManyToMany关系时生成中间表
// List<DbModelMapping> mapping = new ArrayList<>();
// for(DbModelMapping mm : slaves) {
// if(mm.getMappingSchema().equals("ManyToMany")) {
// mapping.add(mm);
// }
// }
// 当且仅当相关主表中含有oneToMany关系时需要生成外键
// List<Record> foreign = new ArrayList<>();
// for(Record mm : master) {
// if(mm.getStr("mapping_schema").equals("oneToMany")) {
// foreign.add(mm);
// }
// }
Generate generate = Generate.dao.findFirst("select * from w_generate where w_model_id = ?", id);
Map<String, Object> paras = new HashMap<>();
paras.put("db", dbName);
paras.put("model", model);
paras.put("columns", columns);
paras.put("mapping", slaves);
// 添加生成信息
paras.put("generate", generate);
// paras.put("foreign", foreign);
Template template = gt.getTemplate(templatePath);
template.binding(paras);
String[] sqls = template.render().split(";");
try {
for ( String sql : sqls ) {
if ( StrKit.isBlank(sql) ) continue;
Db.update(sql);
}
} finally {
// 返回walle的数据库
Db.update("USE `" + generateDbName + "`");
}
System.out.println("############generateDB success############");
}
示例7: updateJoinCount
import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
public boolean updateJoinCount(String id) {
String sql = "UPDATE t_resource SET \"joinCount\" = \"joinCount\" + 1 WHERE \"id\" = ?";
return Db.update(sql, id) > 0;
}
示例8: updateProfit
import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
public boolean updateProfit(Integer reward) {
String sql = "UPDATE t_user SET profit = profit + ? WHERE id = ?";
return Db.update(sql, reward, super.get("id")) > 0;
}
示例9: 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;
}
示例10: update
import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
public int update(String sql, Object... params)
{
return Db.update(asterisk(sql, params), unpack(params));
}
示例11: 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"));
}
示例12: changeStatus
import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
public Integer changeStatus(Integer id, String tenantId) {
String sql = "update wx_event_config set status=(status+1)%2 where id = ? and tenant_id = ?";
return Db.update(sql, id, tenantId);
}
示例13: deleteByNewsId
import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
public int deleteByNewsId(Integer newsId) {
String sql = "delete from wc_news_article where news_id = ?";
return Db.update(sql, newsId);
}
示例14: delete
import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
public Integer delete(String tenantId, String mediaId) {
String sql = "delete from wc_wc_media where tenant_id = ? and media_id = ?";
return Db.update(sql, tenantId, mediaId);
}
示例15: updatePassword
import com.jfinal.plugin.activerecord.Db; //导入方法依赖的package包/类
public boolean updatePassword(int userId, String password) {
return Db.update("update user set password=? where userId=?", password, userId) > 0;
}