我尝试在Entity类上编写if else条件但是当我运行tomcat时它不起作用。它有一个错误。我很想知道如何在spring roo项目中编写if else条件?我可以写哪个文件?
我尝试通过写:(在Student.java中)测试条件
9 @RooJavaBean
10 @RooToString
11 @RooJpaActiveRecord
12 public class Student {
13 private long id;
14 private String name;
15 private Integer age;
16 if(true){} //test if condition
当我运行tomcat时这是错误。
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project tap: Compilation failure: Compilation failure:
[ERROR] Employee.java:[22,1] illegal start of type
[ERROR] Employee.java:[22,4] illegal start of type
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
答案 0 :(得分:0)
失败表示您有语法错误。
是的,第16行的语法错误。
你不能在某个类的某个地方写一个if
语句,它必须在一个方法中!
@RooJavaBean
@RooToString
@RooJpaActiveRecord
public class Student {
private long id;
private String name;
private Integer age;
public void someMethod() {
if(1 == 1){
// if 1 is 1 then do this.
} else {
// if 1 is different to 1 then do this.
}
}
你应该注意到,这个Roo类是普通的Java类(由一些Roo生成的AspectJ文件增强),但这是真正的类,但没有配置文件。