Mybatis注記を使用する場合は、注記のSQL文字列のスペルに注意してください.


Springbootがmybatisを統合する場合、エラーメッセージ:
Failed to load ApplicationContext
...
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'commentMapper' defined in file [D:\code\springbootCode\chapter03\target\classes\com
anding\mapper\CommentMapper.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: org.apache.ibatis.builder.BuilderException: Could not find value method on SQL annotation. Cause: org.apache.ibatis.builder.BuilderException: Parsing error was found in mapping #{content),#{author}. Check syntax #{property|(expression), var1=value1, var2=value2, ...}

期間中の重要な項目:Check syntax#{property|(expression)、var 1=value 1、var 2=value 2、...}
このヒント:参考ブログを見つけました.エラーは私にそっくりです.リンクは:https://www.cnblogs.com/dream-0916/p/5966429.html
エラーコードは次のとおりです.
@Mapper
public interface CommentMapper {
    @Select("select * from t_comment where id=#{id}")
    public Comment findById(Integer id);

    @Insert("insert into t_comment(content,author,a_id) values(#{content),#{author},#{aId})")
    public int insertComment(Comment comment);

    @Update("update t_comment set content=#{content} where id=#{id}")
    public int updateComment(Comment comment);

    @Delete("delete from t_comment where id=#{id}")
    public int deleteComment(Integer id);
}

エラーの原因は@Insert注記のsql文の作成、#{content)の後ろのカッコが#{}と一致しないため、Check syntax#{property|(expression)、var 1=value 1、var 2=value 2、...}異常が発生します.
今心の中で奔騰しています...また1時間もかかって、もっと複雑な考えでこの文字のスペルを調べて、時間を浪費して、効率が悪いです.
小結:スペルされたSQL文字列、エディタでエラーを提示できない場合は、SQLツールで一度実行してから書くのが望ましい.また、ほとんどの効率的な原因はバグを調べる考え方が壁にぶつかっているため、やり方に従うべきで、最初のステップはまず自分のコードをよくチェックしてから、状況によって分析しなければならない.