JdbcTemplate中的queryforInt/queryforLong方法在Spring 3.2中已弃用.我无法找出使用这些方法替换现有代码的最佳做法的原因或内容.
一种典型的方法:
int rowCount = jscoreJdbcTemplate.queryForInt(
"SELECT count(*) FROM _player WHERE nameKey = ? AND teamClub = ?",
playerNameKey.toUpperCase(),
teamNameKey.toUpperCase()
);
Run Code Online (Sandbox Code Playgroud)
好的,上面的方法需要重写如下:
Object[] params = new Object[] {
playerNameKey.toUpperCase(),
teamNameKey.toUpperCase()
};
int rowCount = jscoreJdbcTemplate.queryForObject(
"SELECT count(*) FROM _player WHERE nameKey = ? AND teamClub = ?",
params, Integer.class);
Run Code Online (Sandbox Code Playgroud)
显然,这种弃用使JdbcTemplate类更简单(或者它?).QueryForInt总是一种方便的方法(我猜)并且已经存在了很长时间.为什么删除它.结果代码变得更加复杂.
所以我基本上想要使用会话来存储用户名,并检查用户是否登录.如果没有,页面将重定向到登录页面.
我正在使用Node.js,express和couchDB.
这是我到目前为止如何设置我的会话
var MemoryStore = require('connect').session.MemoryStore;
app.use(express.cookieParser());
app.use(express.session({
secret: "keyboard cat",
store: new MemoryStore({
reapInterval: 60000 * 10
})
}));
Run Code Online (Sandbox Code Playgroud)
要在会话中存储内容,我使用以下代码吗?
req.session = {user:name);
Run Code Online (Sandbox Code Playgroud)
所以会话变量似乎在我的登录页面上工作.我成功地将用户的名称存储到会话中但是,当我尝试访问另一个页面上的会话变量时,它会给我错误
Cannot read property 'user' of undefined
Run Code Online (Sandbox Code Playgroud)
我所做的就是:
if (req.session.user){
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种错误?会话不是整个应用程序的全局?或者我在这里完全遗漏了一些东西.
提前致谢!
我不确定什么是使用Spring3将Hibernate会话实例注入DAO类的最佳方法.我没有使用Spring的Hibernate Template支持,所以这里是我在DAO类中的代码.
public void setSessionFactory(SessionFactory sessionFactory){
this.sessionFactory=sessionFactory;
}
public SessionFactory getSessionFactory(){
log.info("Returning a refrence to the session instance");
if(sessionFactory==null){
log.error("Not able to find any associated session");
throw new RuntimeException("Not able to find any associated session");
}
return sessionFactory;
}
Run Code Online (Sandbox Code Playgroud)
下面是将会话注入此方法的代码
<bean id="genericSessionFactory" class="HibernateSessionFactory"
factory-method="getSessionfactory" scope="prototype/>
Run Code Online (Sandbox Code Playgroud)
我不确定这是否是进行SessionFactory注入的最佳方式,因为我们不想在项目中使用Spring Template.所以任何其他改进建议都会有所帮助.
我有一些不同的SELECT查询具有相同的值.我想使用类似DECLARE的东西,但是当我写一个简单的DECLARE时,它说"INTO"是预期的.
如果我只想要一个"SELECT",我怎么能用"INTO"这个表格?
我只有两个(或更多)选择:
SELECT * FROM my_table1 WHERE column1=5 and column2=6;
Run Code Online (Sandbox Code Playgroud)
和
SELECT * FROM my_table2 WHERE col1=5 and col2=6;
Run Code Online (Sandbox Code Playgroud)
现在我想声明一个像var_col1和var_col2这样的变量,并在两个select查询中同时使用它们.
我认为这会奏效:
DECLARE
var_col1 number := 5;
var_vol2 number := 6;
BEGIN
SELECT * FROM my_table1 WHERE column1=var_col1 and column2=var_col2;
SELECT * FROM my_table2 WHERE col1=var_col1 and col2=var_col1;
/* and more SELECTs with var_col1 and var_col2 */
END;
Run Code Online (Sandbox Code Playgroud)
但没有机会......没有程序或功能,如何做到这一点?
我有一个maven spring项目(最新版本),我想写一些junit测试(最新版本).
我的问题是我的spring bean是自动装配的,当我从junit测试中调用它们时,我得到空指针异常,因为spring不会自动装配它们.
如何加载上下文以便自动连接?
我的JFormattedTextField物体上有两个物体JFrame.我希望通过这些JFormattedTextField对象的值得到基本的数学(加法).当焦点丢失第一个或第二个文本字段时,我希望它发生.但是当" focusLost()",事件没有得到最后一个值时,它会得到之前的值.
例如; tf1为tf20,最初为0.我写了2 tf1,当when focusLost()(tf1+tf2)变为0时,当我改变其中任何一个时,结果变为2(前一个值)
如何获取focusLost上的最后一个值?
这是我的代码:
JFormattedTextField tf1,tf2;
NumberFormat format=NumberFormat.getNumberInstance();
tf1=new JFormattedTextField(format);
tf1.addFocusListener(this);
tf2=new JFormattedTextField(format);
tf2.addFocusListener(this);
Run Code Online (Sandbox Code Playgroud)
并且focusLost():
public void focusLost(FocusEvent e) {
if(tf1.getValue() == null) tf1.setValue(0);
if(tf2.getValue() == null) tf2.setValue(0);
//because if I dont set, it throws nullPointerException for tf.getValue()
BigDecimal no1 = new BigDecimal(tf1.getValue().toString());
BigDecimal no2 = new BigDecimal(tf2.getValue().toString());
System.out.println("total: " + (no1.add(no2)));
}
Run Code Online (Sandbox Code Playgroud) 我有一个名为的表person,我希望将列排除为默认值,
const Person = sequelize.define('person',{
secretColumn: Sequelize.STRING,
//... and other columns
});
Run Code Online (Sandbox Code Playgroud)
我看到有一个叫ScopeSequelize 的功能:http://docs.sequelizejs.com/manual/tutorial/scopes.html
我试图像这样排除;
const Person = sequelize.define('person',{
secretColumn: Sequelize.STRING,
//... and other columns
}, {
defaultScope: {
exclude: ['secretColumn']
}
});
Run Code Online (Sandbox Code Playgroud)
但这不起作用.是否还有其他方法可以在默认情况下排除列?
我在我的.NET Web应用程序中使用jQuery DataTables但是如何为一个特定列设置最大宽度,所有其他列应该是自动调整大小的(就像它们现在在我的表中一样)
编辑
DataTables本身正确地完成了它,问题是有一个很长的单词没有空格导致问题
我正在使用一个具有枚举类型的lib,这些类似于consts;
Type.SHORT
Type.LONG
Type.FLOAT
Type.STRING
Run Code Online (Sandbox Code Playgroud)
当我在Eclipse中调试时,我收到一个错误:
No enum const class Type.STR?NG
Run Code Online (Sandbox Code Playgroud)
当我使用土耳其语系统时,工作i>İ有一个问题,但因为这是一个enum const,即使我把每个属性都设置为UTF-8,也没有什么可以让STRING成为Eclipse应该寻找的东西.但它仍然在寻找STRİNG,它无法找到,我无法使用它.我该怎么做?
项目>属性>资源>文本文件编码现在是UTF-8.问题仍然存在
编辑:更多信息可能会提供一些我无法得到的线索; 我正在开发OrientDB.这是我的第一次尝试,所以我不知道问题可能出在OrientDB软件包上.但是我使用了很多其他的库,我从未见过这样的问题.这个包中有一个OType枚举,我只是想连接数据库.
String url = "local:database";
ODatabaseObjectTx db = new ODatabaseObjectTx(url).
Person person = new Person("John");
db.save(person);
db.close();
Run Code Online (Sandbox Code Playgroud)
我还没有更多的代码.创建数据库,但后来我得到java.lang.IllegalArgumentException:
Caused by: java.lang.IllegalArgumentException: No enum const class com.orientechnologies.orient.core.metadata.schema.OType.STR?NG
at java.lang.Enum.valueOf(Unknown Source)
at com.orientechnologies.orient.core.metadata.schema.OType.valueOf(OType.java:41)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLCreateProperty.parse(OCommandExecutorSQLCreateProperty.java:81)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLCreateProperty.parse(OCommandExecutorSQLCreateProperty.java:35)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:43)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:28)
at com.orientechnologies.orient.core.storage.OStorageEmbedded.command(OStorageEmbedded.java:63)
at com.orientechnologies.orient.core.command.OCommandRequestTextAbstract.execute(OCommandRequestTextAbstract.java:63)
at com.orientechnologies.orient.core.metadata.schema.OClassImpl.addProperty(OClassImpl.java:342)
at com.orientechnologies.orient.core.metadata.schema.OClassImpl.createProperty(OClassImpl.java:258)
at com.orientechnologies.orient.core.metadata.security.OSecurityShared.create(OSecurityShared.java:177)
at com.orientechnologies.orient.core.metadata.security.OSecurityProxy.create(OSecurityProxy.java:37)
at com.orientechnologies.orient.core.metadata.OMetadata.create(OMetadata.java:70)
at com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.create(ODatabaseRecordAbstract.java:142)
... 4 more …Run Code Online (Sandbox Code Playgroud)