我知道这并不是Roo的真正用途,但我想用Roo制作一个在控制台应用程序中运行的快速演示。
project --topLevelPackage com.xetius.maths
persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY
entity --class ~.domain.Equation --testAutomatically
field number --fieldName firstNum --type java.lang.Integer --notNull
field number --fieldName secondNum --type java.lang.Integer --notNull
field string --fieldName operator --notNull
field number --fieldName answer --type java.lang.Integer
接下来,我想通过添加以下类来添加一个基本控制台
package com.xetius.maths;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MathMain {
public static void main(String[] args) {
ApplicationContext appContext = new ClassPathXmlApplicationContext("applicationContext.xml");
System.out.println("Here");
}
}
我的计划是传入firstNum、operator和secondNum,将它们添加到数据库中,然后计算答案,将其添加到数据库中,然后显示响应。如果无法计算答案(例如除以0),则回滚事务。
这应该很简单,而且我猜它是,但是,我不知道如何访问sessionFactory。这是隐含在别的事情里,还是我只是做错了什么?
我就是做不到,还是有别的办法。这些都是为了给我的老板演示一下Roo的优点,但我似乎没法理解这一点