空构造函数或无构造函数(Empty constructor or no constructor)
我认为在类(C#)中有一个默认的构造函数是不是必须的。
那么在这种情况下,我有一个空的建设者在课堂上还是我可以跳过它?
有空的默认构造函数是最佳做法吗?
Class test { public test() { } ...... }
要么
Class test { ...... }
I think it is not mandatory to have a default constructor in a class (C#).
So, in that situation shall I have an empty constructor in the class or can I skip it?
Is it a best practice to have an empty default constructor?
Class test { public test() { } ...... }
or
Class test { ...... }
原文:https://stackoverflow.com/questions/2963742
更新时间:2023-11-26 16:11
最满意答案
为此使用jquery:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
并调用函数
$(document).ready(function(){ $.post('localhost:5000/registrar', { "enrollId": "jim", "enrollSecret": "6avZQLwcUe9b" }, function(serverResponse){ //do what you want with server response }) })
同样没有速记来处理错误:
$.ajax({ type: "POST", url: 'localhost:5000/registrar', data: { "enrollId": "jim", "enrollSecret": "6avZQLwcUe9b" }, success: function(){$('#register').html('<h1>Login successfull</h1>');}, error: function(){$('#register').html('<h1>Login error</h1>');}, dataType: dataType });
Use jquery for this:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
And call function
$(document).ready(function(){ $.post('localhost:5000/registrar', { "enrollId": "jim", "enrollSecret": "6avZQLwcUe9b" }, function(serverResponse){ //do what you want with server response }) })
Same without shorthand to handle errors:
$.ajax({ type: "POST", url: 'localhost:5000/registrar', data: { "enrollId": "jim", "enrollSecret": "6avZQLwcUe9b" }, success: function(){$('#register').html('<h1>Login successfull</h1>');}, error: function(){$('#register').html('<h1>Login error</h1>');}, dataType: dataType });
相关问答
更多-
为此使用jquery: 并调用函数 $(document).ready(function(){ $.post('localhost:5000/registrar', { "enrollId": "jim", "enrollSecret": "6avZQLwcUe9b" }, functio ...
-
如果仔细比较你的JSON和文档中的JSON,你会在数据之前和之后有一个额外的" 。这意味着你发布了一个大的字符串,而不是一个JSON对象。 解决方法是从开始和结束删除多余的双引号。 这也意味着你不再需要转义JSON中的双引号: '{"senderId":"CBPA9tdrNyc1Y3AxSb8rkZjDJxh2","senderName":"John","text":"Hello its me"}' 如果您用于发布的工具尝试将JSON解析为单个字符串,则需要单引号。 如果没有(提示:hurl.it没有), ...
-
不要使用POST。 根据文件 : 要完成JavaScript push()方法(请参阅数据列表)的等价物,您可以发出POST请求。 你不想在这里推。 推送操作会创建一个新的随机推送ID并使其成为您提供的数据的关键。 如果你已经知道你想要设置的位置(它看起来像你已经有一个已知的推送ID),只需使用PUT来设置该位置的数据。 Don't use POST. According to the documentation: To accomplish the equivalent of the JavaScript ...
-
你可以从这样的事情开始 服务 export class MyService{ constructor( private httpClient: HttpClient) { } getSomethingFromServer():Observable
{ return this.httpClient.get('you_request_url'); } } 零件 constructor( private myService: MyService) { ... -
例外信息中明确说明了这个问题: Can not deserialize instance of long out of START_OBJECT 当杰克逊在你的JSON请求正文中找到一个起始{字符时,它不能反序列化一长串。 在如下模型中包装id应该就足够了: public class MyModel { private Long id; // use primitive type if, as I would think, id cannot be null public void se ...
-
我错过了:现在我可以得到正确的Base64值并连接到授权头并且它的工作正常 I was missing the : thing now I can get the correct Base64 value and concatenate to authorization header and its working fine
-
错误代码404表示文件不是fount。 您的api链接不是文件名退出。 请添加完整的api路径,例如 developer.b24solutions.com/grocery/api/rest/yourfilename 因为此链接在浏览器中不起作用。 您的代码是正确的但不正确的api链接。 NSURL *myURL = [NSURL URLWithString:@"http://developer.b24solutions.com/grocery/api/rest/giveyourfilenamewithext ...
-
错误 JsonMappingException是Jackson的一个例外,它是Java的JSON解析器。 它表示将JSON映射到Java bean时会出现致命问题。 在这种情况下,看起来像字符串2016-04-11无法从Java 8解析为LocalDate 。 如何解决它 Jackson支持Java 8日期类型,但需要以下依赖项:
com.fasterxml.jackson.datatype jackso ... -
如何使用Django REST API验证android用户POST请求?(How to authenticate android user POST request with Django REST API?)[2021-08-27]
听起来你正在使用Django REST Framework,在这种情况下TokenAuthentication可能是合适的。 从文档: 此认证方案使用简单的基于令牌的HTTP认证方案。 令牌认证适用于客户端 - 服务器设置,例如本机桌面和移动客户端 您不需要预先生成令牌,因为客户端可以使用您在urls.py中配置的内置视图obtain_auth_token来请求令牌。 一旦客户端获得会话标记,他们就可以使用Authorization: HTTP标头在随后的API调用中提供它。 查看文档以获取更多信息: ht ... -
关于REST API(Regarding REST API)[2022-08-05]
要回答您的问题,是的,REST API是您希望将其公开给创建用户,发布条目等的任何客户端的集合。接受的数据格式是您为API决定的。 它可能是JSON,XML甚至两者。 一些例子: http://coenraets.org/blog/2011/12/restful-services-with-jquery-php-and-the-slim-framework/ http://peter.neish.net/building-a-mobile-app-于后端的使用-mongodb的和超薄-A-PHP-其余的框架 ...