rails 格式化时间
time. strftime ( "%Y-%m-%d %H:%M:%S" )
rails rescue可以单独使用
def show
sys_log = SysLog . find ( params[ :id ] )
render json: { status: '0' , data: { log_content: sys_log. log_content} }
rescue
render json: { status: '1' , error: '查询日志出错' , errors: syslog. errors }
end
rails joins嵌套
. joins ( :base_audit_project = > [ :base_audit_object ] )
rails 自定义数据库查询方法
在model中:
scope :select_problem_name , - > ( problem_name) { where ( "problem_name like '%#{ problem_name} %'" ) }
然后可以在控制器中:
problems = BaseAuditProjectProblem . select_problem_name ( params[ :problem_name ] )
rails 字符串转常量
d. accessory_type. constantize. find_by ( id: d. accessory_id)
d数据库查询到的记录
accessory_type常量字符串
constantize转常量方法
后面的find_by就是常量本身拥有的方法
rails 迁移文件创建外键
create_table :base_important_policy_contents do | t|
t. references :base_accessory , index: true
t. text :content
t. timestamps
end
rails 中批量删除
BasePrepareInfo . destroy ( params[ :important_policy_ids ] )
pg数据库空值处理
COALESCE ( bp. audit_problem_amount, 0 )
pg行号获取
row_number( ) over ( partition by base_audit_object_id order by serve_starttime desc )
pg数据库自定义函数
函数 返回类型 描述
currval( regclass) bigint 返回最近一次用 nextval 获取的指定序列的数值
nextval( regclass) bigint 递增序列并返回新值
setval( regclass, bigint ) bigint 设置序列的当前数值
setval( regclass, bigint , boolean ) bigint 设置序列的当前数值以及 is_called 标志
SELECT
setval(
'"t_student_Id_seq"' :: regclass,
100
) ;
pg数据库自定义函数
CREATE AGGREGATE group_concat( anyelement)
(
sfunc = array_append,
stype = anyarray,
initcond = '{}'
) ;
pg数据库将查询结果拼接字符串返回
select users. * , array_to_string( ARRAY_AGG( roles. name) , ',' ) from users
left join user_roles on user_roles. user_id = users. id
inner join roles on user_roles. role_id = roles. id
group by users. id;
pg 通过命令行安装后给出的启动提示
/ usr/ lib/ postgresql/ 10 / bin/ pg_ctl - D / var/ lib/ postgresql/ 10 / main - l logfile start
/ etc/ init. d/ postgresql start
sudo su postgres - c psql
pg 根据编号分组后取第一条数据
SELECT * FROM
( SELECT ROW_NUMBER( ) OVER ( partition BY no ORDER BY no ) rowId, *
from table ) t
WHERE rowId= 1
COALESCE ( ( select major_projects_num from base_audit_indicators where year = ( select extract( year from now ( ) ) ) and base_audit_unit_id= ap. base_audit_unit_id order by id desc limit 1 ) , 0 ) as major_projects_num,
css 元素出现滚动条
// 元素设置height属性并overflow : auto;
如:
{
height : 800px;
overflow : auto;
}
axios 处理并发请求
function getUserAccount ( ) {
return axios. get ( '/user/12345' ) ;
}
function getUserPermissions ( ) {
return axios. get ( '/user/12345/permissions' ) ;
}
axios. all ( [ getUserAccount ( ) , getUserPermissions ( ) ] )
. then ( axios. spread ( function ( acct, perms) {
} ) )
js 判断数值类型
判读数值类型的正则表达式
"^//d+$"
"^[0-9]*[1-9][0-9]*$"
"^((-//d+)|(0+))$"
"^-[0-9]*[1-9][0-9]*$"
"^-?//d+$"
"^//d+(//.//d+)?$"
"^(([0-9]+//.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*//.[0-9]+)|([0-9]*[1-9][0-9]*))$"
"^((-//d+(//.//d+)?)|(0+(//.0+)?))$"
"^(-(([0-9]+//.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*//.[0-9]+)|([0-9]*[1-9][0-9]*)))$"
"^(-?//d+)(//.//d+)?$"
二进制(blob)数据转化文件下载
# msg为后台返回的二进制数据
let url = window. URL . createObjectURL ( msg)
let a = document. createElement ( 'a' )
document. body. appendChild ( a)
let fileName = '审计项目清单.xlsx'
a. href = url
a. download = fileName
a. click ( )
window. URL . revokeObjectURL ( url)
this . $message ( '导出表格成功' )