据我所知,field injection
不推荐.应该使用constructor
.
我在这里尝试做的是@Autowired
在基类的构造函数中使用,并使其可供所有子类访问.在某些子类中,我还需要一些特定的bean @Autowired
来自它们的构造函数.演示代码如下:
基类:
public abstract class Base {
protected final MyDemoService myDemoService;
@Autowired
public Base(MyDemoService myDemoService) {
this.myDemoService = myDemoService;
}
}
Run Code Online (Sandbox Code Playgroud)
继承(子)类:
public class Sub extends Base {
private final MySubService mySubService;
@Autowired
public Sub(MySubService mySubService) {
this.mySubService = mySubService;
}
}
Run Code Online (Sandbox Code Playgroud)
这将给我一个'无默认构造函数'错误.
它类似于问题:类似的问题和答案,但它在这里不起作用.
我已经潜入了一段时间,我发现这篇文章dependency injection
:进一步阅读
我在想Setter Injection
我的问题是正确的方法吗?
塞特犬注射:
public abstract class Base {
protected MyDemoService myDemoService;
@Autowired
public void setMyDemoService(MyDemoService myDemoService) { …
Run Code Online (Sandbox Code Playgroud) 我在这里找到了计算两个日期之间天差的代码.
我写了一个方法:
-(NSInteger)daysWithinEraFromDate:(NSDate *) startDate toDate:(NSDate *) endDate
{
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSInteger startDay=[gregorian ordinalityOfUnit:NSDayCalendarUnit
inUnit: NSEraCalendarUnit forDate:startDate];
NSInteger endDay=[gregorian ordinalityOfUnit:NSDayCalendarUnit
inUnit: NSEraCalendarUnit forDate:endDate];
return endDay-startDay;
}
Run Code Online (Sandbox Code Playgroud)
这种方法有一个问题:它不能考虑时区的事情.即使我添加这样一行:
[gregorian setTimeZone:[NSTimeZone localTimeZone]];
Run Code Online (Sandbox Code Playgroud)
我的测试代码是这样的:
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *strDate = @"2012-09-03 23:00:00";
NSDate *dateStart = [dateFormat dateFromString:strDate];
strDate = @"2012-09-04 01:00:00";
NSDate *dateEnd = [dateFormat dateFromString:strDate];
NSLog(@"Days difference between %@ and %@ is: %d days",[dateFormat stringFromDate:dateStart],[dateFormat stringFromDate:dateEnd],[self daysWithinEraFromDate:dateStart toDate:dateEnd]);
Run Code Online (Sandbox Code Playgroud)
结果是:
2012-09-03 …
这是演示.
我想将两个<p>
元素对齐在同一行,但你可以看到第二个元素向下移动了一点.谁知道原因?
HTML
<div class="logo">
<p>Hello world</p>
<p class="web_address">Hello all</p>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
.logo p {
margin:0;
padding:0;
border: solid 1px black;
margin-left: 20px;
font-size: 36px;
display: inline-block;
line-height: 80px;
}
Run Code Online (Sandbox Code Playgroud) 我希望调整图像大小,同时保持四个边缘拉伸,并且中心区域对于iOS应用程序不可更改.它可以在Android中通过9补丁,但有没有任何方法Objective-C
可以做到这一点?
我正在寻找resizableImageWithCapInsets
,但它将保持四个边缘不变,并拉伸中心区域,这不是我的情况.
任何建议将受到高度赞赏.
我知道这似乎是一个很容易的目标。我有一个input[type=text]
, 我想检测其中新添加的字符。正常的方法是:
$selector.keypress(function(e) {
//do sth here
var newchar = String.fromCharCode(e.which);
});
Run Code Online (Sandbox Code Playgroud)
但上述方法对于Android 设备上的某些浏览器无法正常工作。输入 Android 虚拟键盘不会触发keypress
.
然后我发现下面的方法比较好:
$selector.on('input', function(e){
//do sth here
});
Run Code Online (Sandbox Code Playgroud)
它适用于 Android 设备,而且还可以检测cut/paste
.
现在的问题是,有没有办法知道新添加的字符input
?每次输入时是否需要进行复杂的字符串比较,即比较输入框中之前的字符串和新的字符串?我说这很复杂,因为你可能并不总是在末尾输入字符,你可能会在前一个字符串的中间插入一些字符。想一想,输入框中之前的字符串是“abc”,粘贴后的新字符串是“abcxabc”,我们怎么知道新粘贴的字符串是“abcx”,还是“xabc”呢?
按键的方法非常简单:
String.fromCharCode(e.which);
Run Code Online (Sandbox Code Playgroud)
那么,有没有类似的方法可以做到这一点on('input')
呢?
读完 Yeldar Kurmangaliyev 的回答后,我深入研究了这个问题一段时间,发现这确实比我之前的预期更复杂。这里的关键点是有一种方法可以通过调用来获取光标位置:selectionEnd
。
正如 Yeldar Kurmangaliyev 提到的,他的回答不能涵盖这种情况:
当您选择文本并粘贴另一文本并替换原始文本时,它不起作用。
根据他的回答,我将getInputedString
函数修改如下:
function getInputedString(prev, curr, selEnd) {
if (selEnd === 0) {
return "";
}
//note: substr(start,length) and …
Run Code Online (Sandbox Code Playgroud) 我在我的代码中使用了joda时间.当我添加这行代码时,使用内存将增加30M!
LocalDateTime _currDate = new LocalDateTime();
Run Code Online (Sandbox Code Playgroud)
我发现几乎所有的java程序员都建议使用joda时间.所以我想也许我没有以正确的方式使用它.谁知道原因,请帮帮我.非常感谢你!
我确信 Photoshop 脚本编写者之前应该讨论过它。我写了一个解决方案如下。我认为这在逻辑上是正确的,但结果不正确。任何人都可以帮助检查代码中的错误,或者对这个主题有想法?我想获取文档中的所有图层。
代码:
function getAllLayersInLayerSets(layerNodes) {
var retList = [];
for (var i=0; i<layerNodes.length; i++) {
if(layerNodes[i].layerSets.length > 0)
{
var tmp = getAllLayersInLayerSets(layerNodes[i].layerSets);
var j = (tmp == null) ? -1 : tmp.length-1;
while(tmp && j>=0)
{
retList.push(tmp[i]);
j--;
}
}
for(var layerIndex=0; layerIndex < layerNodes[i].artLayers.length; layerIndex++)
{
var layer=layerNodes[i].artLayers[layerIndex];
retList.push(layer);
}
}
return retList;
}
Run Code Online (Sandbox Code Playgroud)
非常感谢您的任何帮助或讨论。
我的问题如下所示:jsfiddle demo
如您所见,<span>
如果我将每个元素放在文件中<span>
的新行上,该元素将自动换行html
。
但是,如果我将它们一一放在一起,它们就不会断线。
请注意,为什么我问这个问题是因为在我的真实项目中,我<span>
从我的js
代码中动态添加了。那会导致同样的问题,就是<span>
不能自动断行,并且当它们的数量增加时会添加一个水平滚动条。
任何建议将不胜感激。
ps 我在我的代码中使用了 Jquery 和 Bootstrap 3。
我认为我的问题很简单,但我仍然没有找到解决方案.
我在每个项目中都有一个LongListSelector
和一个ContextMenu
.当我长按该项目时LongListSelector
,ContextMenu
会弹出一个删除选项.我想删除所选LongListSelector
项目.我的代码:
XAML:
<phone:PhoneApplicationPage
....
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
>
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid x:Name="ContentPanel" Grid.Row="0" Margin="12,0,12,0">
<phone:LongListSelector
Name="TestList"
>
<phone:LongListSelector.ItemTemplate
>
<DataTemplate>
<TextBlock Text="{Binding}">
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu Name="ContextMenu" >
<toolkit:MenuItem
Name="Delete"
Header="Delete"
Click="Delete_Click"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</TextBlock>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</Grid>
</Grid>
Run Code Online (Sandbox Code Playgroud)
C#:
namespace TestContextMenu
{
public partial class MainPage : PhoneApplicationPage
{
public List<string> Items = new List<string>
{
"Item1",
"Item2",
"Item3",
"Item4",
"Item5",
};
public MainPage()
{
InitializeComponent(); …
Run Code Online (Sandbox Code Playgroud) 我想在一个like
子句上加入两个表.我的架构是链接:
如您所见,结果为空.
但如果我使用like
如下:
如你所见,我可以得到结果name
或des
包含'GRE'.那么这里的问题是什么?
我搜索了一段时间的答案,发现建议的方法与我做的相同:
任何建议将受到高度赞赏.
在objective-c
,我想添加淡入淡出和淡出动画到UIView
.我想连续做淡出和淡入动画.为了说明一下,我想要的效果如下:
淡出 - 淡入 - 淡出 - 淡入 - ......
我正在尝试的是如下:
-(void)fadeOutIn:(UIView *)view duration:(NSTimeInterval)duration
{
static CGFloat alpha = 1.0;
[UIView animateWithDuration:duration
delay:0.0
options: UIViewAnimationOptionRepeat| UIViewAnimationOptionCurveEaseInOut
animations:^{
alpha = abs((int)(alpha - 1.0));
view.alpha = alpha;
}
completion:^(BOOL finished){
}];
}
Run Code Online (Sandbox Code Playgroud)
我也试过以下:
-(void)fadeOutIn:(UIView *)view duration:(NSTimeInterval)duration
{
[UIView animateWithDuration:duration
delay:0.0
options: UIViewAnimationOptionRepeat| UIViewAnimationOptionCurveEaseInOut
animations:^{
view.alpha = 0.0;
}
completion:^(BOOL finished){
[UIView animateWithDuration:duration
delay:0.0
options: UIViewAnimationOptionRepeat|UIViewAnimationOptionCurveEaseInOut
animations:^{
view.alpha = 1.0;
}
completion:^(BOOL finished){
}];
}];
}
Run Code Online (Sandbox Code Playgroud)
但问题是他们的工作方式完全相同,即UIView
意志淡出并且 …
javascript ×3
objective-c ×3
css ×2
ios ×2
java ×2
android ×1
animation ×1
c# ×1
contextmenu ×1
datetime ×1
html ×1
inline ×1
input ×1
javabeans ×1
jodatime ×1
join ×1
jquery ×1
mysql ×1
nstimezone ×1
photoshop ×1
spring ×1
spring-boot ×1
sql ×1
uiimage ×1