我正在尝试使用 dropwizard 探索 JDBI,我的自定义代码如下。
public interface UserDao {
@SqlQuery("SELECT FROM `t_user` :cond")
@Mapper(UserMapper.class)
List<User> fetch(@Bind("cond") String cond);
}
并尝试使用以下代码调用
Application.getJdbi().onDemand(UserDao.class).fetch("where logon_id="+p.getEmail()+"'");
并得到以下问题
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `t_user` 'where logon_id=sanjaypatel2525@gmail.com\''' at line 1
我收到引号问题,因为这是作为字符串传递的。通过这种方式,我试图为所有查询实现通用的 where 子句代码。我的问题是 1. 如何解决这个问题。2. 这样编码是否合适,或者我们可以使用准备好的语句。如果是,那么如何。
非常感谢提前:)