spring boot 的sql插入语句报错是为什么

spring boot 的sql插入语句报错是为什么
数据库都连接了,查了很久也没有解决

img

有时候是开发工具的校验,先看下程序能不能运行

1、优先看数据能不能插入
2、如果能插入看是不是编译器报的错,并不影响

【相关推荐】



  • 建议你看下这篇博客👉 :spring boot 初始化 sql脚本
  • 您还可以看一下 钟林森老师的Java核心技术 典型案例与面试实战系列二(Spring Boot)课程中的 APP应用版本管理之小作业-复杂SQL关联查询小节, 巩固相关知识点
  • 除此之外, 这篇博客: spring boot用注解写sql中的 直接看例子 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:

    1.查

    @Select("select * from users")
    List<Users> AllUser();
    

    2.改

    //注意要加script标签
    @Update("<script> " + "update users" +
                "<set>" + "<if test=\"name != null and name !=''\">name=#{name},</if>" +
                "<if test=\"nickname != null and nickname !=''\">nickname=#{nickname},</if>" +
                "<if test=\"url != null and url !=''\">url=#{url},</if>" +
                "<if test=\"sex != null and sex !=''\">sex=#{sex},</if>" +
                "<if test=\"age !=null and age !=''\">age=#{age},</if>" +
                "<if test=\"password !=null and password !=''\">password=#{password},</if>" +
                "</set>" + "where id=#{id}" +
                " </script> ")
    int updateTest(Users users);
    

    3.增

    @Insert("insert into users (id,name,telephone,nickname,salt,userstate,password,jid,udate)\n" +
                "VALUES(#{id},#{name},#{telephone},#{nickname},#{salt},'01',#{password},'03',now())")
    int in(Users users);
    

    4.删

    @Delete("delete from users where id = #{id}")
    int delete(String id);
    

    5.模糊查询(根据姓名和登记日期模糊查询所有数据)

     
        @Select({"select * from putong_rencai where concat(name,dengji_time) like '%' || 'search_name' || '%' "})
        public List<PuTongUser> selectMohu(@Param("search_name") String search_name);
    
    

    个人觉得这个比mapper.xml要方便一些但是一些复杂的表关系还是不要用了,例如多对多一对多关系这种的


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^

看一下控制层是不是没加@RequestBody注解,导致获取不到参数值,或者是不是表单提交