提问人:SectionPJY 提问时间:10/3/2023 最后编辑:Zufar SunagatovSectionPJY 更新时间:10/3/2023 访问量:21
在 Spring 项目中,Mybatis SQL 中没有输入任何值
No values are entered into Mybatis SQL in Spring project
问:
我正在与 IntelliJ 合作一个春季项目。
我的 DAO
// Board Insert
public int boardInsert(String rb_uid, String rb_sub, String r_name, String r_address, String rb_contents, int rb_rating) {
System.out.println("===== Board Insert DAO =====");
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("rb_uid", rb_uid);
map.put("rb_sub", rb_sub);
map.put("r_name", r_name);
map.put("r_address", r_address);
map.put("rb_contents", rb_contents);
map.put("rb_rating", rb_rating);
return sqlSession.insert("ResBoardMapper.boardInsert", map);
}
我的 XML
<insert id="boardInsert">
<!-- Duplicate Check -->
INSERT IGNORE
INTO m_restaurant(r_name, r_address)
VALUES(#{r_name }, #{r_address });
<!-- INSERT -->
INSERT INTO m_resboard(rb_rid, rb_uid, rb_sub, rb_rating, rb_contents)
VALUES((SELECT r_id FROM m_restaurant WHERE r_name = #{r_name }), #{rb_uid }, #{rb_sub }, #{rb_ratring }, #{rb_contents });
</insert>
错误
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: ### Error updating database. Cause: java.sql.SQLSyntaxErrorException: (conn:135) 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 'INSERT INTO m_resboard(rb_rid, rb_uid, rb_sub, rb_rating, rb_contents) ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: INSERT IGNORE INTO m_restaurant(r_name, r_address) VALUES(?, ?); INSERT INTO m_resboard(rb_rid, rb_uid, rb_sub, rb_rating, rb_contents) VALUES((SELECT r_id FROM m_restaurant WHERE r_name = ?), ?, ?, ?, ?); ### Cause: java.sql.SQLSyntaxErrorException: (conn:135) 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 'INSERT INTO m_resboard(rb_rid, rb_uid, rb_sub, rb_rating, rb_contents) ; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: (conn:135) 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 'INSERT INTO m_resboard(rb_rid, rb_uid, rb_sub, rb_rating, rb_contents) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) javax.servlet.http.HttpServlet.service(HttpServlet.java:681) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) javax.servlet.http.HttpServlet.service(HttpServlet.java:764) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
在执行查询前检查控制台时,正常插入值。 请告诉我如何解决 BadSqlGrammarException。登录功能运行正常。
答: 暂无答案
评论
allowMultiQueries=true
<insert>