我正在通过FileReader读取文件 - 该文件是UTF-8解码的(带有BOM)现在我的问题是:我读取文件并输出一个字符串,但遗憾的是BOM标记也输出了.为什么会这样?
fr = new FileReader(file);
br = new BufferedReader(fr);
String tmp = null;
while ((tmp = br.readLine()) != null) {
String text;
text = new String(tmp.getBytes(), "UTF-8");
content += text + System.getProperty("line.separator");
}
Run Code Online (Sandbox Code Playgroud)
第一行后的输出
?<style>
Run Code Online (Sandbox Code Playgroud) byte[]
我的实体中有一些字段,例如:
@Entity
public class ServicePicture implements Serializable {
private static final long serialVersionUID = 2877629751219730559L;
// seam-gen attributes (you should probably edit these)
@Id
@GeneratedValue
private Long id;
private String description;
@Lob
@Basic(fetch = FetchType.LAZY)
private byte[] picture;
Run Code Online (Sandbox Code Playgroud)
在我的数据库架构上,字段设置为,BLOB
所以这应该没问题.无论如何:每当我尝试插入图片或pdf时 - 没有什么比1mb
这更大,我只接受这个
16:52:27,327 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: 22001
16:52:27,327 ERROR [JDBCExceptionReporter] Data truncation: Data too long for column 'picture' at row 1
16:52:27,328 ERROR [STDERR] javax.persistence.PersistenceException: org.hibernate.exception.DataException: could not insert: [de.ac.dmg.productfinder.entity.ServicePicture]
16:52:27,328 ERROR [STDERR] …
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的抽象类
public abstract class AbstractServiceActions {
@Autowired
protected DatabaseModel dbModel;
protected User user;
protected boolean complete;
protected String serviceResult;
public AbstractServiceActions(User user) {
this.user = user;
this.serviceResult = "";
}
public abstract String doAction();
}
Run Code Online (Sandbox Code Playgroud)
现在您可以看到,我正在尝试自动装配DatabaseModel.但在我的扩展类中,我只接受dbModel的null.
@Component
public class CreateDatabaseAction extends AbstractServiceActions {
....
}
Run Code Online (Sandbox Code Playgroud)
问题:我在这里尝试一些不可能的事吗?
我正在尝试构建此查询
select * from m_orders where year(order_date) = '2010'
Run Code Online (Sandbox Code Playgroud)
字段order_date是DateTime字段.我只是不想在这里使用原始的SQL查询.甚至可以在django quersets中使用例如MySQL函数吗?
我们今天发布了我们的第一个可穿戴应用程序,但遗憾的是这个应用程序没有自动安装.
我们仔细检查了APK和可穿戴式apk,但从未点击过手表.按照http://android-developers.blogspot.de/2014/07/update-on-android-wear-paid-apps.html中的建议手动打包APK 也没有帮助.(我们知道这应该只影响付费应用,但只是为了确定)
还有其他人面临这个问题吗?如果我们通过adb安装APK,该应用程序可以正常运行.
我正在寻找一个html清理程序,我可以根据API调用它来清理我从webapp获取的字符串.是否有一些有用的易用库?有谁知道也许一两个?
我不需要大的东西它必须能够找到未封闭的标签并关闭它们.
我正在尝试使用maven2托管依赖设置一个webapp.这是我的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mtx-production</groupId>
<artifactId>mtx-production</artifactId>
<version>0.0.1</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.0.2.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.2.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.12</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.5.1-Final</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.1-Final</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.8</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>jboss-releases</id>
<url>http://repository.jboss.org/maven2</url>
</repository>
</repositories>
</project>
Run Code Online (Sandbox Code Playgroud)
如果我出错了,请纠正我,但这应该有用吗?!我只是进入了我的日食这个例外
13.06.2010 16:48:15 org.springframework.context.support.AbstractApplicationContext$BeanPostProcessorChecker postProcessAfterInitialization
INFO: Bean 'dataSource' is not eligible …
Run Code Online (Sandbox Code Playgroud) 我主要开发Java EE,现在我需要编写一个小的本机Java应用程序.
但是,我有点迷失,哪些框架(Swing,SWT等)都在那里?其中一个还有一些快速开发吗?也许有人可以提供一些链接或分享他的经验.
我正在将一些我的hql语句迁移到Criterias现在我正在解决一个问题:实体属性是Integer类型但是我需要一个像通配符搜索一样,所以在hql中我做
session.createQuery("from P1 where id like :id").setString("id", "%"+s+"%")
Run Code Online (Sandbox Code Playgroud)
没问题,Hibernate将String转换为Integer.
如果我在Criteria中尝试这个,我只会得到一个ClassCastException
String cannot be cast to Integer
Criteria crit = sessionFactory.getCurrentSession().createCriteria(P1.class);
crit.add(Restrictions.like("id",s)).addOrder(Order.asc("id")).setMaxResults(maxResults);
Run Code Online (Sandbox Code Playgroud)
为什么Hibernate以不同的方式处理这两种情况?
让我先解释一下这个问题我的目标:
我是一个什么样的开发者?我是那个思考问题,编写代码然后自己测试的人.我主要开发网络应用程序,但也有基于UI的项目(RCP/Swing应用程序).我运行我的应用程序并单击此处,测试此...您可能知道这种"风格".
好吧,我是一个试图通过每一行/项目提高自己的人,我希望我的代码/应用程序能够进行实用的测试.我在代码中写 - 我想在代码中测试.
所以我开始使用我的一些类/函数来使用单元测试(junit 4).这适用于没有涉及UI的后端内容 - tbh:我发现很难编写大部分测试.如果我们正在构建一个webapp,可能会与会话或其他东西进行交互.我想你明白了.
我正在寻找的是一些可能带有示例的资源.任何好的书籍建议也会受到欢迎.不要误会我的意思 - 我不想只做逻辑测试的东西,我对测试我的UI感兴趣.
也许这也是一个重要的部分:我用Java开发(85%的时间)和PHP/Python(其余的)
问候