Skip to content

Commit f5c4869

Browse files
committed
first add
0 parents  commit f5c4869

File tree

132 files changed

+28203
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+28203
-0
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/.settings
2+
3+
/.classpath
4+
/.project
5+
/.mymetadata
6+
/target

pom.xml

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>com.study</groupId>
4+
<artifactId>springsecurity01</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<packaging>war</packaging>
7+
8+
<properties>
9+
<!-- spring版本号 -->
10+
<spring.version>4.3.5.RELEASE</spring.version>
11+
<!-- log4j日志文件管理包版本 -->
12+
<slf4j.version>1.7.7</slf4j.version>
13+
<log4j.version>1.2.17</log4j.version>
14+
<springsecurity.version>4.2.1.RELEASE</springsecurity.version>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.springframework</groupId>
20+
<artifactId>spring-webmvc</artifactId>
21+
<version>${spring.version}</version>
22+
</dependency>
23+
24+
<dependency>
25+
<groupId>org.springframework.security</groupId>
26+
<artifactId>spring-security-web</artifactId>
27+
<version>${springsecurity.version}</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.springframework.security</groupId>
31+
<artifactId>spring-security-config</artifactId>
32+
<version>${springsecurity.version}</version>
33+
</dependency>
34+
35+
<dependency>
36+
<groupId>org.springframework.security</groupId>
37+
<artifactId>spring-security-taglibs</artifactId>
38+
<version>${springsecurity.version}</version>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>mysql</groupId>
43+
<artifactId>mysql-connector-java</artifactId>
44+
<version>5.1.27</version>
45+
<type>jar</type>
46+
<scope>compile</scope>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>javax.servlet</groupId>
51+
<artifactId>javax.servlet-api</artifactId>
52+
<version>3.1.0</version>
53+
<scope>provided</scope>
54+
</dependency>
55+
<!-- tomcat jstl -->
56+
<dependency>
57+
<groupId>jstl</groupId>
58+
<artifactId>jstl</artifactId>
59+
<version>1.2</version>
60+
</dependency>
61+
<dependency>
62+
<groupId>javax.servlet</groupId>
63+
<artifactId>jsp-api</artifactId>
64+
<version>2.0</version>
65+
<scope>provided</scope>
66+
</dependency>
67+
68+
69+
<dependency>
70+
<groupId>commons-logging</groupId>
71+
<artifactId>commons-logging</artifactId>
72+
<version>1.2</version>
73+
</dependency>
74+
75+
<!-- 日志文件管理包 -->
76+
<!-- log start -->
77+
<dependency>
78+
<groupId>log4j</groupId>
79+
<artifactId>log4j</artifactId>
80+
<version>${log4j.version}</version>
81+
</dependency>
82+
<!-- mybatis核心包 -->
83+
<dependency>
84+
<groupId>org.mybatis</groupId>
85+
<artifactId>mybatis</artifactId>
86+
<version>3.2.8</version>
87+
</dependency>
88+
<!-- mybatis/spring包 -->
89+
<dependency>
90+
<groupId>org.mybatis</groupId>
91+
<artifactId>mybatis-spring</artifactId>
92+
<version>1.2.2</version>
93+
</dependency>
94+
95+
<!--单元测试依赖 -->
96+
<dependency>
97+
<groupId>junit</groupId>
98+
<artifactId>junit</artifactId>
99+
<version>4.12</version>
100+
<scope>test</scope>
101+
</dependency>
102+
103+
<!--spring单元测试依赖 -->
104+
<dependency>
105+
<groupId>org.springframework</groupId>
106+
<artifactId>spring-test</artifactId>
107+
<version>${spring.version}</version>
108+
<scope>test</scope>
109+
</dependency>
110+
<dependency>
111+
<groupId>com.alibaba</groupId>
112+
<artifactId>fastjson</artifactId>
113+
<version>1.2.15</version>
114+
</dependency>
115+
116+
<dependency>
117+
<groupId>com.github.pagehelper</groupId>
118+
<artifactId>pagehelper</artifactId>
119+
<version>4.1.4</version>
120+
</dependency>
121+
122+
</dependencies>
123+
<build>
124+
<plugins>
125+
<!-- define the project compile level -->
126+
<plugin>
127+
<groupId>org.apache.maven.plugins</groupId>
128+
<artifactId>maven-compiler-plugin</artifactId>
129+
<version>2.3.2</version>
130+
<configuration>
131+
<source>1.7</source>
132+
<target>1.7</target>
133+
</configuration>
134+
</plugin>
135+
</plugins>
136+
</build>
137+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.study.config;
2+
3+
import java.util.Properties;
4+
5+
import javax.sql.DataSource;
6+
7+
import org.apache.ibatis.plugin.Interceptor;
8+
import org.apache.ibatis.session.SqlSessionFactory;
9+
import org.apache.log4j.Logger;
10+
import org.mybatis.spring.SqlSessionFactoryBean;
11+
import org.mybatis.spring.mapper.MapperScannerConfigurer;
12+
import org.springframework.beans.factory.annotation.Value;
13+
import org.springframework.context.annotation.Bean;
14+
import org.springframework.context.annotation.Configuration;
15+
import org.springframework.context.annotation.PropertySource;
16+
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
17+
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
18+
import org.springframework.jdbc.datasource.DriverManagerDataSource;
19+
20+
import com.github.pagehelper.PageHelper;
21+
22+
@Configuration
23+
//加载资源文件
24+
@PropertySource({"classpath:jdbc.properties"})
25+
public class DataSourceConfig {
26+
private static final Logger logger = Logger.getLogger(DataSourceConfig.class);
27+
/*
28+
* 绑定资源属性
29+
*/
30+
@Value("${jdbc.driver}")
31+
String driverClass;
32+
@Value("${jdbc.url}")
33+
String url;
34+
@Value("${jdbc.username}")
35+
String userName;
36+
@Value("${jdbc.password}")
37+
String passWord;
38+
39+
@Bean(name = "dataSource")
40+
public DataSource dataSource() {
41+
logger.info("DataSource");
42+
DriverManagerDataSource dataSource = new DriverManagerDataSource();
43+
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
44+
dataSource.setUrl("jdbc:mysql://localhost:3306/mytest?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&failOverReadOnly=false");
45+
dataSource.setUsername("root");
46+
dataSource.setPassword("root");
47+
return dataSource;
48+
}
49+
50+
@Bean
51+
public DataSourceTransactionManager txManager() {
52+
return new DataSourceTransactionManager(dataSource());
53+
}
54+
55+
@Bean
56+
public SqlSessionFactory sqlSessionFactory() throws Exception {
57+
SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
58+
sessionFactory.setDataSource(dataSource());
59+
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
60+
sessionFactory.setMapperLocations(resolver.getResources("classpath:com/study/mapping/*Mapping.xml"));
61+
//配置pageHelper
62+
sessionFactory.setPlugins(new Interceptor[]{pageHelper()});
63+
return sessionFactory.getObject();
64+
}
65+
66+
@Bean
67+
public MapperScannerConfigurer scannerConfigurer(){
68+
MapperScannerConfigurer configurer = new MapperScannerConfigurer();
69+
configurer.setBasePackage("com.study.dao");
70+
configurer.setSqlSessionFactoryBeanName("sqlSessionFactory");
71+
return configurer;
72+
}
73+
/**
74+
* mybatis 分页插件配置
75+
* @return
76+
*/
77+
@Bean
78+
public PageHelper pageHelper() {
79+
System.out.println("MyBatisConfiguration.pageHelper()");
80+
PageHelper pageHelper = new PageHelper();
81+
Properties p = new Properties();
82+
p.setProperty("offsetAsPageNum", "true");
83+
p.setProperty("rowBoundsWithCount", "true");
84+
p.setProperty("reasonable", "true");
85+
pageHelper.setProperties(p);
86+
return pageHelper;
87+
}
88+
89+
}
90+
91+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.study.config;
2+
3+
import org.springframework.context.annotation.ComponentScan;
4+
import org.springframework.context.annotation.ComponentScan.Filter;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.context.annotation.FilterType;
7+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
8+
9+
@Configuration
10+
@ComponentScan(basePackages={"com.study"},excludeFilters={@Filter(type=FilterType.ANNOTATION,value=EnableWebMvc.class)})
11+
public class RootConfig {
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.study.config;
2+
3+
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
4+
/**
5+
* 配置Delegating-FilterProxy
6+
* 继承AbstractSecurityWebApplicationInitializer会自动注册DelegatingFilterProxy
7+
* 等价于xml配置
8+
* <filter>
9+
<filter-name>springSecurityFilterChain</filter-name>
10+
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
11+
</filter>
12+
*
13+
*
14+
*/
15+
public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer{
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.study.config;
2+
3+
import java.util.List;
4+
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.ComponentScan;
7+
import org.springframework.context.annotation.Configuration;
8+
import org.springframework.http.converter.HttpMessageConverter;
9+
import org.springframework.web.servlet.ViewResolver;
10+
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
11+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
12+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
13+
import org.springframework.web.servlet.view.InternalResourceViewResolver;
14+
import org.springframework.web.servlet.view.JstlView;
15+
16+
import com.alibaba.fastjson.serializer.SerializerFeature;
17+
import com.alibaba.fastjson.support.config.FastJsonConfig;
18+
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
19+
20+
@Configuration
21+
@EnableWebMvc
22+
@ComponentScan("com.study.controller")
23+
public class WebConfig extends WebMvcConfigurerAdapter {
24+
25+
@Bean
26+
public ViewResolver viewResolver(){
27+
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
28+
resolver.setPrefix("/jsp/");
29+
resolver.setSuffix(".jsp");
30+
resolver.setExposeContextBeansAsAttributes(true);
31+
resolver.setViewClass(JstlView.class);
32+
return resolver;
33+
}
34+
35+
@Override
36+
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
37+
configurer.enable();
38+
}
39+
40+
/* @Override
41+
public void addResourceHandlers(ResourceHandlerRegistry registry) {
42+
registry.addResourceHandler("/css/**")
43+
.addResourceLocations("classpath:/css");
44+
registry.addResourceHandler("/js/**")
45+
.addResourceLocations("classpath:/js");
46+
registry.addResourceHandler("/img/**")
47+
.addResourceLocations("classpath:/img");
48+
}*/
49+
50+
@Override
51+
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
52+
super.configureMessageConverters(converters);
53+
54+
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
55+
56+
FastJsonConfig fastJsonConfig = new FastJsonConfig();
57+
fastJsonConfig.setSerializerFeatures(
58+
SerializerFeature.PrettyFormat
59+
);
60+
fastConverter.setFastJsonConfig(fastJsonConfig);
61+
62+
converters.add(fastConverter);
63+
}
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.study.config;
2+
3+
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
4+
5+
6+
public class WebProjectConfigInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
7+
8+
/**
9+
* 加载驱动应用后端的中间层和数据层组件
10+
*/
11+
@Override
12+
protected Class<?>[] getRootConfigClasses() {
13+
return new Class[]{RootConfig.class};
14+
}
15+
/** 指定配置类
16+
* 加载包含web组件的bean,如控制机器、视图解析器以及映射处理器
17+
*/
18+
@Override
19+
protected Class<?>[] getServletConfigClasses() {
20+
return new Class[]{WebConfig.class};
21+
}
22+
23+
//将DispatcherServlet 映射到“/”
24+
@Override
25+
protected String[] getServletMappings() {
26+
return new String[] { "/" };
27+
}
28+
29+
30+
}

0 commit comments

Comments
 (0)