1
比方说,我有Swing应用程序,我使用的MyBatis:MyBatis - 如何从swing应用程序设置数据库属性?
public class MyAppCView extends FrameView {
public SqlSession session;
public StaticMapper mapper;
public Config c = new Config();
public MyAppView(SingleFrameApplication app) {
super(app);
String user="root", pswd="root"
session = MyBatisSqlSessionFactory.getSqlSessionFactory().openSession();
mapper = session.getMapper(StaticMapper.class);
MyBatisSqlSessionFactory看起来是这样的:
public class MyBatisSqlSessionFactory {
public static Map<String,String> propeties = new HashMap<String,String>();
protected static final SqlSessionFactory FACTORY;
static {
try {
Properties props = new Properties();
props.setProperty("username", user);
....
// how can i get variables from swing application into configuration of sqlfactory?
Reader reader = Resources.getResourceAsReader("wsnscc/mybatis/xml/Configuration.xml");
FACTORY = new SqlSessionFactoryBuilder().build(reader,props);
} catch (Exception e){
throw new RuntimeException("Fatal Error. Cause: " + e, e);
}
}
public static SqlSessionFactory getSqlSessionFactory() {
return FACTORY;
}
}
如何我可以从Swing应用程序变量纳入sqlfactory的配置?
感谢您的任何建议。