老师,关联查询报错,貌似说我的查询语句有问题?

来源:4-1 获取多表关联查询结果

CodeMz

2020-03-17 21:40:16

org.apache.ibatis.exceptions.PersistenceException: 

### Error querying database.  Cause: 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 't_goods g, t_category c

        where g.category_id=c.category_id' at line 1

### The error may exist in mappers/goods.xml

### The error may involve defaultParameterMap

### The error occurred while setting parameters

### SQL: select g.* , c.category_name form t_goods g, t_category c         where g.category_id=c.category_id

### Cause: 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 't_goods g, t_category c

        where g.category_id=c.category_id' at line 1

上面时报错信息


<select id="selectGoodsMap" resultType="java.util.Map">
   select g.* , c.category_name form t_goods g, t_category c
   where g.category_id=c.category_id
</select>

这是查询语句代码,用的老师视频里面的


@Test
public void testSelectGoodsMap() throws Exception {
   SqlSession session=null;
   try{
       session=MyBatisUtils.openSession();
       List<Map> list=session.selectList("goods.selectGoodsMap");
       for (Map map:list){
           System.out.println(map);
       }
   }catch (Exception e){
       throw e;
   }finally {
       MyBatisUtils.closeSession(session);
   }
}


这是测试用例的代码,另外确认了数据库连接是对的,表用的源代码导入的,表里面字段category_id也是对的

写回答

1回答

CodeMz

提问者

2020-03-17

找到问题了,不用麻烦老师了!from写成了form,醉了!

0

0 学习 · 8016 问题

查看课程

相似问题

关联查询?

回答 1

关联查询。

回答 1

回答 5