ssm框架拦截器设置 & 改变数据库表结构 & JavaWeb出现Invalid bound statement (not found)

拦截器:

自己写的拦截器可以通过实现HandlerInterceptor接口或者继承HandlerInterceptorAdapter类来完成

写好拦截器代码之后,需要在你的springmvc.xml中进行配置

<!-- 拦截器 -->
<mvc:interceptors>
    <!-- 按照配置的顺序执行 -->
    <mvc:interceptor>
        <!-- 拦截所有url及url子路径 ,如果不加路径映射,默认对所有请求进行拦截-->
        <mvc:mapping path="/**"/>
        <bean class="com.interceptor.EachPageInterceptor"></bean>
    </mvc:interceptor>
</mvc:interceptors> 

 

 

 

查看数据库表结构:

desc 表名;

 

修改表结构:

mysql> show create table person;
| person | CREATE TABLE `person` (
  `number` int(11) DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
  `birthday` date DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 

删除列:
ALTER TABLE person DROP COLUMN birthday; 

添加列:
ALTER TABLE person ADD COLUMN birthday datetime;

修改列,把number修改为bigint:
ALTER TABLE person MODIFY number BIGINT NOT NULL;

把number修改为id,类型为bigint:
ALTER TABLE person CHANGE number id BIGINT;

添加主键:
ALTER TABLE person ADD PRIMARY KEY (id);

删除主键:
ALTER TABLE person DROP PRIMARY KEY;

添加唯一索引:
ALTER TABLE person ADD UNIQUE name_unique_index (`name`);
为name这一列创建了唯一索引,索引的名字是name_unique_index.

添加普通索引:
ALTER TABLE person ADD INDEX birthday_index (`birthday`);
 

删除索引:
ALTER TABLE person DROP INDEX birthday_index;
ALTER TABLE person DROP INDEX name_unique_index;

1,为当前已有的表添加新的字段

alter table student add studentName varchar(20) not null;

2,为当前已有的表中的字段设置为主键自增

alter table student add constraint PK_studentId primaryKey(studentId);

3,为当前已有的表中的字段设置为外键

alter table student add constraint FK_teacherId_studentInfo foreign key (teacherId) references teacherInfo(teacherId)

alter table 表名 add constraint 键名 foreign key (外键字段名) references 主表名(主表主键名)

4,字段移动位置

alter table student modify studentId varchar(20) first

将student表中的studentId字段的位置移动到第一位

 

JavaWeb出现Invalid bound statement (not found) 

 

其实出现这个问题实质就是mapper接口和mapper.xml文件没有映射起来。
常见的错误如下:
1.mapper.xml中的namespace和实际的mapper文件不一致
这个问题其实很好解决,瞪大眼睛,仔仔细细看看,到底对不对应不就好了嘛

 

2.mapper接口中的方法名和mapper.xml中的id标签不一致
这个问题和上个问题解决方法一样,仔细对对嘛,这个再对不出来,面壁思过吧。

 

3.上两步的问题都没有,但是还是不行,可能原因就是,没有构建进去,打开target看看对应的mapper.xml文件在不在

如果不在的话,clean一下,maven项目,然后再启动。

4.pom.xml文件中配置resource,不然mapper.xml文件就会被漏掉!pom.xml的中配置了resource,bug消失了~

 

 

 

 

参考链接:https://blog.csdn.net/weixin_44695793/article/details/107752054

参考链接:https://www.cnblogs.com/Anidot/articles/7666909.html

 

posted @ 2021-06-21 09:54  kongbursi  阅读(111)  评论(0编辑  收藏  举报