我知道这并不是 Roo 的真正用途,但我打算用 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,将它们添加到 DB,然后计算答案,将其添加到 DB,然后显示响应。如果无法计算答案(例如除以 0),则回滚事务。
这应该很简单,我猜是这样,但是,我不知道如何访问 sessionFactory。这是否隐含在其他东西中,或者我只是做错了什么?
我只是无法做到这一点,还是有其他方法可以做到这一点。这一切都是为了向我的老板演示以展示 Roo 的优势,但我似乎无法理解这一点