I try to write if else condition on Entity class but when i run tomcat it's not working. It have an error. I curious to know how to write if else condition in spring roo project? And which file i can write that?
i try to test condition by write:(in 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
And this's errors when i run 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.
The failure indicate that you have an syntax error.
And yes there in an syntax error in line 16.
You can not write an if
statement somewhere into an class, it must be in an method!
@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.
}
}
You should notice, that this Roo classes, are normal Java classes (enhannced by some Roo generated AspectJ files), but this are real classes, but no configuration files.