@configuration
@enablewebmvc
@componentscan("com.m24.controller")
public class webconfig extends webmvcconfigureradapter {
@bean
public viewresolver viewresolver() {
internalresourceviewresolver resolver = new internalresourceviewresolver();
resolver.setprefix("/web-inf/views/");
resolver.setsuffix(".jsp");
return resolver;
}
@override
public void configuredefaultservlethandling(defaultservlethandlerconfigurer configurer) {
configurer.enable();
}
@override
public void addresourcehandlers(resourcehandlerregistry registry) {
super.addresourcehandlers(registry);
}
}
此处注意的是使用@enablewebmvc,是springmvc配置类
最后是业务相关配置类
@configuration
@import(dataconfig.class)
@componentscan(basepackages = {"com.m24"},
excludefilters = @filter(type=filtertype.custom, value=rootconfig.webpackage.class))
public class rootconfig {
public static class webpackage extends regexpatterntypefilter {
public webpackage() {
super(pattern.compile("com.m24.controller"));
}
}
}
由于该配置类中使用了h2数据库,所以还需要引入h2的配置类
@import(dataconfig.class)
@configuration
public class dataconfig {
@bean
public datasource datasource() {
return new embeddeddatabasebuilder()
.settype(embeddeddatabasetype.h2)
.addscript("schema.sql")
.build();
}
@bean
public jdbcoperations jdbctemplate(datasource datasource) {
return new jdbctemplate(datasource);
}
}
问题小结
1、提供数据库插入语句时,正确的是
insert into user values(10001, 'mvc', '123456', 'm', 'vc', 'mvc@m24.com');
在开始时使用双引号,后台出现未识别列的的错误,经查找