Netbeans告诉我从非静态方法访问静态方法是不好的.为什么这么糟糕?"访问静态方法getInstance"是警告:
import java.util.Calendar;
public class Clock
{
// Instance fields
private Calendar time;
/**
* Constructor. Starts the clock at the current operating system time
*/
public Clock()
{
System.out.println(getSystemTime());
}
private String getSystemTime()
{
return this.time.getInstance().get(Calendar.HOUR)+":"+
this.time.getInstance().get(Calendar.MINUTE);
}
Run Code Online (Sandbox Code Playgroud)
}
使用Zend Framework中设置的标准MVC,我希望能够显示具有锚点的页面.现在我只是在.phtml文件中添加一个我想要的'#anchor'的无意义参数.
<?= $this->url(array(
'controller'=>'my.controller',
'action'=>'my.action',
'anchor'=>'#myanchor'
));
Run Code Online (Sandbox Code Playgroud)
这将URL设置为/my.controller/my.action/anchor/#myanchor
有没有更好的方法来实现这一目标?导航到锚链接后,额外的项参数将在用户的URL中设置,这是我不想发生的事情.
我有一个应用程序将数据保存到名为Jobs的表中.Jobs表有一个名为Name的列,它具有UNIQUE约束."名称"列不是PRIMARY KEY.我想知道在尝试保存/更新新条目之前是否应该自己检查重复条目,或者最好是等待数据访问层抛出的异常.如果它有任何重要性,我正在使用NHibernate这个应用程序
感谢大家的巨大投入.
我找到了另一个原因,我应该在代码中验证,而不是等待抛出异常(并由我的代码捕获).似乎NHibernate只会抛出一个NHibernate.Exceptions.GenericADOException,它在这种情况下对异常的原因没有太多信息.或者我在这里错过了NHibernate的一个方面?
这个问题特别针对java语言.我知道为所有静态代码留出了一个静态的内存.
我的问题是这个静态内存是如何填充的?静态对象是在导入时还是在第一次引用时放入静态内存?此外,相同的垃圾收集规则是否适用于静态对象,因为它们适用于所有其他对象?
public class Example{
public static SomeObject someO = new SomeObject();
}
/********************************/
// Is the static object put into static memory at this point?
import somepackage.Example;
public class MainApp{
public static void main( Sting args[] ){
// Or is the static object put into memory at first reference?
Example.someO.someMethod();
// Do the same garbage collection rules apply to a
// static object as they do all others?
Example.someO = null;
System.gc();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在设计一个帮助方法,为我延迟加载某些对象,调用它看起来像这样:
public override EDC2_ORM.Customer Customer {
get { return LazyLoader.Get<EDC2_ORM.Customer>(
CustomerId, _customerDao, ()=>base.Customer, (x)=>Customer = x); }
set { base.Customer = value; }
}
Run Code Online (Sandbox Code Playgroud)
当我编译此代码时,我收到以下警告:
警告5通过匿名方法,lambda表达式,查询表达式或迭代器中的'base'关键字访问成员'EDC2_ORM.Billing.Contract.Site'会导致无法验证的代码.考虑将访问权限移动到包含类型的辅助方法中.
这里的投诉到底是什么,为什么我做得不好?
现在我正在尝试使用System.Web.Routing.一切都很好,但我无法理解如何使用url路由进行表单身份验证(返回URL,重定向等).谷歌没有说什么.救命!:)
UPD:我忘了 - 我不使用MVC.那就是问题所在.如何在没有MVC的情况下使用rounig和表单身份验证
UPD2:更多关于我的问题
我想得到的:使用Routes的URL" mysite.com/content/123"," mysite.com/login/"等.使登录页面像"常规"ASP.NET登录表单一样重要(在不登录时重定向到从安全区域登录,并在登录时重定向回安全区域).
这就是我正在做的事情.
在global.asaxon Application_Start,注册这样的路线:
routes.Add("LoginPageRoute", new Route("login/", new CustomRouteHandler("~/login.aspx")));
routes.Add("ContentRoute", new Route("content/{id}", new ContentRoute("~/content.aspx"))
{
Constraints = new RouteValueDictionary {{ "id", @"\d+" }}
});
Run Code Online (Sandbox Code Playgroud)
在哪里CustomRouteHandler和ContentRoute- 简单的IRouteHandler类,就像:...
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
var page = BuildManager.CreateInstanceFromVirtualPath(VirtualPath, typeof(Page)) as IHttpHandler;
return page;
}
Run Code Online (Sandbox Code Playgroud)
...
一切似乎都很完美:我content.aspx什么时候去“/content/10”,login.aspx什么时候去“/login/”.但是......
当我确保内容安全(in web.config,with deny=”?”)时,登录表单不能像预期的那样工作.
现在我无法访问该“/content/10” …
我对Rails相当陌生,我很好奇一些专家在需要构建包含许多条件的非常复杂的SQL查询时正在使用的约定.具体来说,保持代码可读和可维护.
我可以想到几种方法:
单行,在调用find()时:
@pitchers = Pitcher.find(:all, "<conditions>")
Run Code Online (Sandbox Code Playgroud)
使用预定义的字符串并将其传递给:
@pitchers = Pitcher.find(:all, @conditions)
Run Code Online (Sandbox Code Playgroud)
使用私有成员函数返回查询
@pitchers = Pitcher.find(:all, conditionfunction)
Run Code Online (Sandbox Code Playgroud)
我更倾向于私有成员函数约定,另外因为您可以传入参数来自定义查询.
有什么想法吗?
我有
$.ajax({
url: identity,
success: function(data) { ProcessIdentityServer(data) }
});
Run Code Online (Sandbox Code Playgroud)
当返回'data'时,是否有办法针对它运行选择器而不将其添加到DOM中.那么,例如,如何在不将数据首先添加到DOM中的情况下获取"数据"中包含的HTML中包含的任何LINK标记的所有href值?如果我想要做的就是将一些东西提取到一个数组中,那么将它添加到DOM中似乎是一种耻辱.有人有任何想法吗?