|
|
|
package web.config;
|
|
|
|
|
|
|
|
import core.dao.BaseDao1;
|
|
|
|
import org.springframework.context.annotation.ComponentScan;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.PropertySource;
|
|
|
|
import org.springframework.http.converter.HttpMessageConverter;
|
|
|
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
|
|
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
|
|
import org.springframework.orm.hibernate5.support.OpenSessionInViewInterceptor;
|
|
|
|
import org.springframework.web.servlet.config.annotation.*;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by reborn on 2017/7/28.
|
|
|
|
*/
|
|
|
|
@Configuration
|
|
|
|
@EnableWebMvc
|
|
|
|
@PropertySource("classpath:config.properties")
|
|
|
|
@ComponentScan({"web.controller","web.service"})
|
|
|
|
|
|
|
|
public class SpringConfig implements WebMvcConfigurer {
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
private BaseDao1 baseDao;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void configureViewResolvers(ViewResolverRegistry registry) {
|
|
|
|
registry.jsp("/WEB-INF/jsp/",".jsp");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
|
|
registry.addResourceHandler("/webjars/**")
|
|
|
|
.addResourceLocations(
|
|
|
|
"classpath:/META-INF/resources/webjars/");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
|
|
OpenSessionInViewInterceptor interceptor=new OpenSessionInViewInterceptor();
|
|
|
|
interceptor.setSessionFactory(baseDao.getSessionFactory());
|
|
|
|
registry.addWebRequestInterceptor(interceptor);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
|
|
|
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
|
|
|
|
builder.indentOutput(true);
|
|
|
|
converters.add(new MappingJackson2HttpMessageConverter(builder.build()));
|
|
|
|
}
|
|
|
|
}
|