比如我查询一个分类我是用编码规范的001是根 001001 001002等是001的子
002是根 002001 002002等是002的子但是我现在用where id=001或者00X去查询表他发出的语句把前面的00省略了不发id=001而是发id=1我数据库的ID用的是vachar类型的,JAVABEAN对应的类也是String类型的这个咋办哦我用的是MYSQL
002是根 002001 002002等是002的子但是我现在用where id=001或者00X去查询表他发出的语句把前面的00省略了不发id=001而是发id=1我数据库的ID用的是vachar类型的,JAVABEAN对应的类也是String类型的这个咋办哦我用的是MYSQL
mysql> select * from t_category where id=1;
+-----+-------+-------------+
| id | title | description |
+-----+-------+-------------+
| 001 | 电脑 | dddddddd |
+-----+-------+-------------+
1 row in setmysql> select * from t_category where id=001;
+-----+-------+-------------+
| id | title | description |
+-----+-------+-------------+
| 001 | 电脑 | dddddddd |
+-----+-------+-------------+
1 row in set
我就奇怪了,直接用数据库查询就能查询出来了。可是用程序却有问题
public Category findCategoryById(String id) {
return (Category) this.getHibernateTemplate().find("from Category c where c.id = "+id ).get(0);
}
传入的数据是id='001'
发的语句Hibernate: select category0_.id as id0_, category0_.DESCRIPTION as DESCRIPT2_0_, category0_.title as title0_ from t_category category0_ where category0_.id=1
数据库能查询的出来,可是程序查询的有问题我想应该是程序的问题了——!谢谢大家,我再调下。