标签:视图解析器 figure 其它 home webconfig rip gen prefix data
web配置
public class SpitterWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override protected Class<?>[] getRootConfigClasses() { return new Class<?>[] { RootConfig.class }; } @Override protected Class<?>[] getServletConfigClasses() { return new Class<?>[] { WebConfig.class }; } @Override protected String[] getServletMappings() { return new String[] { "/" }; } }
视图解析器等
@Configuration @EnableWebMvc @ComponentScan("spittr.web") 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) { // TODO Auto-generated method stub super.addResourceHandlers(registry); } }
控制器
@Controller @RequestMapping("/") public class HomeController { @RequestMapping(method = GET) public String home(Model model) { return "home"; } }
其它配置类
@Configuration @Import(DataConfig.class) @ComponentScan(basePackages = { "spittr" }, excludeFilters = { @Filter(type = FilterType.CUSTOM, value = WebPackage.class) }) public class RootConfig { public static class WebPackage extends RegexPatternTypeFilter { public WebPackage() { super(Pattern.compile("spittr\\.web")); } } }
@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); }
标签:视图解析器 figure 其它 home webconfig rip gen prefix data
原文地址:https://www.cnblogs.com/suheng/p/9222529.html