猿问

用户不输入时返回默认值

当用户不输入字段 var 时返回默认值(notes ='this will be default')


qapi := `

UPDATE custom_param SET param_value = $1, start_date = $2, end_date = $3, status = $4 `enter code here` WHERE param_name = 'default-password'

RETURNING param_value, start_date, end_date, status, notes; 

`

// insrt into master_param

sqlError := tx.QueryRowContext(ctx, qapi, request.Value, request.StartDate, request.EndDate, request.Status, request.Notes).Scan(

    &value,

    &startDate,

    &endDate,

    &status,

    &notes,

)

queryInsertNotes := `insert `

if request.Notes != "" {

    notes = request.Notes

}


if sqlError != nil {

    log.Println("SQL Error on ReadApplication on UpdateScheduleMaintenance", sqlError)

    tx.Rollback()

    return schedule, sqlError

}


err = tx.Commit()

if err != nil {

    tx.Rollback()

    return schedule, err

}

当用户不输入任何注释时返回默认注释


浮云间
浏览 111回答 1
1回答

叮当猫咪

我认为你需要这样的东西,没有测试过代码,但你明白了。notes := "this will be default"if request.Notes != "" {    notes = request.Notes}qapi := `UPDATE custom_param SET param_value = $1, start_date = $2, end_date = $3, status = $4, notes = $4 WHERE param_name = 'default-password'RETURNING param_value, start_date, end_date, status, notes; `// insrt into master_paramsqlError := tx.QueryRowContext(ctx, qapi, request.Value, request.StartDate, request.EndDate, request.Status, notes).Scan(    &value,    &startDate,    &endDate,    &status,    &notes,)if sqlError != nil {    log.Println("SQL Error on ReadApplication on UpdateScheduleMaintenance", sqlError)    tx.Rollback()    return schedule, sqlError}err = tx.Commit()if err != nil {    tx.Rollback()    return schedule, err}
随时随地看视频慕课网APP

相关分类

Go
我要回答