从软件设计的角度来看,什么时候应该使用@Component而不是传统的Java类(需要通过“ new”显式实例化)?例如,如果我们需要创建以下模式之一的类:
适配器
桥
正面
战略
译者
类是否应该具有@Component注释(或任何Spring衍生注释,例如@Repository/ @Controller/ @Service)?
上传到spring批处理后传递动态文件名进行处理
我是 Spring Batch 的新手,我想要完成的是从一个应用程序上传一个 csv 文件,然后使用上传文件的文件名向 Spring Batch 发送一个 post 请求,并让 Spring Batch 从它所在的位置获取文件并处理它。
我试图将字符串值传递给阅读器,但我不知道如何在步骤中访问它
// controller where i want to pass the file name to the reader
@RestController
public class ProcessController {
@Autowired
JobLauncher jobLauncher;
@Autowired
Job importUserJob;
@PostMapping("/load")
public BatchStatus Load(@RequestParam("filePath") String filePath) throws JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException {
JobExecution jobExecution = jobLauncher.run(importUserJob, new JobParametersBuilder()
.addString("fullPathFileName", filePath)
.toJobParameters());
return jobExecution.getStatus();
}
}
//reader in my configuration class
@Bean
public FlatFileItemReader<Person> reader(@Value("#{jobParameters[fullPathFileName]}") String pathToFile)
// the problem is …Run Code Online (Sandbox Code Playgroud) 我想从我的Web API访问多个文件夹位置以显示图像。我无法更改文件夹位置(取决于我无权修改任何内容的设备)。
对于我做过的其中一个文件夹:
string FolderToListen = Configuration["xxx:yyy"];
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(FolderToListen),
});
Run Code Online (Sandbox Code Playgroud)
现在我想做的是:
string FolderToListen2= Configuration["xxx2:yyy2"];
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(FolderToListen),
FileProvider = new PhysicalFileProvider(FolderToListen2),
});
Run Code Online (Sandbox Code Playgroud)
但这不起作用。有什么办法可以将多个文件夹传递给UseStaticFiles?
Highcharts发布了新版本(我相信是7.1),因此,每当您将鼠标悬停在图形上的某个元素上时,其余元素的颜色都会变浅。
我要删除此效果,并使元素颜色不淡并且仍对用户可见。
任何帮助表示赞赏。谢谢!
plotOptions: {
series: {
states: {
hover: {
enabled: false
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过了,但这不是我所需要的,或者至少它并没有消除我正在谈论的影响。
我最近对 Integer.bitCount 做了一些调查。我发现一个有趣的结果是 Integer.bitCount 比我自己的 func 快得多,即使代码是相同的。
我以为是JIT造成的,但是查了一下文档,发现JIT是基于运行时策略的。这让我很困惑。
public static void main(String[] args) {
long sum = 0;
long start, end;
start = System.currentTimeMillis();
for (int i = Integer.MIN_VALUE; i != Integer.MAX_VALUE; i++) {
sum += bitCount(i);
//sum += Integer.bitCount(i);
}
end = System.currentTimeMillis();
System.out.println(sum);
System.out.println(end - start);
}
private static int bitCount(int i) {
i = i - ((i >>> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
i = (i + (i …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的 ASP.NET 页面上添加一个按钮。我有使用 Windows 表单的经验,我知道如何将单击事件链接到按钮,但在 ASP.NET MVC 中,此链接是不同的。
如何正确制作此链接,以便在单击按钮时触发在我的 c# 源中编写的单击事件?
我正在尝试计算两个日期之间的周数。下面的代码有 3 周的结果。然而,确实是4个星期。为什么计算错误以及解决方案是什么?
我很想知道为什么这个特定的代码不起作用,但也想知道是否有更好的方法。
我正在运行 PHP 7.2 版本。下面是我正在使用的代码:
$HowManyWeeks = date( 'W', strtotime( 2019-04-21 23:59:00 ) ) - date( 'W', strtotime( 2019-03-25 00:00:00 ) );
Run Code Online (Sandbox Code Playgroud)
$HowManyWeeks 的值应为 4,但它显示为 3。
另外,当我在https://phpfiddle.org/尝试该代码时,它给出了以下错误:
Line : 2 -- syntax error, unexpected '23' (T_LNUMBER), expecting ',' or ')'
Run Code Online (Sandbox Code Playgroud)
但在我的服务器上运行时它显示“3”,没有任何错误。
谢谢,
蒂姆
if (process.env.NODE_ENV !== 'production') {
(WithUser as any).displayName = wrapDisplayName(Component, 'withUser');
}
Run Code Online (Sandbox Code Playgroud)
我不确定as是否是关键字。但是“ as”关键字在js中有什么作用?
我将多个数组连接到一个数组。这个效果很好
\n\nthis.facetsLocations = [].concat(\n response.facets[\'134_locations\'].terms,\n response.facets[\'135_locations\'].terms\n );\nRun Code Online (Sandbox Code Playgroud)\n\n但输出不是我想要的。正如你所看到的,我有相同的术语,如“deutschland”,计数:6\n“deutschland”,计数:4 等等。
\n\n结果应该是一个“deutschland”,计数 10\ni 想检查该值是否已存在并添加计数值。
\n\n(11) [{\xe2\x80\xa6}, {\xe2\x80\xa6}, {\xe2\x80\xa6}, {\xe2\x80\xa6}, {\xe2\x80\xa6}, {\xe2\x80\xa6}, {\xe2\x80\xa6}, {\xe2\x80\xa6}, {\xe2\x80\xa6}, {\xe2\x80\xa6}, {\xe2\x80\xa6}]\n0: {term: "deutschland", count: 6}\n1: {term: "basel", count: 3}\n2: {term: "osteuropa", count: 2}\n3: {term: "\xc3\xb6sterreich", count: 1}\n4: {term: "ungarn", count: 1}\n5: {term: "schweiz", count: 1}\n6: {term: "basel", count: 5}\n7: {term: "deutschland", count: 4}\n8: {term: "\xc3\xb6sterreich", count: 1}\n9: {term: "ungarn", count: 1}\nRun Code Online (Sandbox Code Playgroud)\n I have the following code
class Program
{
public async Task<bool> StartMyTask()
{
await Foo();
return true;
}
public async Task<bool> Foo()
{
for (int i = 0; i < 1000000; i++)
{
Console.WriteLine("Loop");
}
return true;
}
static void Main(string[] args)
{
Program obj = new Program();
var myTask = obj.StartMyTask();
Console.WriteLine("Before Task Return");
Console.ReadLine();
}
}
Run Code Online (Sandbox Code Playgroud)
根据我的理解,当调用“await Foo()”时,将创建一个线程来执行“Foo()”方法,并将控制权返回给调用者(Main方法)。
考虑到这一点,“Before Task Return”应该在“Foo()”方法完成之前打印。但它没有发生,首先“Foo()”方法完成,然后显示“任务返回之前”。
java ×3
c# ×2
spring ×2
typescript ×2
angular ×1
architecture ×1
arrays ×1
asp.net-core ×1
asp.net-mvc ×1
async-await ×1
date ×1
directory ×1
highcharts ×1
javascript ×1
php ×1
spring-batch ×1
strtotime ×1