postman用globals封装自定义函数

0.准备工作

首先,我的Postman版本

是 Postman for Windows
Version 7.6.0
win32 10.0.17134 / x64

然后,准备需要封装的JS代码。自定义函数如下。

function getOneName(type) {
    var someoneArray = new Array("蕊", "薇", "菁", "梦", "岚", "苑", "婕", "馨", "瑗", "琰", "韵", "融", "园", "艺", "咏", "卿", "聪", "澜", "纯", "爽", "琬", "茗", "羽", "希", "宁", "欣", "飘", "育", "滢", "馥", "筠", "柔", "竹", "霭", "凝", "晓", "欢", "霄", "伊", "亚", "宜", "可", "姬", "舒", "影", "荔", "枝", "思", "丽", "芬", "芳", "燕", "莺", "媛", "艳", "珊", "莎", "蓉", "眉", "君", "琴", "毓", "悦", "昭", "冰", "枫", "芸", "菲", "寒", "锦", "玲", "秋", "秀", "娟", "英", "华", "慧", "巧", "美", "娜", "静", "淑", "惠", "珠", "翠", "雅", "芝", "玉", "萍", "红", "月", "彩", "春", "菊", "兰", "凤", "洁", "梅", "琳", "素", "云", "莲", "真", "环", "雪", "荣", "爱", "妹", "霞", "香", "凡", "佳", "嘉", "琼", "勤", "珍", "贞", "莉", "桂", "娣", "叶", "璧", "璐", "娅", "琦", "晶", "妍", "茜", "黛", "青", "倩", "婷", "姣", "婉", "娴", "瑾", "颖", "露", "瑶", "怡", "婵", "雁", "蓓", "纨", "仪", "荷", "丹");
    var somethingArray = new Array("刀", "枪", "剑", "戟", "斧", "钺", "钩", "叉", "鞭", "锏", "锤", "挝", "镋", "棍", "槊", "棒", "拐", "流星");
    var adjArray = new Array("好", "坏", "伟大", "勇敢", "优秀", "聪明", "老实", "鲁莽", "大方", "软", "硬", "苦", "甜", "冷", "热", "坚固", "平常", "长", "短", "大", "小", "粗", "细", "红", "绿", "平坦", "整齐", "雪白", "笔直", "绿油油", "血淋淋", "骨碌碌", "黑不溜秋", "快", "慢", "全", "整", "多", "少");
    var advArray = new Array("非常", "绝对", "极度", "十分", "最", "顶级", "太", "更", "极其", "格外", "分外", "一直", "总", "生动", "熟练", "轻松", "清楚", "马虎", "干脆", "许多");
    var vArray = new Array("搀", "抱", "搂", "扶", "捉", "擒", "掐", "推", "拿", "抽", "撕", "摘", "拣", "捡", "打", "播", "击", "捏", "撒", "按", "弹", "撞", "提", "扭", "捶", "持", "揍", "披", "捣", "搜", "托", "举", "拖", "擦", "敲", "挖", "抛", "掘", "抬", "插", "扔", "写", "抄", "抓", "捧", "掷", "撑", "摊", "倒", "摔", "劈", "画", "搔", "撬", "挥", "揽", "挡", "捺", "抚", "搡", "拉", "摸", "拍", "摇", "剪", "拎", "拔", "拧", "拨", "舞", "握", "攥");
    var objectArray = new Array("头", "喉", "胸", "肚", "腹", "腿", "脖", "肩", "背", "腰", "臀", "手", "脚");
    var nickArray = new Array("儿", "子", "君", "酱");
    var n;
    var prefix;
    if (type === 0) {
        prefix = objectArray[(Math.random() * (objectArray.length - 1)).round()] + advArray[(Math.random() * (advArray.length - 1)).round()] + adjArray[(Math.random() * (adjArray.length - 1)).round()];
        n = "的" + someoneArray[(Math.random() * (someoneArray.length - 1)).round()] + nickArray[(Math.random() * (nickArray.length - 1)).round()];
    } else if (type === 1) {
        prefix = advArray[(Math.random() * (advArray.length - 1)).round()] + vArray[(Math.random() * (vArray.length - 1)).round()] + objectArray[(Math.random() * (objectArray.length - 1)).round()] + adjArray[(Math.random() * (adjArray.length - 1)).round()];
        n = "之" + somethingArray[(Math.random() * (somethingArray.length - 1)).round()];
    } else if (type === 2) {
        prefix = advArray[(Math.random() * (advArray.length - 1)).round()] + vArray[(Math.random() * (vArray.length - 1)).round()] + objectArray[(Math.random() * (objectArray.length - 1)).round()] + adjArray[(Math.random() * (adjArray.length - 1)).round()];
        n = "";
    }
    return prefix + n;
}

1.将自定义函数放入全局变量

首先,把代码格式化,引号转义。

function getOneName(type){var someoneArray=new Array(\"蕊\",\"薇\",\"菁\",\"梦\",\"岚\",\"苑\",\"婕\",\"馨\",\"瑗\",\"琰\",\"韵\",\"融\",\"园\",\"艺\",\"咏\",\"卿\",\"聪\",\"澜\",\"纯\",\"爽\",\"琬\",\"茗\",\"羽\",\"希\",\"宁\",\"欣\",\"飘\",\"育\",\"滢\",\"馥\",\"筠\",\"柔\",\"竹\",\"霭\",\"凝\",\"晓\",\"欢\",\"霄\",\"伊\",\"亚\",\"宜\",\"可\",\"姬\",\"舒\",\"影\",\"荔\",\"枝\",\"思\",\"丽\",\"芬\",\"芳\",\"燕\",\"莺\",\"媛\",\"艳\",\"珊\",\"莎\",\"蓉\",\"眉\",\"君\",\"琴\",\"毓\",\"悦\",\"昭\",\"冰\",\"枫\",\"芸\",\"菲\",\"寒\",\"锦\",\"玲\",\"秋\",\"秀\",\"娟\",\"英\",\"华\",\"慧\",\"巧\",\"美\",\"娜\",\"静\",\"淑\",\"惠\",\"珠\",\"翠\",\"雅\",\"芝\",\"玉\",\"萍\",\"红\",\"月\",\"彩\",\"春\",\"菊\",\"兰\",\"凤\",\"洁\",\"梅\",\"琳\",\"素\",\"云\",\"莲\",\"真\",\"环\",\"雪\",\"荣\",\"爱\",\"妹\",\"霞\",\"香\",\"凡\",\"佳\",\"嘉\",\"琼\",\"勤\",\"珍\",\"贞\",\"莉\",\"桂\",\"娣\",\"叶\",\"璧\",\"璐\",\"娅\",\"琦\",\"晶\",\"妍\",\"茜\",\"黛\",\"青\",\"倩\",\"婷\",\"姣\",\"婉\",\"娴\",\"瑾\",\"颖\",\"露\",\"瑶\",\"怡\",\"婵\",\"雁\",\"蓓\",\"纨\",\"仪\",\"荷\",\"丹\");var somethingArray=new Array(\"刀\",\"枪\",\"剑\",\"戟\",\"斧\",\"钺\",\"钩\",\"叉\",\"鞭\",\"锏\",\"锤\",\"挝\",\"镋\",\"棍\",\"槊\",\"棒\",\"拐\",\"流星\");var adjArray=new Array(\"好\",\"坏\",\"伟大\",\"勇敢\",\"优秀\",\"聪明\",\"老实\",\"鲁莽\",\"大方\",\"软\",\"硬\",\"苦\",\"甜\",\"冷\",\"热\",\"坚固\",\"平常\",\"长\",\"短\",\"大\",\"小\",\"粗\",\"细\",\"红\",\"绿\",\"平坦\",\"整齐\",\"雪白\",\"笔直\",\"绿油油\",\"血淋淋\",\"骨碌碌\",\"黑不溜秋\",\"快\",\"慢\",\"全\",\"整\",\"多\",\"少\");var advArray=new Array(\"非常\",\"绝对\",\"极度\",\"十分\",\"最\",\"顶级\",\"太\",\"更\",\"极其\",\"格外\",\"分外\",\"一直\",\"总\",\"生动\",\"熟练\",\"轻松\",\"清楚\",\"马虎\",\"干脆\",\"许多\");var vArray=new Array(\"搀\",\"抱\",\"搂\",\"扶\",\"捉\",\"擒\",\"掐\",\"推\",\"拿\",\"抽\",\"撕\",\"摘\",\"拣\",\"捡\",\"打\",\"播\",\"击\",\"捏\",\"撒\",\"按\",\"弹\",\"撞\",\"提\",\"扭\",\"捶\",\"持\",\"揍\",\"披\",\"捣\",\"搜\",\"托\",\"举\",\"拖\",\"擦\",\"敲\",\"挖\",\"抛\",\"掘\",\"抬\",\"插\",\"扔\",\"写\",\"抄\",\"抓\",\"捧\",\"掷\",\"撑\",\"摊\",\"倒\",\"摔\",\"劈\",\"画\",\"搔\",\"撬\",\"挥\",\"揽\",\"挡\",\"捺\",\"抚\",\"搡\",\"拉\",\"摸\",\"拍\",\"摇\",\"剪\",\"拎\",\"拔\",\"拧\",\"拨\",\"舞\",\"握\",\"攥\");var objectArray=new Array(\"头\",\"喉\",\"胸\",\"肚\",\"腹\",\"腿\",\"脖\",\"肩\",\"背\",\"腰\",\"臀\",\"手\",\"脚\");var nickArray=new Array(\"儿\",\"子\",\"君\",\"酱\");var n;var prefix;if(type===0){prefix=objectArray[(Math.random()*(objectArray.length-1)).round()]+advArray[(Math.random()*(advArray.length-1)).round()]+adjArray[(Math.random()*(adjArray.length-1)).round()];n=\"的\"+someoneArray[(Math.random()*(someoneArray.length-1)).round()]+nickArray[(Math.random()*(nickArray.length-1)).round()];}else if(type===1){prefix=advArray[(Math.random()*(advArray.length-1)).round()]+vArray[(Math.random()*(vArray.length-1)).round()]+objectArray[(Math.random()*(objectArray.length-1)).round()]+adjArray[(Math.random()*(adjArray.length-1)).round()];n=\"之\"+somethingArray[(Math.random()*(somethingArray.length-1)).round()];}else if(type===2){prefix=advArray[(Math.random()*(advArray.length-1)).round()]+vArray[(Math.random()*(vArray.length-1)).round()]+objectArray[(Math.random()*(objectArray.length-1)).round()]+adjArray[(Math.random()*(adjArray.length-1)).round()];n=\"\";}return prefix+n;}"

在Pre-req.里面将这段代码放入全局变量pm.globals.set(“key”,”value”)。

pm.globals.set("getOneName", "function getOneName(type){var someoneArray=new Array(\"蕊\",\"薇\",\"菁\",\"梦\",\"岚\",\"苑\",\"婕\",\"馨\",\"瑗\",\"琰\",\"韵\",\"融\",\"园\",\"艺\",\"咏\",\"卿\",\"聪\",\"澜\",\"纯\",\"爽\",\"琬\",\"茗\",\"羽\",\"希\",\"宁\",\"欣\",\"飘\",\"育\",\"滢\",\"馥\",\"筠\",\"柔\",\"竹\",\"霭\",\"凝\",\"晓\",\"欢\",\"霄\",\"伊\",\"亚\",\"宜\",\"可\",\"姬\",\"舒\",\"影\",\"荔\",\"枝\",\"思\",\"丽\",\"芬\",\"芳\",\"燕\",\"莺\",\"媛\",\"艳\",\"珊\",\"莎\",\"蓉\",\"眉\",\"君\",\"琴\",\"毓\",\"悦\",\"昭\",\"冰\",\"枫\",\"芸\",\"菲\",\"寒\",\"锦\",\"玲\",\"秋\",\"秀\",\"娟\",\"英\",\"华\",\"慧\",\"巧\",\"美\",\"娜\",\"静\",\"淑\",\"惠\",\"珠\",\"翠\",\"雅\",\"芝\",\"玉\",\"萍\",\"红\",\"月\",\"彩\",\"春\",\"菊\",\"兰\",\"凤\",\"洁\",\"梅\",\"琳\",\"素\",\"云\",\"莲\",\"真\",\"环\",\"雪\",\"荣\",\"爱\",\"妹\",\"霞\",\"香\",\"凡\",\"佳\",\"嘉\",\"琼\",\"勤\",\"珍\",\"贞\",\"莉\",\"桂\",\"娣\",\"叶\",\"璧\",\"璐\",\"娅\",\"琦\",\"晶\",\"妍\",\"茜\",\"黛\",\"青\",\"倩\",\"婷\",\"姣\",\"婉\",\"娴\",\"瑾\",\"颖\",\"露\",\"瑶\",\"怡\",\"婵\",\"雁\",\"蓓\",\"纨\",\"仪\",\"荷\",\"丹\");var somethingArray=new Array(\"刀\",\"枪\",\"剑\",\"戟\",\"斧\",\"钺\",\"钩\",\"叉\",\"鞭\",\"锏\",\"锤\",\"挝\",\"镋\",\"棍\",\"槊\",\"棒\",\"拐\",\"流星\");var adjArray=new Array(\"好\",\"坏\",\"伟大\",\"勇敢\",\"优秀\",\"聪明\",\"老实\",\"鲁莽\",\"大方\",\"软\",\"硬\",\"苦\",\"甜\",\"冷\",\"热\",\"坚固\",\"平常\",\"长\",\"短\",\"大\",\"小\",\"粗\",\"细\",\"红\",\"绿\",\"平坦\",\"整齐\",\"雪白\",\"笔直\",\"绿油油\",\"血淋淋\",\"骨碌碌\",\"黑不溜秋\",\"快\",\"慢\",\"全\",\"整\",\"多\",\"少\");var advArray=new Array(\"非常\",\"绝对\",\"极度\",\"十分\",\"最\",\"顶级\",\"太\",\"更\",\"极其\",\"格外\",\"分外\",\"一直\",\"总\",\"生动\",\"熟练\",\"轻松\",\"清楚\",\"马虎\",\"干脆\",\"许多\");var vArray=new Array(\"搀\",\"抱\",\"搂\",\"扶\",\"捉\",\"擒\",\"掐\",\"推\",\"拿\",\"抽\",\"撕\",\"摘\",\"拣\",\"捡\",\"打\",\"播\",\"击\",\"捏\",\"撒\",\"按\",\"弹\",\"撞\",\"提\",\"扭\",\"捶\",\"持\",\"揍\",\"披\",\"捣\",\"搜\",\"托\",\"举\",\"拖\",\"擦\",\"敲\",\"挖\",\"抛\",\"掘\",\"抬\",\"插\",\"扔\",\"写\",\"抄\",\"抓\",\"捧\",\"掷\",\"撑\",\"摊\",\"倒\",\"摔\",\"劈\",\"画\",\"搔\",\"撬\",\"挥\",\"揽\",\"挡\",\"捺\",\"抚\",\"搡\",\"拉\",\"摸\",\"拍\",\"摇\",\"剪\",\"拎\",\"拔\",\"拧\",\"拨\",\"舞\",\"握\",\"攥\");var objectArray=new Array(\"头\",\"喉\",\"胸\",\"肚\",\"腹\",\"腿\",\"脖\",\"肩\",\"背\",\"腰\",\"臀\",\"手\",\"脚\");var nickArray=new Array(\"儿\",\"子\",\"君\",\"酱\");var n;var prefix;if(type===0){prefix=objectArray[(Math.random()*(objectArray.length-1)).round()]+advArray[(Math.random()*(advArray.length-1)).round()]+adjArray[(Math.random()*(adjArray.length-1)).round()];n=\"的\"+someoneArray[(Math.random()*(someoneArray.length-1)).round()]+nickArray[(Math.random()*(nickArray.length-1)).round()];}else if(type===1){prefix=advArray[(Math.random()*(advArray.length-1)).round()]+vArray[(Math.random()*(vArray.length-1)).round()]+objectArray[(Math.random()*(objectArray.length-1)).round()]+adjArray[(Math.random()*(adjArray.length-1)).round()];n=\"之\"+somethingArray[(Math.random()*(somethingArray.length-1)).round()];}else if(type===2){prefix=advArray[(Math.random()*(advArray.length-1)).round()]+vArray[(Math.random()*(vArray.length-1)).round()]+objectArray[(Math.random()*(objectArray.length-1)).round()]+adjArray[(Math.random()*(adjArray.length-1)).round()];n=\"\";}return prefix+n;}");

2.引用全局变量中的封装函数

在其他请求的Pre-req.中引用自定义函数

//获取起名器 
eval(globals.getOneName);
var myName = getOneName(0);
// 将变量放入环境变量中。
pm.environment.set("myName", myName);

引用环境变量,发送请求。

//变量用{{...}}括起来。
{{domain}}/{{myName}}

2011版课标背诵推荐

关雎

【作者】《诗经》
【朝代】先秦
关关雎鸠,在河之洲。
窈窕淑女,君子好逑。
参差荇菜,左右流之。
窈窕淑女,寤寐求之。
求之不得,寤寐思服。
悠哉悠哉,辗转反侧。
参差荇菜,左右采之。
窈窕淑女,琴瑟友之。
参差荇菜,左右芼之。
窈窕淑女,钟鼓乐之。

Read More

Java List.add() UnsupportedOperationException

八年前。

Java List.add() UnsupportedOperationException

______
Not every List implementation supports the add() method.
One common example is the List returned by Arrays.asList(): it is documented not to support any structural modification (i.e. removing or adding elements) (emphasis mine):
Returns a fixed-size list backed by the specified array.
Even if that’s not the specific List you’re trying to modify, the answer still applies to other Listimplementations that are either immutable or only allow some selected changes.
You can find out about this by reading the documentation of UnsupportedOperationException and List.add(), which documents this to be an “(optional operation)”. The precise meaning of this phrase is explained at the top of the List documentation.
As a workaround you can create a copy of the list to a known-modifiable implementation like ArrayList:
seeAlso = new ArrayList<>(seeAlso);

https://stackoverflow.com/questions/5755477/java-list-add-unsupportedoperationexception

MyBatis 批量 update,字段不能为 null

MyBatis Batch Update Exception: Column cannot be null

https://stackoverflow.com/questions/32217568/mybatis-batch-update-exceptioncolumn-cannot-be-null

加一句 else

为什么加

UPDATE base\_goods\_package WHEN goodsId = #{item.goodsId} THEN #{item.packageRate} WHEN goodsId = #{item.goodsId} THEN #{item.packageName} WHEN goodsId = #{item.goodsId} THEN #{item.boxLong} WHEN goodsId = #{item.goodsId} THEN #{item.boxWidth} WHEN goodsId = #{item.goodsId} THEN #{item.boxHeight} WHEN goodsId = #{item.goodsId} THEN #{item.boxWeight} WHERE goodsId = #{item.goodsId}

我错了:
参数类型为非字符串类型的时候
上面像我这样写,假如costPrice是Integer,就完蛋了。
要么 item.costPrice.toString(),要么直接删掉写成
这样。