在本文中,我们将带你了解web3.js_1.x.x--API(一)event/Constant/deploy/options在这篇文章中,同时我们还将给您一些技巧,以帮助您实现更有效的.jdbc4.M
在本文中,我们将带你了解web3.js_1.x.x--API(一)event/Constant/deploy/options在这篇文章中,同时我们还将给您一些技巧,以帮助您实现更有效的.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.、android – Fragment,保存onSaveInstanceState上的大型数据列表(如何防止TransactionTooLargeException)、ApplicationStartedEvent与ContextStartedEvent有区别吗?、asp.net-web-api – WebAPI 2 – CORS无法使用contentType application / json。
本文目录一览:- web3.js_1.x.x--API(一)event/Constant/deploy/options
- .jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
- android – Fragment,保存onSaveInstanceState上的大型数据列表(如何防止TransactionTooLargeException)
- ApplicationStartedEvent与ContextStartedEvent有区别吗?
- asp.net-web-api – WebAPI 2 – CORS无法使用contentType application / json
web3.js_1.x.x--API(一)event/Constant/deploy/options
/*
事件是使用EVM日志内置功能的方便工具,在DAPP的接口中,它可以反过来调用Javascript的监听事件的回调。
事件在合约中可被继承。当被调用时,会触发参数存储到交易的日志中(一种区块链上的特殊数据结构)。
这些日志与合约的地址关联,并合并到区块链中,只要区块可以访问就一直存在
*/
myContract.once(event[, options], callback) //单次订阅合约事件
myContract.events.MyEvent([options][, callback]) //订阅合约事件
myContract.events.allEvents([options][, callback]) //订阅合约全部事件
myContract.getPastEvents(event[, options][, callback]) //读取合约历史事件
options - Object: 可选,用于部署的选项,包含以下字段:
filter - Object : 可选,按索引参数过滤事件。例如 {filter: {myNumber: [12,13]}} 表示 “myNumber” 为12或13的所有事件
fromBlock - Number: 可选,仅监听该选项指定编号的块中发生的事件
topics - Array : 可选,用来手动为事件过滤器设定主题。如果设置过filter属性和事件签名,那么(topic[0])将不会自动设置
callback - Function: 可选,该回调函数触发时,其第二给参数为事件对象,第一个参数为错误对象
底层的日志接口(Low-level Interface to Logs)
通过函数log0,log1,log2,log3,log4,可以直接访问底层的日志组件。logi表示总共有带i + 1个参数
log3(
msg.value,
0x50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb20,
msg.sender,
_id
);
调用:
myContract.deploy(options)
参数:
options - Object: 用于部署的配置选项,包含以下字段:
data - String: 合约的字节码
arguments - Array : 可选,在部署时将传入合约的构造函数
返回值:
Object: 交易对象,包含以下字段:
arguments: Array - 之前传入方法的参数,可修改
send: Function - 用来部署合约,其返回的promise对象将解析为新的合约实例,而非交易收据!
estimateGas: Function - 用来估算用于部署的gas用量
encodeABI: Function - 用来编码部署的ABI数据,即合约数据 + 构造函数参数
myContract.deploy({
data: ''0x12345...'',
arguments: [123, ''My String'']
})
.send({
from: ''0x1234567890123456789012345678901234567891'',
gas: 1500000,
gasPrice: ''30000000000000''
}, function(error, transactionHash){ ... })
.on(''error'', function(error){ ... })
.on(''transactionHash'', function(transactionHash){ ... })
.on(''receipt'', function(receipt){
console.log(receipt.contractAddress) // 收据中包含了新的合约地址
})
.on(''confirmation'', function(confirmationNumber, receipt){ ... })
.then(function(newContractInstance){
console.log(newContractInstance.options.address) // 新地址的合约实例
});
// data是合约自身的一个可选配置项
myContract.options.data = ''0x12345...'';
myContract.deploy({
arguments: [123, ''My String'']
})
.send({
from: ''0x1234567890123456789012345678901234567891'',
gas: 1500000,
gasPrice: ''30000000000000''
})
.then(function(newContractInstance){
console.log(newContractInstance.options.address) // instance with the new contract address
});
// 编码
myContract.deploy({
data: ''0x12345...'',
arguments: [123, ''My String'']
})
.encodeABI();
> ''0x12345...0000012345678765432''
// 估算gas
myContract.deploy({
data: ''0x12345...'',
arguments: [123, ''My String'']
})
.estimateGas(function(err, gas){
console.log(gas);
});
/*
new web3.eth.Contract(jsonInterface[, address][, options])
参数:
jsonInterface(abi) - Object: 要实例化的合约的json接口
address - String: 可选,要调用的合约的地址,也可以在之后使用 myContract.options.address = ''0x1234..'' 来指定该地址
options - Object : 可选,合约的配置对象,其中某些字段用作调用和交易的回调:
from - String: 交易发送方地址
gasPrice - String: 用于交易的gas价格,单位:wei
gas - Number: 交易可用的最大gas量,即gas limit
data - String: 合约的字节码,部署合约时需要
*/
truffle(develop)> tokenContract.options
{ address: [Getter/Setter], jsonInterface: [Getter/Setter] }
truffle(develop)> tokenContract.options.jsonInterface[1]
{ constant: false,
inputs:
[ { name: ''_from'', type: ''address'' },
{ name: ''_to'', type: ''address'' },
{ name: ''_value'', type: ''uint256'' } ],
name: ''transferFrom'',
outputs: [ { name: '''', type: ''bool'' } ],
payable: false,
stateMutability: ''nonpayable'',
type: ''function'',
signature: ''0x23b872dd'' }
.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
at sun.reflect.GeneratedConstructorAccessor65.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
at com.mysql.jdbc.ConnectionImpl.throwConnectionClosedException(ConnectionImpl.java:1311)
at com.mysql.jdbc.ConnectionImpl.checkClosed(ConnectionImpl.java:1303)
at com.mysql.jdbc.ConnectionImpl.createStatement(ConnectionImpl.java:2683)
at com.mysql.jdbc.ConnectionImpl.createStatement(ConnectionImpl.java:2665)
at security.view.util.SqlUtils.insert(SqlUtils.java:315)
at security.view.util.SqlUtils.processKill(SqlUtils.java:109)
at security.view.util.SqlUtils.sql(SqlUtils.java:148)
at security.view.util.SqlUtils.sqlJsonObj(SqlUtils.java:418)
at security.view.util.SqlUtils.processKill(SqlUtils.java:97)
at security.view.util.SqlUtils.sql(SqlUtils.java:148)
android – Fragment,保存onSaveInstanceState上的大型数据列表(如何防止TransactionTooLargeException)
在我的片段onSaveInstanceState上,我将列表数据保存到Bunde,以保持配置更改等数据.
public void onSaveInstanceState(Bundle savedState) { super.onSaveInstanceState(savedState); savedState.putParcelableArrayList(LIST_STORAGE_KEY,new ArrayList<>(mItemAdapter.getModels())); }
现在我已经开始在我的应用程序错误报告上看到TransactionTooLargeException.
在某些情况下,似乎我放入Bundle的列表太大(因为它是非常复杂的对象的集合).
我该如何处理这个案子?如何存储(和恢复)我的Fragment状态.
在ViewPager中的片段上使用setRetainInstance(true)是否可以?
解决方法
public class MyActivity extends Activity { private DataFragment dataFragment; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // find the retained fragment on activity restarts FragmentManager fm = getFragmentManager(); dataFragment = (DataFragment) fm.findFragmentByTag("data"); // create the fragment and data the first time if (dataFragment == null) { // add the fragment dataFragment = new DataFragment(); fm.beginTransaction().add(dataFragment,"data").commit(); // load the data from the web dataFragment.setData(loadMyData()); } // the data is available in dataFragment.getData() ... } @Override public void onDestroy() { super.onDestroy(); // store the data in the fragment dataFragment.setData(collectMyLoadedData()); } }
片段的例子:
public class DataFragment extends Fragment { // data object we want to retain private MyDataObject data; // this method is only called once for this fragment @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // retain this fragment setRetainInstance(true); } public void setData(MyDataObject data) { this.data = data; } public MyDataObject getData() { return data; } }
ApplicationStartedEvent与ContextStartedEvent有区别吗?
大家好,我是DD!
今天跟大家聊聊这个问题:ApplicationStartedEvent与ContextStartedEvent有区别吗?
对了,最近花了几周时间,把SpringForAll社区 3.0上线了,社区的建设目标与之前一样,希望能够构建一个垂直于Java开发者的高质量技术社区!目前,已经有接近1000名注册用户,每天也有不少读者会发布一些帖子,技术氛围已经初步形成。
如果你正在学习Java、Spring,你可以在这里分享你的见解,碰到的问题以及帮助别人解决问题。
后面,我会持续精选一些,我觉得有意思的问题,在这里继续给大家分享一下!
关于这个问题,其实就是Spring和Spring Boot事件机制的理解。
虽然Spring Boot的基础是Spring,但Spring Boot并没有直接使用Spring中定义的常用事件,而是重新定义了一批。
它们都是继承自SpringApplicationEvent
,而SpringApplicationEvent
继承自ApplicationEvent
,SpringApplicationEvent
与题主提到的ContextStartedEvent
是平级的。
所以,Spring Boot中应该是没用到ContextStartedEvent的
。
Spring Boot具体有哪些事件可以看看之前在2.0发布的时候写过一篇:[《Spring Boot 2.0 新特性(二):新增事件ApplicationStartedEvent
》](https://blog.didispace.com/Sp...)
ApplicationStartingEvent
ApplicationEnvironmentPreparedEvent
ApplicationPreparedEvent
ApplicationStartedEvent <= 新增的事件
ApplicationReadyEvent
ApplicationFailedEvent
今天的分享就到这里!如果您学习过程中如遇困难?可以加入我们超高质量的Spring技术交流群,参与交流与讨论,更好的学习与进步!更多Spring Boot教程可以点击直达!,欢迎收藏与转发支持!
以上是我的认识,如果有不对的地方,也欢迎评论区指出,一起学习一起进阶!
欢迎关注我的公众号:程序猿DD。第一时间了解前沿行业消息、分享深度技术干货、获取优质学习资源
asp.net-web-api – WebAPI 2 – CORS无法使用contentType application / json
如果我尝试从我的客户端js发布这个:
$.ajax({ url: 'http://localhost:57517/api/booking',type: 'POST',crossDomain:true,data: {AdultpaxCount:1},contentType: "application/json" });
我得到一个不允许的错误(我的BookingController上的Post动作未被命中)
然而;
如果我删除了
contentType: “application/json”
部分,它’工作'(它被发送到控制器)
我在设置中遗漏了什么吗?
解决方法
[HttpOptions] [AcceptVerbs("POST","OPTIONS")]
属性到控制器的PostXXX方法.
我们今天的关于web3.js_1.x.x--API(一)event/Constant/deploy/options的分享已经告一段落,感谢您的关注,如果您想了解更多关于.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.、android – Fragment,保存onSaveInstanceState上的大型数据列表(如何防止TransactionTooLargeException)、ApplicationStartedEvent与ContextStartedEvent有区别吗?、asp.net-web-api – WebAPI 2 – CORS无法使用contentType application / json的相关信息,请在本站查询。
本文标签: