在这里,我们将给大家分享关于拒绝!=null的知识,让您更了解拒绝英语的本质,同时也会涉及到如何更有效地ALTERTABLE,在nullnull列中设置null,PostgreSQL9.1、andro
在这里,我们将给大家分享关于拒绝 ! = null的知识,让您更了解拒绝英语的本质,同时也会涉及到如何更有效地ALTER TABLE,在null null列中设置null,PostgreSQL 9.1、android – 目标主机不能为null或在parameters.scheme = null,host = null中设置、angularjs是否作为$scope.null处理null?、ANSI_NULLS 和 CONCAT_NULL_YIELDS_NULL的内容。
本文目录一览:- 拒绝 ! = null(拒绝英语)
- ALTER TABLE,在null null列中设置null,PostgreSQL 9.1
- android – 目标主机不能为null或在parameters.scheme = null,host = null中设置
- angularjs是否作为$scope.null处理null?
- ANSI_NULLS 和 CONCAT_NULL_YIELDS_NULL
拒绝 ! = null(拒绝英语)
...if (someobject != null) {
someobject.doCalc();}...
1、null 是一个有效有意义的返回值(Where null is a valid response in terms of the contract; and)
2、null是无效有误的(Where it isn''t a valid response.)
null就是一个不合理的参数,就应该明确地中断程序,往外抛错误。这种情况常见于api方法。例如你开发了一个接口,id是一个必选的参数,如果调用方没传这个参数给你,当然不行。你要感知到这个情况,告诉调用方“嘿,哥们,你传个null给我做甚"。
这种情况下,null是个”看上去“合理的值,例如,我查询数据库,某个查询条件下,就是没有对应值,此时null算是表达了“空”的概念。
public interface Action {
void doSomething();}
public interface Parser {
Action findAction(String userInput);}
其中,Parse有一个接口FindAction,这个接口会依据用户的输入,找到并执行对应的动作。假如用户输入不对,可能就找不到对应的动作(Action),因此findAction就会返回null,接下来action调用doSomething方法时,就会出现空指针。
解决这个问题的一个方式,就是使用Null Object pattern(空对象模式)
我们来改造一下
类定义如下,这样定义findAction方法后,确保无论用户输入什么,都不会返回null对象
public class MyParser implements Parser {
private static Action DO_NOTHING = new Action() {
public void doSomething() { /* do nothing */ }
};
public Action findAction(String userInput) {
// ...
if ( /* we can''t find any actions */ ) {
return DO_NOTHING;
}
}}
对比下面两份调用实例
Parser parser = ParserFactory.getParser();
if (parser == null) {
// now what?
// this would be an example of where null isn''t (or shouldn''t be) a valid response
}
Action action = parser.findAction(someInput);
if (action == null) {
// do nothing} else {
action.doSomething();}
2、精简
ParserFactory.getParser().findAction(someInput).doSomething();
其他回答精选:
1、如果要用equal方法,请用object<不可能为空>.equal(object<可能为空>))
"bar".equals(foo)
而不是
foo.equals("bar")
stackoverflow链接:
来自:CSDN,译者:lizeyang
链接:https://blog.csdn.net/lizeyang/article/details/40040817
本文分享自微信公众号 - Java后端(web_resource)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。
ALTER TABLE,在null null列中设置null,PostgreSQL 9.1
我的意思是,我想做这样的事情:
postgres=# ALTER TABLE person ALTER COLUMN phone SET NULL;
但它显示:
postgres=# ALTER TABLE person ALTER COLUMN phone SET NULL; ERROR: Syntax error at or near "NULL" LINE 1: ALTER TABLE person ALTER COLUMN phone SET NULL;
ALTER TABLE person ALTER COLUMN phone DROP NOT NULL;
更多细节在手册:http://www.postgresql.org/docs/9.1/static/sql-altertable.html
android – 目标主机不能为null或在parameters.scheme = null,host = null中设置
我得到以下例外:
Target host must not be null or set in parameters.scheme=null,
host=null,path=/webservices/tempconvert.asmx/FahrenheitToCelsius
我的源代码:
public class Paractivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView t=new TextView(this);
String encodedUrl = null;
// setContentView(R.layout.main);
HttpClient client = new DefaultHttpClient();
//String query = "?Fahrenheit=26";
// String host = "www.w3schools.com/webservices/tempconvert.asmx/";
// encodedUrl = host + URLEncoder.encode(query,"utf-8");
// int p=(Integer) null;
// URI uri = URIUtils.createURI("vv", "www.w3schools.com", 50, "/webservices/tempconvert.asmx", "?Fahrenheit=26", null);
try{
String postURL = "/webservices/tempconvert.asmx/FahrenheitToCelsius";
HttpPost post = new HttpPost(postURL);
// post.addHeader("scheme","vv");
// post.setHeader("host", "www.w3schools.com");
String PostData="36";
StringEntity httpPostEntity = new StringEntity(PostData, HTTP.UTF_8);
post.setEntity(httpPostEntity);
post.setHeader("host", "www.w3schools.com");
post.setHeader("Content-Length", new Integer(PostData.length()).toString());
post.setHeader("Content-Type", "application/x-www-form-urlencoded");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
// nameValuePairs.add(new BasicNameValuePair("host", "www.w3schools.com"));
nameValuePairs.add(new BasicNameValuePair("Fahrenheit", "26"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse responsePOST = null;
// Execute HTTP Post Request
// HttpResponse response = httpclient.execute(post);
client.getConnectionManager();
responsePOST = client.execute(post);
httpentity resEntity = responsePOST.getEntity();
String response=EntityUtils.toString(resEntity);
response=response.trim();
// Log.i("RESPONSE=",response);
t.setText("response"+response);
setContentView(t);
} catch (Exception e) {
// Todo Auto-generated catch block
//e.printstacktrace();
t.setText("ex"+e.getMessage());
setContentView(t);
}
}
}
我想在以下位置调用webservice:
http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit
使用HttpClient.How应该给主机和方案作为输入?
请帮忙…
解决方法:
这是您的主机错误
您在post.setHeader(“主持人”,“www.w3schools.com”)中传递“www.w3schools.com”;而你必须通过“http://www.w3schools.com”
您可以在here中引用相同的问题
angularjs是否作为$scope.null处理null?
<div ng-show="bar !== null">hello</div>
这是否在范围内评估为
$scope.bar !== null
还是这样?
$scope.bar !== $scope.null
请注意,在最后一种情况下,$scope.null将是未定义的,并且示例似乎正常工作.
奖金:
如果bar = null则会发生这种情况
// this does not work (shows hello) <div ng-show="bar !== null">hello</div>
没有给出相同的结果
// this works ok (does not show hello) <div ng-show="bar != null">hello</div>
为什么会这样?
解决方法
ANSI_NULLS 和 CONCAT_NULL_YIELDS_NULL
在sqlserver宝典上又看到了这两个属性,研究了一下。
最后的查询都是推荐方案。不建议使用属性设置的方式!
sql-92 标准要求对空值的等于 (=) 或不等于 (<>) 比较取值为 FALSE。当set ansi_nulls on时,就符合了92标准。
今天的关于拒绝 ! = null和拒绝英语的分享已经结束,谢谢您的关注,如果想了解更多关于ALTER TABLE,在null null列中设置null,PostgreSQL 9.1、android – 目标主机不能为null或在parameters.scheme = null,host = null中设置、angularjs是否作为$scope.null处理null?、ANSI_NULLS 和 CONCAT_NULL_YIELDS_NULL的相关知识,请在本站进行查询。
本文标签: