好的,我需要你的帮助.我在Stackoverflow上找到了一些代码(无法找到那个链接),它通过JS动态生成HTML代码.这是代码:
function create(htmlStr) {
var frag = document.createDocumentFragment(),
temp = document.createElement('div');
temp.innerHTML = htmlStr;
while (temp.firstChild) {
frag.appendChild(temp.firstChild);
}
return frag;
}
var fragment = create('<div class="someclass"><a href="www.example.com"><p>some text</p></a></div>');
document.body.insertBefore(fragment, document.body.childNodes[0]);
Run Code Online (Sandbox Code Playgroud)
这段代码工作很好!但生成的代码在页面顶部,body标签正下方.我的愿望是在div具有特定的空内生成该代码id="generate-here".
所以输出将是:
<div id="generate-here">
<!-- Here is generated content -->
</div>
Run Code Online (Sandbox Code Playgroud)
我知道我看不到使用"查看源"生成的内容.我只需要在这个特定的地方生成那些内容#generate-here.我是Javascript noob,所以如果有人可以重新排列这个完美的代码.非常感谢!
PS我知道如何用Jquery做这个,但在这种情况下我需要原生和纯JavaScript.
我试图让我的一个项目(ProjectA)生成一个包含所有测试类的jar文件,以便可以在ProjectB中使用它。
I did a bit of research and found this as possible solution: Create test jar artifact in gradle. That says that the following code snippet should do the trick.
apply plugin: 'java'
task testJar(type: Jar) {
classifier = 'tests'
from sourceSets.test.classes
}
Run Code Online (Sandbox Code Playgroud)
However, when I add the above to my build.gradle, I get the following error message:
- What went wrong:
A problem occurred evaluating root project 'gradle_project'.
Could not find property 'sourceSets' on task ':testJar'.
I have …
我@Transactional在控制器类中有如下方法:主要问题是每个服务调用根据日志在其自己的事务中运行。
控制器是否忽略了事务功能?
我希望学生记录不会被保存,因为我在使用另一个服务之后抛出异常,但更新仍然发生在数据库中。我什至有@EnableTransactionManagement配置类。你能帮我解决这个问题吗?
@RestController
@RequestMapping("/api")
public class Resource {
@Transactional
@RequestMapping(value="/test", method = RequestMethod.PUT, produces = "application/json")
public StudentDTO updateRecord(@RequestBody StudentDTO DTO) throws ApplicationException{
studentservice.find(1234); //jparepository.findone() runs in one transaction
studentservice.save(dto); //jparepository.save() runs in one transaction
testservice.throwException(); // this method throws application exception
}
@Configuration
@ComponentScan(basePackages={"com.student.*"})
@EnableAutoConfiguration(exclude = {MetricFilterAutoConfiguration.class, MetricRepositoryAutoConfiguration.class})
@EnableConfigurationProperties
@EnableTransactionManagement
public class Application {
}
Run Code Online (Sandbox Code Playgroud)
下面是日志:
[TRACE] org.springframework.transaction.interceptor.TransactionInterceptor - Getting transaction for [org.springframework.data.jpa.repository.support.SimpleJpaRepository.findOne]
[TRACE] org.springframework.transaction.interceptor.TransactionInterceptor - Completing transaction for [org.springframework.data.jpa.repository.support.SimpleJpaRepository.findOne]
[TRACE] org.springframework.transaction.interceptor.TransactionInterceptor - Getting …Run Code Online (Sandbox Code Playgroud) 我们的 Spark Job 有时会因为未知的原因而停止。
我们可能在日志中看到的唯一线索是failed: Set()如下所示的重复日志语句。
关于为什么在下面显示消息的任何想法将不胜感激。
18/02/08 22:12:14 INFO Executor: Finished task 0.0 in stage 51.0 (TID 38). 2008 bytes result sent to driver
18/02/08 22:12:14 INFO TaskSetManager: Finished task 0.0 in stage 51.0 (TID 38) in 312094 ms on localhost (executor driver) (1/1)
18/02/08 22:12:14 INFO TaskSchedulerImpl: Removed TaskSet 51.0, whose tasks have all completed, from pool
18/02/08 22:12:14 INFO DAGScheduler: ShuffleMapStage 51 (rdd at EsSparkSQL.scala:97) finished in 602.298 s
18/02/08 22:12:14 INFO DAGScheduler: looking for …Run Code Online (Sandbox Code Playgroud)