我有一个PDF文件,我试图通过Javascript打印它.我试过这个嵌入技巧:无声打印嵌入式PDF 然而,打印功能永远不可用,它总是未定义的.
我用这段代码尝试了Iframe技巧:
function printPDF() {
if(document.getElementById("pdfDocument").contentWindow.document.readyState === "complete") {
document.getElementById("pdfDocument").focus();
document.getElementById("pdfDocument").contentWindow.print();
} else {
setInterval(printPDF(), 1000);
}
}
Run Code Online (Sandbox Code Playgroud)
(pdfDocument是iframe的ID)这会弹出打印对话框,但打印空白页.我希望embed标签的工作方式.但为什么打印功能永远不可用?
关于这个主题的大多数帖子都很老了.什么是最好的HTML5/jQuery方法呢?(或者只是普通的JS)
编辑:
这是embed标签的JS代码:
function printPDF() {
alert(document.getElementById("pdfDocument").print);
//Wait until PDF is ready to print
if (typeof document.getElementById("pdfDocument").print == 'undefined') {
setTimeout(function(){printPDF();}, 1000);
} else {
var x = document.getElementById("pdfDocument");
x.print();
}
}
Run Code Online (Sandbox Code Playgroud)
这每秒都会改变"未定义"."打印"选项永远不可用.有任何想法吗?
我有一个第三方jar,它包含所有实体和映射.我目前在经典的Spring-MVC应用程序中成功使用此jar,但现在我尝试在Spring-Boot应用程序中使用它.(1.5.7.RELEASE)
我有这个用于我的Applicaion.java:
@SpringBootApplication
@EntityScan(basePackages = "com.third.party.entity.package")
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
由于它是第三方,我必须进行会话扫描,所以我在@Configuration类中有这个:
@Bean
public LocalSessionFactoryBean sessionFactory(EntityManagerFactory emf) throws ClassNotFoundException {
LocalSessionFactoryBean fact = new LocalSessionFactoryBean();
fact.setAnnotatedPackages("com.third.party.entity.package");
fact.setPackagesToScan("com.third.party.entity.package");
fact.setDataSource(dataSource);
return fact;
}
Run Code Online (Sandbox Code Playgroud)
这在我的application.properties中:
spring.datasource.url=jdbc:mysql://dbserver:3306/mydb?useSSL=false
spring.datasource.username=user
spring.datasource.password=password
spring.datasource.tomcat.max-wait=20000
spring.datasource.tomcat.max-active=50
spring.datasource.tomcat.max-idle=20
spring.datasource.tomcat.min-idle=15
spring.jpa.properties.hibernate.dialect =org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.id.new_generator_mappings = false
spring.jpa.properties.hibernate.format_sql = true
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'mydb.user' doesn't exist
Run Code Online (Sandbox Code Playgroud)
现在表名是"用户",所以这样才有意义.但是,我正在将此jar用于其他应用程序,因此关于此主题的所有其他100个答案都不适用.
它必须是一个配置问题?对?
更新 我尝试下面的@sam答案无济于事,但我能够看到这个第三方jar文件的源代码,它看起来像这样:
@Entity
@Table(name = "User")
public class User {
etc... …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Spring Boot,并创建一个jar,并将其安装到我的maven repo中.
这是一个库jar文件,将在我的主应用程序中用作依赖项,它也是一个Spring-Boot应用程序.现在,我正在研究一个问候世界的例子.这是我在这个项目中的一个类:
public class MyLibrary {
public String getMessage() {
return "Hello World!";
}
}
Run Code Online (Sandbox Code Playgroud)
而我的POM基本上是这样的:
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<groupId>com.me.plugin</groupId>
<artifactId>myLibrary</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
但是当我尝试构建时,我得到"无法找到主类"错误.这对我来说非常有意义,但是如何让spring生成库jar.我知道我可以使用main方法添加Application.java ,但这不是我想要的,我想要一个简单的jar文件,但是所有的Spring-Boot注释,注入等......
我该怎么做呢?春季靴子不是我想要的吗?
我已经实现了jQuery-ui tabs小部件,它工作得很好.但是,它做了一些我不喜欢的风格.特别是.ui-corner-all是圆形的,我不希望这样.
什么是"正确"的方式来覆盖这个.我应该使用主题吗?
有人有关于如何使用/创建ui主题的初学者教程吗?
我在工作中获得了一个web项目,其中包含.eslintrc文件并被告知要使用它.
我认为这会强制执行代码样式并听起来像个好主意,但我以前从未这样做过.
我刚刚切换到Eclipse Neon.但是我找不到关于如何使用它的教程.我确实找到了一些东西,说eslint现在是Eclipse的默认linter,但那是Orion.有人能告诉我如何将我的.eslintrc文件用于Eclipse中的所有.js文件吗?
我有一个带有Spring Security的JSP.我有一个简单的标签,确定用户是否有这样的ADMIN角色:
<sec:authorize access="hasRole('ADMIN')">
Run Code Online (Sandbox Code Playgroud)
并且工作正常.我现在正试图在整个站点中实现许多角色,所以我有一个UserAccess静态字符串的类作为我所有角色的常量.所以我试试这个:
<sec:authorize access="hasRole(UserAccess.ADMIN)">
Run Code Online (Sandbox Code Playgroud)
但这是投掷:
Field or property 'UserAccess' cannot be found on object of type
'org.springframework.security.web.access.expression.WebSecurityExpressionRoot'
Run Code Online (Sandbox Code Playgroud)
该类位于类路径中,我可以使用<% .. %>等
方式访问它... 处理此问题的最佳方法是什么?
我有这个 Hibernate/JPA 代码:
List<User> users = getEntityManager().createQuery("from com.xxx.xxx.persistence.model.User where name = :userName")
.setParameter("userName", name.toLowerCase())
.getResultList();
Run Code Online (Sandbox Code Playgroud)
但我收到此异常:
java.lang.IllegalArgumentException: Parameter with that name [userName] did not exist
at org.hibernate.jpa.spi.BaseQueryImpl.findParameterRegistration(BaseQueryImpl.java:487)
at org.hibernate.jpa.spi.BaseQueryImpl.setParameter(BaseQueryImpl.java:638)
at org.hibernate.jpa.spi.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:163)
at org.hibernate.jpa.spi.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:32)
Run Code Online (Sandbox Code Playgroud)
如果我在 SQL 中对 userName 进行硬编码,删除 setParamter,它就可以工作。怎么了?
所以我有一个正在尝试升级 CXF 和 WSS4J 的工作项目
看起来我已经升级了我的客户端,但那是因为我将其用于 wss4j:
<dependency>
<groupId>org.apache.wss4j</groupId>
<artifactId>wss4j</artifactId>
<version>2.1.8</version>
<type>pom</type>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但我的服务器抛出 ClassNotFound 异常,显然是因为 type=pom.
那么我在哪里可以找到新的类 jar 呢?特别是 WSPasswordCallback。
顺便说一句,我正在使用 CXF 3.1.9
我得到这个:
Failed to execute goal on project boot: Could not resolve dependencies for project xxx:boot:jar:1.0.0-SNAPSHOT: Could not find artifact xxx:xxx:jar:1.0.0-SNAPSHOT in central (http://xxx/artifactory/all/) -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
该文物仅在我的本地仓库中。(是的,我可以在那里看到它)Maven 没有恢复。
我看到了很多关于 SO 的想法,但没有一个有效。
我已经尝试过所有的建议:
find ~/.m2/repository -name _maven.repositories -exec rm -v {} \;
find ~/.m2/repository -name _remote.repositories -exec rm -v {} \;
Run Code Online (Sandbox Code Playgroud)
我删除了存储库并重新构建(即 mvn install)所有需要的依赖项。
我添加了
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
Run Code Online (Sandbox Code Playgroud)
到 POM
我尝试过 mvn -o install
我不知道接下来要尝试什么!我在 Ubuntu 16.04 上使用 mvn 3.3.9
所以我有一个完美的Spring应用程序。我的大多数控制器方法都用于ajax调用,这些调用通过具有jackson api的@ResponseBody返回JSON并将Java POJO返回到JSON。
我需要将XML转换为JSON,因此我发现Jackson为此提供了一个工具,并将其添加到POM中以使用该库:
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.9.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
这样我就可以使用:
XmlMapper xmlMapper = new XmlMapper();
JsonNode node = xmlMapper.readTree(sb.toString().getBytes());
Run Code Online (Sandbox Code Playgroud)
但是现在@ResponseBody返回的是XML,而不是JSON。我删除了依赖关系,控制器再次返回JSON。
有办法两者兼得吗?我想要xmlMapper和响应正文中的JSON。