问题遇到的现象和发生背景 用@Select写语句查询没有问题,语句是对的,就是用eq拼接会有问题存在
问题相关代码,请勿粘贴截图
@Test
void testSelectMyAddr() {
QueryWrapper<UserAddr> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_username","admin");
List<UserAddr> userAddrs = userAddrMapper.selectList(queryWrapper);
System.out.println(userAddrs);
}
运行结果及报错内容
org.springframework.jdbc.BadSqlGrammarException:
Error querying database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-addrs
WHERE (user_username = 'admin')' at line 1
The error may exist in com/ds/mapper/UserAddrMapper.java (best guess)
The error may involve defaultParameterMap
The error occurred while setting parameters
SQL: SELECT addr_id,user_username,addr_type,addrs,created,updated FROM user-addrs WHERE (user_username = ?)
Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-addrs
我的解答思路和尝试过的方法
之前以为是有关键词问题,添加@TableField注解,和这个并没有关系