Skip to content

Commit

Permalink
配置不拦截静态资源
Browse files Browse the repository at this point in the history
  • Loading branch information
dasorb committed Mar 12, 2019
1 parent 8d3089c commit 847ad88
Show file tree
Hide file tree
Showing 24 changed files with 10,082 additions and 36 deletions.
4 changes: 1 addition & 3 deletions .idea/artifacts/remomendedbook_war_exploded.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
## 技术选型
SPRING、MYBATIS、SPRINGMVC
SPRING、MYBATIS、SPRINGMVC

模版引擎:thymeleaf

数据源:druid
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@


<!--功能-->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.11.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/showbook/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ public LoginInterceptor loginInterceptor(){
return new LoginInterceptor();
}

/**
* 注册自定义拦截器
* @param registry
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(loginInterceptor()).addPathPatterns("/login");
}


/**
* 用于设置前缀和后缀
* @return
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/showbook/controller/BookController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public class BookController {
@RequestMapping("/book/{id}")
@ResponseBody
public BookDetail getBook(@PathVariable("id")Integer id, Model model){

//通过路径中的id值,查询到相应书籍,返回对应的信息
BookDetail bookDetail = bookService.queryBookDetail(id);

return bookDetail;
}



public BookService getBookService() {
return bookService;
}
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/com/showbook/controller/HelloWorld.java

This file was deleted.

17 changes: 11 additions & 6 deletions src/main/resources/applicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

<!--使用默认的servlet处理静态资源-->
<mvc:annotation-driven/>
<mvc:default-servlet-handler/>

<context:component-scan base-package="com.*" >
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
Expand Down Expand Up @@ -45,14 +50,14 @@
<property name="statementExecutableSqlLogEnable" value="false" />
</bean>

<!--配置sqlsession-->
<!--配置sqlsession工厂-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<!--加载映射文件-->
<property name="mapperLocations" value="classpath*:mapper/BookDetailMapper.xml"/>
<property name="configLocation" value="classpath:mybatis-config.xml"/><!--全局配置-->
<!--加载映射文件,指定xml文件路径-->
<property name="mapperLocations" value="classpath*:mapper/*.xml"/>
</bean>
<!--接口-->
<!--通过扫描的方式,扫描注册接口-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.showbook.dao"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
Expand Down
14 changes: 13 additions & 1 deletion src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!--启用其他请求方式-->
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!--设置编码-->
<filter>
<filter-name>encodingFilter</filter-name>
Expand All @@ -39,11 +49,13 @@
<param-name>contextConfigLocation</param-name>
<param-value>classpath:dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>



</web-app>
Loading

0 comments on commit 847ad88

Please sign in to comment.