我正在尝试解组我的xml文件:
public Object convertFromXMLToObject(String xmlfile) throws IOException {
FileInputStream is = null;
File file = new File(String.valueOf(this.getClass().getResource("xmlToParse/companies.xml")));
try {
is = new FileInputStream(file);
return getUnmarshaller().unmarshal(new StreamSource(is));
} finally {
if (is != null) {
is.close();
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:java.io.FileNotFoundException:null(没有这样的文件或目录)
这是我的结构:
为什么我无法从资源文件夹中获取文件?谢谢.
更新.
重构后,
URL url = this.getClass().getResource("/ xmlToParse/companies.xml"); 文件文件=新文件(url.getPath());
我可以更清楚地看到错误:
java.io.FileNotFoundException:/content/ROOT.war/WEB-INF/classes/xmlToParse/companies.xml(没有这样的文件或目录)
它试图找到WEB-INF/classes /我在那里添加了文件夹,但仍然收到此错误:(
我尝试生成查询类型类(例如QUser)但出现错误...
你可以在这里找到我的源代码:https : //github.com/TheNakedMan/remindme.server/
我正在使用 IntelliJ IDEA,似乎我有工作插件。请帮帮我。
日志消息:
/remindme.server/src/main/java/com/qoobico/remindme/server/repository/UserRepository.java 错误:(21, 126) java:找不到符号符号:类QUser
错误:(25, 62)java:找不到符号符号:类QUser
位置:接口com.qoobico.remindme.server.repository.UserRepository
更新:
之后LifeCycle->clean和运行apt:process中的IntelliJ,我有这样的错误:
[错误] 无法在项目 com.qoobico.remindme.server 上执行目标:无法解析项目 com.qoobico.remindme.server:com.qoobico.remindme.server:war:1.0-SNAPSHOT: 找不到工件 com 的依赖项.qoobico.remindme.server:com.qoobico.remindme.server:jar:1.0-SNAPSHOT
这是我的实体:
@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "name")
private String name;
@Column(name = "surname")
private String surname;
@ManyToOne(fetch = FetchType.LAZY, cascade=CascadeType.MERGE)
@JoinColumn(name = "id_city")
private City city;
//...
}
Run Code Online (Sandbox Code Playgroud)
在我的存储库中我有:
public interface UserRepository extends JpaRepository<User, Long>{
@Query("SELECT u FROM User u JOIN FETCH u.city")
public List<User> findAllUserForApi();
}
Run Code Online (Sandbox Code Playgroud)
如果表中有任何城市,findAllUserForApi()则显示有关用户的完整信息:
[{"id":1,"name":"John","surname":"Pillman","city":{"id":1,"name":"New York"}]
Run Code Online (Sandbox Code Playgroud)
如果没有城市,我至少想得到[{"id":1,"name":"John","surname":"Pillman","city":null]
但我什么也没有:[]
请帮帮我。