├── .gitignore ├── README.md ├── RegisterDemo ├── .classpath ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.core.runtime.prefs │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ ├── org.eclipse.wst.jsdt.ui.superType.name │ └── org.eclipse.wst.validation.prefs ├── pom.xml ├── register.sql ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── dragon │ │ │ ├── dao │ │ │ ├── UserDao.java │ │ │ └── impl │ │ │ │ └── UserDaoImpl.java │ │ │ ├── model │ │ │ └── User.java │ │ │ ├── service │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ │ └── UserServiceImpl.java │ │ │ ├── servlet │ │ │ ├── ActiveServlet.java │ │ │ └── RegisterServlet.java │ │ │ └── util │ │ │ ├── CodeUtil.java │ │ │ ├── DBUtil.java │ │ │ └── MailUtil.java │ │ ├── resources │ │ └── c3p0-config.xml │ │ └── webapp │ │ ├── WEB-INF │ │ └── web.xml │ │ ├── fail.jsp │ │ ├── index.jsp │ │ ├── result.jsp │ │ └── welcome.jsp └── target │ ├── classes │ ├── c3p0-config.xml │ └── com │ │ └── dragon │ │ ├── dao │ │ ├── UserDao.class │ │ └── impl │ │ │ └── UserDaoImpl.class │ │ ├── model │ │ └── User.class │ │ ├── service │ │ ├── UserService.class │ │ └── impl │ │ │ └── UserServiceImpl.class │ │ ├── servlet │ │ ├── ActiveServlet.class │ │ └── RegisterServlet.class │ │ └── util │ │ ├── CodeUtil.class │ │ ├── DBUtil.class │ │ ├── MailUtil$1.class │ │ └── MailUtil.class │ ├── m2e-wtp │ └── web-resources │ │ └── META-INF │ │ ├── MANIFEST.MF │ │ └── maven │ │ └── com.dragon │ │ └── RegisterDemo │ │ ├── pom.properties │ │ └── pom.xml │ └── maven-status │ └── maven-compiler-plugin │ └── compile │ └── default-compile │ ├── createdFiles.lst │ └── inputFiles.lst ├── cg ├── ReadMe.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── scut │ │ │ └── legend │ │ │ └── cg │ │ │ ├── controller │ │ │ ├── UserController.java │ │ │ └── exception │ │ │ │ └── DefaultExceptionHandler.java │ │ │ ├── dao │ │ │ └── UserDao.java │ │ │ ├── po │ │ │ └── User.java │ │ │ ├── realm │ │ │ └── UserRealm.java │ │ │ └── service │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ └── UserServiceImpl.java │ ├── resources │ │ ├── cache │ │ │ └── ehcache.xml │ │ ├── jdbc.properties │ │ ├── logback.xml │ │ ├── mapper │ │ │ └── User.xml │ │ ├── mybatis-config.xml │ │ └── spring │ │ │ ├── spring-dao.xml │ │ │ ├── spring-service.xml │ │ │ ├── spring-shiro.xml │ │ │ └── spring-web.xml │ └── webapp │ │ ├── WEB-INF │ │ ├── jsp │ │ │ ├── index.jsp │ │ │ ├── login.jsp │ │ │ └── unauthorized.jsp │ │ ├── sql │ │ │ └── 20170617cg.sql │ │ └── web.xml │ │ ├── index.jsp │ │ ├── login.jsp │ │ └── static │ │ └── js │ │ └── lib │ │ └── jquery.min.js │ └── test │ └── java │ └── cg │ └── TestPath.java ├── note ├── git.txt └── maven.txt ├── seckill ├── .idea │ ├── .name │ ├── artifacts │ │ ├── seckill_war.xml │ │ └── seckill_war_exploded.xml │ ├── compiler.xml │ ├── copyright │ │ └── profiles_settings.xml │ ├── dataSources.ids │ ├── dataSources.local.xml │ ├── dataSources.xml │ ├── encodings.xml │ ├── libraries │ │ ├── Maven__aopalliance_aopalliance_1_0.xml │ │ ├── Maven__c3p0_c3p0_0_9_1_2.xml │ │ ├── Maven__ch_qos_logback_logback_classic_1_1_2.xml │ │ ├── Maven__ch_qos_logback_logback_core_1_1_2.xml │ │ ├── Maven__com_dyuproject_protostuff_protostuff_api_1_0_8.xml │ │ ├── Maven__com_dyuproject_protostuff_protostuff_collectionschema_1_0_8.xml │ │ ├── Maven__com_dyuproject_protostuff_protostuff_core_1_0_8.xml │ │ ├── Maven__com_dyuproject_protostuff_protostuff_runtime_1_0_8.xml │ │ ├── Maven__com_fasterxml_jackson_core_jackson_annotations_2_8_0.xml │ │ ├── Maven__com_fasterxml_jackson_core_jackson_core_2_8_5.xml │ │ ├── Maven__com_fasterxml_jackson_core_jackson_databind_2_8_5.xml │ │ ├── Maven__commons_collections_commons_collections_3_2_1.xml │ │ ├── Maven__commons_logging_commons_logging_1_2.xml │ │ ├── Maven__javax_servlet_javax_servlet_api_3_1_0.xml │ │ ├── Maven__jstl_jstl_1_2.xml │ │ ├── Maven__junit_junit_4_12.xml │ │ ├── Maven__mysql_mysql_connector_java_5_1_38.xml │ │ ├── Maven__org_apache_commons_commons_pool2_2_4_2.xml │ │ ├── Maven__org_hamcrest_hamcrest_core_1_3.xml │ │ ├── Maven__org_mybatis_mybatis_3_2_8.xml │ │ ├── Maven__org_mybatis_mybatis_spring_1_2_2.xml │ │ ├── Maven__org_slf4j_slf4j_api_1_7_12.xml │ │ ├── Maven__org_springframework_spring_aop_4_1_6_RELEASE.xml │ │ ├── Maven__org_springframework_spring_beans_4_1_6_RELEASE.xml │ │ ├── Maven__org_springframework_spring_context_4_1_6_RELEASE.xml │ │ ├── Maven__org_springframework_spring_core_4_1_6_RELEASE.xml │ │ ├── Maven__org_springframework_spring_expression_4_1_6_RELEASE.xml │ │ ├── Maven__org_springframework_spring_jdbc_4_1_6_RELEASE.xml │ │ ├── Maven__org_springframework_spring_test_4_1_6_RELEASE.xml │ │ ├── Maven__org_springframework_spring_tx_4_1_6_RELEASE.xml │ │ ├── Maven__org_springframework_spring_web_4_1_6_RELEASE.xml │ │ ├── Maven__org_springframework_spring_webmvc_4_1_6_RELEASE.xml │ │ ├── Maven__redis_clients_jedis_2_9_0.xml │ │ └── Maven__taglibs_standard_1_1_2.xml │ ├── misc.xml │ ├── modules.xml │ ├── sqldialects.xml │ ├── uiDesigner.xml │ └── workspace.xml ├── pom.xml ├── seckill.iml ├── src │ ├── main │ │ ├── java │ │ │ └── org │ │ │ │ └── seckill │ │ │ │ ├── dao │ │ │ │ ├── RedisDao.java │ │ │ │ ├── SeckillDao.java │ │ │ │ └── SuccessKilledDao.java │ │ │ │ ├── dto │ │ │ │ ├── Exposer.java │ │ │ │ ├── SeckillExecution.java │ │ │ │ └── SeckillResult.java │ │ │ │ ├── entity │ │ │ │ ├── Seckill.java │ │ │ │ └── SuccessKilled.java │ │ │ │ ├── enums │ │ │ │ └── SeckillStateEnum.java │ │ │ │ ├── exception │ │ │ │ ├── RepeatKillException.java │ │ │ │ ├── SeckillCloseException.java │ │ │ │ └── SeckillException.java │ │ │ │ ├── service │ │ │ │ ├── SeckillService.java │ │ │ │ └── impl │ │ │ │ │ └── SeckillServiceImpl.java │ │ │ │ └── web │ │ │ │ └── SeckillController.java │ │ ├── resources │ │ │ ├── jdbc.properties │ │ │ ├── logback.xml │ │ │ ├── mapper │ │ │ │ ├── SeckillDao.xml │ │ │ │ └── SuccessKilledDao.xml │ │ │ ├── mybatis-config.xml │ │ │ └── spring │ │ │ │ ├── spring-dao.xml │ │ │ │ ├── spring-service.xml │ │ │ │ └── spring-web.xml │ │ ├── sql │ │ │ ├── schema.sql │ │ │ └── seckill.sql │ │ └── webapp │ │ │ ├── WEB-INF │ │ │ ├── jsp │ │ │ │ ├── common │ │ │ │ │ ├── head.jsp │ │ │ │ │ └── tag.jsp │ │ │ │ ├── detail.jsp │ │ │ │ └── list.jsp │ │ │ └── web.xml │ │ │ ├── index.jsp │ │ │ └── resource │ │ │ └── script │ │ │ └── seckill.js │ └── test │ │ └── java │ │ └── org │ │ └── seckill │ │ ├── dao │ │ ├── RedisDaoTest.java │ │ ├── SeckillDaoTest.java │ │ └── SuccessKilledDaoTest.java │ │ └── service │ │ └── impl │ │ └── SeckillServiceImplTest.java ├── 架构图.jpg └── 说明 .txt ├── ssh ├── .classpath ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.prefs.xml │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ ├── org.eclipse.wst.jsdt.ui.superType.name │ └── org.eclipse.wst.validation.prefs ├── pom.xml ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── crm │ │ │ ├── controller │ │ │ └── UserController.java │ │ │ ├── dao │ │ │ ├── UserDao.java │ │ │ └── impl │ │ │ │ └── UserDaoImpl.java │ │ │ ├── model │ │ │ └── User.java │ │ │ └── service │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ └── UserServiceImpl.java │ │ ├── resources │ │ ├── applicationContext.xml │ │ ├── ehcache.xml │ │ ├── jdbc.properties │ │ ├── log4j.properties │ │ └── springmvc.xml │ │ └── webapp │ │ ├── WEB-INF │ │ ├── pages │ │ │ ├── fail.jsp │ │ │ └── welcome.jsp │ │ └── web.xml │ │ ├── index.jsp │ │ ├── login.jsp │ │ └── register.jsp └── target │ ├── classes │ ├── applicationContext.xml │ ├── com │ │ └── crm │ │ │ ├── controller │ │ │ └── UserController.class │ │ │ ├── dao │ │ │ ├── UserDao.class │ │ │ └── impl │ │ │ │ └── UserDaoImpl.class │ │ │ ├── model │ │ │ └── User.class │ │ │ └── service │ │ │ ├── UserService.class │ │ │ └── impl │ │ │ └── UserServiceImpl.class │ ├── ehcache.xml │ ├── jdbc.properties │ ├── log4j.properties │ └── springmvc.xml │ ├── m2e-wtp │ └── web-resources │ │ └── META-INF │ │ ├── MANIFEST.MF │ │ └── maven │ │ └── com.dragon │ │ └── ssh │ │ ├── pom.properties │ │ └── pom.xml │ └── maven-status │ └── maven-compiler-plugin │ └── compile │ └── default-compile │ ├── createdFiles.lst │ └── inputFiles.lst └── ssm ├── .classpath ├── .project ├── .settings ├── .jsdtscope ├── org.eclipse.jdt.core.prefs ├── org.eclipse.m2e.core.prefs ├── org.eclipse.wst.common.component ├── org.eclipse.wst.common.project.facet.core.xml ├── org.eclipse.wst.jsdt.ui.superType.container ├── org.eclipse.wst.jsdt.ui.superType.name └── org.eclipse.wst.validation.prefs ├── pom.xml ├── src └── main │ ├── java │ └── com │ │ └── crm │ │ ├── controller │ │ └── UserController.java │ │ ├── dao │ │ └── UserDao.java │ │ ├── mapping │ │ └── user.xml │ │ ├── model │ │ └── User.java │ │ └── service │ │ ├── UserService.java │ │ └── impl │ │ └── UserServiceImpl.java │ ├── resources │ ├── database.properties │ ├── log4j.properties │ ├── spring-mybatis.xml │ └── springmvc.xml │ └── webapp │ ├── WEB-INF │ ├── pages │ │ ├── fail.jsp │ │ └── welcome.jsp │ └── web.xml │ ├── index.jsp │ ├── login.jsp │ └── register.jsp └── target ├── classes ├── com │ └── crm │ │ ├── controller │ │ └── UserController.class │ │ ├── dao │ │ └── UserDao.class │ │ ├── mapping │ │ └── user.xml │ │ ├── model │ │ └── User.class │ │ └── service │ │ ├── UserService.class │ │ └── impl │ │ └── UserServiceImpl.class ├── database.properties ├── log4j.properties ├── spring-mybatis.xml └── springmvc.xml └── m2e-wtp └── web-resources └── META-INF ├── MANIFEST.MF └── maven └── com.scut.sf └── mypoem ├── pom.properties └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Compile class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # Package Files 8 | *.jar 9 | *.war 10 | *.zip 11 | 12 | .settings 13 | **/target 14 | .classpath 15 | .project -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JavaLearning 2 | Some Demo about Java 3 | ## RegisterDemo 4 | 使用JavaMail实现的注册邮箱验证实例 5 | ## ssh 6 | Spring+SpringMVC+Hibernate整合实例(基于Maven) 7 | ## ssm 8 | Spring+SpringMVC+Mybatis整合实例(基于Maven) 9 | ## seckill 10 | SSM+Redis+MySQL构建的秒杀系统 11 | ## note 12 | 一些学习笔记 13 | ## cg 14 | SSM+Shiro整合(基于Maven) -------------------------------------------------------------------------------- /RegisterDemo/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /RegisterDemo/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | RegisterDemo 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.jsdt.core.javascriptValidator 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.common.project.facet.core.builder 20 | 21 | 22 | 23 | 24 | org.eclipse.m2e.core.maven2Builder 25 | 26 | 27 | 28 | 29 | org.eclipse.wst.validation.validationbuilder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.jem.workbench.JavaEMFNature 36 | org.eclipse.wst.common.modulecore.ModuleCoreNature 37 | org.eclipse.jdt.core.javanature 38 | org.eclipse.m2e.core.maven2Nature 39 | org.eclipse.wst.common.project.facet.core.nature 40 | org.eclipse.wst.jsdt.core.jsNature 41 | 42 | 43 | -------------------------------------------------------------------------------- /RegisterDemo/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /RegisterDemo/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/webapp/index.jsp=UTF-8 3 | -------------------------------------------------------------------------------- /RegisterDemo/.settings/org.eclipse.core.runtime.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | line.separator=\r\n 3 | -------------------------------------------------------------------------------- /RegisterDemo/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /RegisterDemo/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /RegisterDemo/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /RegisterDemo/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /RegisterDemo/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /RegisterDemo/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /RegisterDemo/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /RegisterDemo/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.dragon 5 | RegisterDemo 6 | war 7 | 0.0.1-SNAPSHOT 8 | RegisterDemo Maven Webapp 9 | http://maven.apache.org 10 | 11 | 12 | 13 | javaee 14 | javaee-api 15 | 5 16 | test 17 | 18 | 19 | taglibs 20 | standard 21 | 1.1.2 22 | 23 | 24 | 25 | mysql 26 | mysql-connector-java 27 | 5.1.40 28 | 29 | 30 | 31 | c3p0 32 | c3p0 33 | 0.9.1.2 34 | 35 | 36 | 37 | javax.mail 38 | mail 39 | 1.4.7 40 | 41 | 42 | javax.activation 43 | activation 44 | 1.1.1 45 | 46 | 47 | 48 | 49 | RegisterDemo 50 | 51 | 52 | -------------------------------------------------------------------------------- /RegisterDemo/register.sql: -------------------------------------------------------------------------------- 1 | use test1; 2 | drop table user; 3 | create table `user`( 4 | id int(11) primary key auto_increment comment '用户id', 5 | username varchar(255) not null comment '用户名', 6 | email varchar(255) not null comment '用户邮箱', 7 | password varchar(255) not null comment '用户密码', 8 | state int(1) not null default 0 comment '用户激活状态:0表示未激活,1表示激活', 9 | code varchar(255) not null comment '激活码' 10 | )engine=InnoDB default charset=utf8; 11 | 12 | select * from user; 13 | delete from user; -------------------------------------------------------------------------------- /RegisterDemo/src/main/java/com/dragon/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.dragon.dao; 2 | 3 | import com.dragon.model.User; 4 | 5 | public interface UserDao { 6 | 7 | int save(User user); 8 | 9 | int activeUser(String code); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /RegisterDemo/src/main/java/com/dragon/dao/impl/UserDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.dragon.dao.impl; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.SQLException; 6 | 7 | import com.dragon.dao.UserDao; 8 | import com.dragon.model.User; 9 | import com.dragon.util.DBUtil; 10 | 11 | public class UserDaoImpl implements UserDao{ 12 | 13 | @Override 14 | public int save(User user) { 15 | int num=0; 16 | try { 17 | Connection conn=DBUtil.getConnection(); 18 | String sql ="insert into user(username,email,password,state,code) values(?,?,?,?,?)"; 19 | PreparedStatement pstmt=conn.prepareStatement(sql); 20 | pstmt.setString(1, user.getUserName()); 21 | pstmt.setString(2, user.getEmail()); 22 | pstmt.setString(3, user.getPassword()); 23 | pstmt.setInt(4, user.getState()); 24 | pstmt.setString(5, user.getCode()); 25 | num=pstmt.executeUpdate(); 26 | DBUtil.close(conn,pstmt, null); 27 | } catch (SQLException e) { 28 | e.printStackTrace(); 29 | } 30 | return num; 31 | 32 | } 33 | 34 | @Override 35 | public int activeUser(String code) { 36 | int num=0; 37 | try { 38 | Connection conn=DBUtil.getConnection(); 39 | String sql="update user set state=1 where code=?"; 40 | PreparedStatement pstmt=conn.prepareStatement(sql); 41 | pstmt.setString(1, code); 42 | num=pstmt.executeUpdate(); 43 | DBUtil.close(conn,pstmt,null); 44 | } catch (SQLException e) { 45 | e.printStackTrace(); 46 | } 47 | return num; 48 | 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /RegisterDemo/src/main/java/com/dragon/model/User.java: -------------------------------------------------------------------------------- 1 | package com.dragon.model; 2 | 3 | public class User { 4 | private Integer id;// 用户id 5 | private String userName;// 用户名 6 | private String email;// 用户邮箱 7 | private String password;// 用户密码 8 | private Integer state;// 用户账号状态:0表示未激活,1表示激活 9 | private String code;// 激活码 10 | 11 | public User(){ 12 | 13 | } 14 | 15 | public User(String userName, String email, String password, Integer state, String code) { 16 | this.userName = userName; 17 | this.email = email; 18 | this.password = password; 19 | this.state = state; 20 | this.code = code; 21 | } 22 | 23 | public Integer getId() { 24 | return id; 25 | } 26 | 27 | public void setId(Integer id) { 28 | this.id = id; 29 | } 30 | 31 | public String getUserName() { 32 | return userName; 33 | } 34 | 35 | public void setUserName(String userName) { 36 | this.userName = userName; 37 | } 38 | 39 | public String getEmail() { 40 | return email; 41 | } 42 | 43 | public void setEmail(String email) { 44 | this.email = email; 45 | } 46 | 47 | public String getPassword() { 48 | return password; 49 | } 50 | 51 | public void setPassword(String password) { 52 | this.password = password; 53 | } 54 | 55 | public Integer getState() { 56 | return state; 57 | } 58 | 59 | public void setState(Integer state) { 60 | this.state = state; 61 | } 62 | 63 | public String getCode() { 64 | return code; 65 | } 66 | 67 | public void setCode(String code) { 68 | this.code = code; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /RegisterDemo/src/main/java/com/dragon/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.dragon.service; 2 | 3 | 4 | public interface UserService { 5 | 6 | boolean doRegister(String userName, String password, String email); 7 | 8 | boolean activeUser(String code); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /RegisterDemo/src/main/java/com/dragon/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.dragon.service.impl; 2 | 3 | import com.dragon.dao.UserDao; 4 | import com.dragon.dao.impl.UserDaoImpl; 5 | import com.dragon.model.User; 6 | import com.dragon.service.UserService; 7 | import com.dragon.util.CodeUtil; 8 | import com.dragon.util.MailUtil; 9 | 10 | public class UserServiceImpl implements UserService { 11 | 12 | @Override 13 | public boolean doRegister(String userName, String password, String email) { 14 | // 这里可以验证各字段是否为空 15 | 16 | //利用正则表达式(可改进)验证邮箱是否符合邮箱的格式 17 | if(!email.matches("^\\w+@(\\w+\\.)+\\w+$")){ 18 | return false; 19 | } 20 | //生成激活码 21 | String code=CodeUtil.generateUniqueCode(); 22 | User user=new User(userName,email,password,0,code); 23 | //将用户保存到数据库 24 | UserDao userDao=new UserDaoImpl(); 25 | //保存成功则通过线程的方式给用户发送一封邮件 26 | if(userDao.save(user)>0){ 27 | new Thread(new MailUtil(email, code)).start();; 28 | return true; 29 | } 30 | return false; 31 | } 32 | 33 | @Override 34 | public boolean activeUser(String code) { 35 | UserDao userDao=new UserDaoImpl(); 36 | if(userDao.activeUser(code)>0){ 37 | return true; 38 | }else{ 39 | return false; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /RegisterDemo/src/main/java/com/dragon/servlet/ActiveServlet.java: -------------------------------------------------------------------------------- 1 | package com.dragon.servlet; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.ServletException; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | import com.dragon.service.UserService; 11 | import com.dragon.service.impl.UserServiceImpl; 12 | 13 | public class ActiveServlet extends HttpServlet { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | @Override 18 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 19 | String code=request.getParameter("code"); 20 | UserService userService=new UserServiceImpl(); 21 | if(userService.activeUser(code)){ 22 | request.getRequestDispatcher("/welcome.jsp").forward(request, response); 23 | }else{ 24 | request.getRequestDispatcher("/fail.jsp").forward(request, response); 25 | } 26 | } 27 | 28 | @Override 29 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 30 | this.doGet(request, response); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /RegisterDemo/src/main/java/com/dragon/servlet/RegisterServlet.java: -------------------------------------------------------------------------------- 1 | package com.dragon.servlet; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.ServletException; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | import com.dragon.service.UserService; 11 | import com.dragon.service.impl.UserServiceImpl; 12 | 13 | public class RegisterServlet extends HttpServlet { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | @Override 18 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 19 | this.doPost(request, response); 20 | } 21 | 22 | @Override 23 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 24 | String userName=request.getParameter("username"); 25 | String password=request.getParameter("password"); 26 | String email=request.getParameter("email"); 27 | System.out.println(userName+" "+password+" "+email); 28 | UserService userService=new UserServiceImpl(); 29 | 30 | if(userService.doRegister(userName,password,email)){ 31 | request.setAttribute("msg", "注册成功,请登录邮箱激活账号"); 32 | }else{ 33 | request.setAttribute("msg", "注册失败,请检查相关信息"); 34 | } 35 | 36 | request.getRequestDispatcher("/result.jsp").forward(request, response); 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /RegisterDemo/src/main/java/com/dragon/util/CodeUtil.java: -------------------------------------------------------------------------------- 1 | package com.dragon.util; 2 | 3 | import java.util.UUID; 4 | 5 | public class CodeUtil { 6 | //生成唯一的激活码 7 | public static String generateUniqueCode(){ 8 | return UUID.randomUUID().toString().replaceAll("-", ""); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /RegisterDemo/src/main/java/com/dragon/util/DBUtil.java: -------------------------------------------------------------------------------- 1 | package com.dragon.util; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.sql.SQLException; 7 | 8 | import com.mchange.v2.c3p0.ComboPooledDataSource; 9 | 10 | public class DBUtil { 11 | private static ComboPooledDataSource cpds=null; 12 | 13 | static{ 14 | cpds=new ComboPooledDataSource("mysql"); 15 | } 16 | 17 | public static Connection getConnection(){ 18 | Connection connection=null; 19 | try { 20 | connection = cpds.getConnection(); 21 | } catch (SQLException e) { 22 | e.printStackTrace(); 23 | } 24 | return connection; 25 | } 26 | 27 | public static void close(Connection conn,PreparedStatement pstmt,ResultSet rs){ 28 | try { 29 | if(rs!=null){ 30 | rs.close(); 31 | } 32 | if(pstmt!=null){ 33 | pstmt.close(); 34 | } 35 | if(rs!=null){ 36 | rs.close(); 37 | } 38 | } catch (SQLException e) { 39 | e.printStackTrace(); 40 | } 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /RegisterDemo/src/main/java/com/dragon/util/MailUtil.java: -------------------------------------------------------------------------------- 1 | package com.dragon.util; 2 | 3 | import java.util.Properties; 4 | import javax.mail.Authenticator; 5 | import javax.mail.Message; 6 | import javax.mail.PasswordAuthentication; 7 | import javax.mail.Session; 8 | import javax.mail.Transport; 9 | import javax.mail.internet.InternetAddress; 10 | import javax.mail.internet.MimeMessage; 11 | import com.sun.mail.util.MailSSLSocketFactory; 12 | 13 | public class MailUtil implements Runnable { 14 | private String email;// 收件人邮箱 15 | private String code;// 激活码 16 | 17 | public MailUtil(String email, String code) { 18 | this.email = email; 19 | this.code = code; 20 | } 21 | 22 | public void run() { 23 | // 1.创建连接对象javax.mail.Session 24 | // 2.创建邮件对象 javax.mail.Message 25 | // 3.发送一封激活邮件 26 | String from = "xxx@qq.com";// 发件人电子邮箱 27 | String host = "smtp.qq.com"; // 指定发送邮件的主机smtp.qq.com(QQ)|smtp.163.com(网易) 28 | 29 | Properties properties = System.getProperties();// 获取系统属性 30 | 31 | properties.setProperty("mail.smtp.host", host);// 设置邮件服务器 32 | properties.setProperty("mail.smtp.auth", "true");// 打开认证 33 | 34 | try { 35 | //QQ邮箱需要下面这段代码,163邮箱不需要 36 | MailSSLSocketFactory sf = new MailSSLSocketFactory(); 37 | sf.setTrustAllHosts(true); 38 | properties.put("mail.smtp.ssl.enable", "true"); 39 | properties.put("mail.smtp.ssl.socketFactory", sf); 40 | 41 | 42 | // 1.获取默认session对象 43 | Session session = Session.getDefaultInstance(properties, new Authenticator() { 44 | public PasswordAuthentication getPasswordAuthentication() { 45 | return new PasswordAuthentication("xxx@qq.com", "xxx"); // 发件人邮箱账号、授权码 46 | } 47 | }); 48 | 49 | // 2.创建邮件对象 50 | Message message = new MimeMessage(session); 51 | // 2.1设置发件人 52 | message.setFrom(new InternetAddress(from)); 53 | // 2.2设置接收人 54 | message.addRecipient(Message.RecipientType.TO, new InternetAddress(email)); 55 | // 2.3设置邮件主题 56 | message.setSubject("账号激活"); 57 | // 2.4设置邮件内容 58 | String content = "

这是一封激活邮件,激活请点击以下链接

http://localhost:8080/RegisterDemo/ActiveServlet?code=" + code 60 | + "

"; 61 | message.setContent(content, "text/html;charset=UTF-8"); 62 | // 3.发送邮件 63 | Transport.send(message); 64 | System.out.println("邮件成功发送!"); 65 | } catch (Exception e) { 66 | e.printStackTrace(); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /RegisterDemo/src/main/resources/c3p0-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | com.mysql.jdbc.Driver 5 | jdbc:mysql://127.0.0.1:3306/test1?useSSL=false 6 | root 7 | 123456 8 | 9 | 5 10 | 11 | 30 12 | 13 | 20 14 | 15 | 5 16 | 17 | -------------------------------------------------------------------------------- /RegisterDemo/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | registerServlet 7 | com.dragon.servlet.RegisterServlet 8 | 9 | 10 | registerServlet 11 | /register 12 | 13 | 14 | 15 | ActiveServlet 16 | com.dragon.servlet.ActiveServlet 17 | 18 | 19 | ActiveServlet 20 | /ActiveServlet 21 | 22 | 23 | -------------------------------------------------------------------------------- /RegisterDemo/src/main/webapp/fail.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 |

激活失败,请检查激活码!

11 |
12 | 13 | -------------------------------------------------------------------------------- /RegisterDemo/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 | <%String basePath=request.getContextPath(); %> 5 | 6 | 7 | 8 | 注册 9 | 10 | 11 | 12 |

注册页面

13 |
14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
32 | 33 | 34 | -------------------------------------------------------------------------------- /RegisterDemo/src/main/webapp/result.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | 结果页 8 | 9 | 10 | ${msg } 11 | 12 | -------------------------------------------------------------------------------- /RegisterDemo/src/main/webapp/welcome.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | 激活成功 8 | 9 | 10 |

激活成功,请登录!

11 |
12 | 13 | -------------------------------------------------------------------------------- /RegisterDemo/target/classes/c3p0-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | com.mysql.jdbc.Driver 5 | jdbc:mysql://127.0.0.1:3306/test1?useSSL=false 6 | root 7 | 123456 8 | 9 | 5 10 | 11 | 30 12 | 13 | 20 14 | 15 | 5 16 | 17 | -------------------------------------------------------------------------------- /RegisterDemo/target/classes/com/dragon/dao/UserDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/RegisterDemo/target/classes/com/dragon/dao/UserDao.class -------------------------------------------------------------------------------- /RegisterDemo/target/classes/com/dragon/dao/impl/UserDaoImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/RegisterDemo/target/classes/com/dragon/dao/impl/UserDaoImpl.class -------------------------------------------------------------------------------- /RegisterDemo/target/classes/com/dragon/model/User.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/RegisterDemo/target/classes/com/dragon/model/User.class -------------------------------------------------------------------------------- /RegisterDemo/target/classes/com/dragon/service/UserService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/RegisterDemo/target/classes/com/dragon/service/UserService.class -------------------------------------------------------------------------------- /RegisterDemo/target/classes/com/dragon/service/impl/UserServiceImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/RegisterDemo/target/classes/com/dragon/service/impl/UserServiceImpl.class -------------------------------------------------------------------------------- /RegisterDemo/target/classes/com/dragon/servlet/ActiveServlet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/RegisterDemo/target/classes/com/dragon/servlet/ActiveServlet.class -------------------------------------------------------------------------------- /RegisterDemo/target/classes/com/dragon/servlet/RegisterServlet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/RegisterDemo/target/classes/com/dragon/servlet/RegisterServlet.class -------------------------------------------------------------------------------- /RegisterDemo/target/classes/com/dragon/util/CodeUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/RegisterDemo/target/classes/com/dragon/util/CodeUtil.class -------------------------------------------------------------------------------- /RegisterDemo/target/classes/com/dragon/util/DBUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/RegisterDemo/target/classes/com/dragon/util/DBUtil.class -------------------------------------------------------------------------------- /RegisterDemo/target/classes/com/dragon/util/MailUtil$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/RegisterDemo/target/classes/com/dragon/util/MailUtil$1.class -------------------------------------------------------------------------------- /RegisterDemo/target/classes/com/dragon/util/MailUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/RegisterDemo/target/classes/com/dragon/util/MailUtil.class -------------------------------------------------------------------------------- /RegisterDemo/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Built-By: pc 3 | Build-Jdk: 1.8.0_73 4 | Created-By: Maven Integration for Eclipse 5 | 6 | -------------------------------------------------------------------------------- /RegisterDemo/target/m2e-wtp/web-resources/META-INF/maven/com.dragon/RegisterDemo/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Maven Integration for Eclipse 2 | #Sat Mar 04 14:22:35 GMT+08:00 2017 3 | version=0.0.1-SNAPSHOT 4 | groupId=com.dragon 5 | m2e.projectName=RegisterDemo 6 | m2e.projectLocation=D\:\\javaEEd1\\RegisterDemo 7 | artifactId=RegisterDemo 8 | -------------------------------------------------------------------------------- /RegisterDemo/target/m2e-wtp/web-resources/META-INF/maven/com.dragon/RegisterDemo/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.dragon 5 | RegisterDemo 6 | war 7 | 0.0.1-SNAPSHOT 8 | RegisterDemo Maven Webapp 9 | http://maven.apache.org 10 | 11 | 12 | 13 | javaee 14 | javaee-api 15 | 5 16 | test 17 | 18 | 19 | taglibs 20 | standard 21 | 1.1.2 22 | 23 | 24 | 25 | mysql 26 | mysql-connector-java 27 | 5.1.40 28 | 29 | 30 | 31 | c3p0 32 | c3p0 33 | 0.9.1.2 34 | 35 | 36 | 37 | javax.mail 38 | mail 39 | 1.4.7 40 | 41 | 42 | javax.activation 43 | activation 44 | 1.1.1 45 | 46 | 47 | 48 | 49 | RegisterDemo 50 | 51 | 52 | -------------------------------------------------------------------------------- /RegisterDemo/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/RegisterDemo/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst -------------------------------------------------------------------------------- /RegisterDemo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | D:\javaEEd1\RegisterDemo\src\main\java\com\dragon\service\impl\UserServiceImpl.java 2 | D:\javaEEd1\RegisterDemo\src\main\java\com\dragon\util\MailUtil.java 3 | D:\javaEEd1\RegisterDemo\src\main\java\com\dragon\dao\impl\UserDaoImpl.java 4 | D:\javaEEd1\RegisterDemo\src\main\java\com\dragon\dao\UserDao.java 5 | D:\javaEEd1\RegisterDemo\src\main\java\com\dragon\model\User.java 6 | D:\javaEEd1\RegisterDemo\src\main\java\com\dragon\util\DBUtil.java 7 | D:\javaEEd1\RegisterDemo\src\main\java\com\dragon\util\CodeUtil.java 8 | D:\javaEEd1\RegisterDemo\src\main\java\com\dragon\service\UserService.java 9 | D:\javaEEd1\RegisterDemo\src\main\java\com\dragon\servlet\ActiveServlet.java 10 | D:\javaEEd1\RegisterDemo\src\main\java\com\dragon\servlet\RegisterServlet.java 11 | -------------------------------------------------------------------------------- /cg/ReadMe.md: -------------------------------------------------------------------------------- 1 | # 说明文档 2 | ## 环境介绍 3 | Spring+SpringMVC+Mybatis+MySQL+Shiro+Maven 4 | ## 运行过程 5 | ### 1.用eclipse导入 6 | 应该可以看到如下目录结构: 7 | 8 | ![](http://i.imgur.com/f76eI6u.png) 9 | 10 | ### 2.执行SQL脚本 11 | SQL脚本位于webapp->WEB-INF->sql下,该脚本在MySQL5.7上测试通过。 12 | 主要有五张表: 13 | 14 | ![](http://i.imgur.com/HupJjhX.png) 15 | 16 | 由用户、角色和权限之间的关系不难得出这五张表。 17 | 18 | ### 3.修改项目配置 19 | 要修改的主要是jdbc的连接配置,将jdbc.properties对应的属性修改成你本机的属性即可: 20 | 21 | ![](http://i.imgur.com/QoGWzSP.png) 22 | 23 | ### 4.确保Maven已导入相关依赖 24 | 25 | --- 26 | ## 项目演示 27 | 28 | 为方便演示,sql脚本中已有相应数据: 29 | 30 | 有两个用户:admin和user 31 | 32 | admin的role为admin,user的role为user 33 | 34 | role["admin"]具有user:view,user:create,user:update,user:delete四种权限 35 | 36 | role["user"]只拥有user:view的权限 37 | 38 | 39 | Shiro的核心配置如下: 40 | 41 | ![](http://i.imgur.com/ahXALOK.png) 42 | 43 | 接下来进行测试,启动项目,在浏览器中输入: 44 | 45 | ### http://localhost:8080/cg/index 46 | 由于/index配置了authc过滤器,因此用户在未认证之前会跳到loginUrl,也就是[http://localhost:8080/cg/login](http://localhost:8080/cg/login)进行认证: 47 | 48 | ![](http://i.imgur.com/2FYS7za.png) 49 | 50 | 输入正确的用户名跟密码(user/123456)后登录成功,再输入[http://localhost:8080/cg/index](http://localhost:8080/cg/index),正常进入页面: 51 | 52 | 53 | ![](http://i.imgur.com/wm6yDCC.png) 54 | 55 | 此时用户role为user,拥有的权限为user:view,输入:[http://localhost:8080/cg/index2](http://localhost:8080/cg/index2 "http://localhost:8080/cg/index2"),[http://localhost:8080/cg/user](http://localhost:8080/cg/user "http://localhost:8080/cg/user"), 56 | 都可以正常访问,而[http://localhost:8080/cg/admin](http://localhost:8080/cg/admin "http://localhost:8080/cg/admin")则不能访问,由于用户已经登录,所以会跳到unauthorizedUrl即http://localhost:8080/cg/unauthorized,如图: 57 | 58 | 59 | ![](http://i.imgur.com/xp6TkIx.png) 60 | 61 | 注销:[http://localhost:8080/cg/logout](http://localhost:8080/cg/logout "http://localhost:8080/cg/logout") 62 | 之后会跳到登录页面,换成admin/123456登录再验证如上url。 -------------------------------------------------------------------------------- /cg/src/main/java/scut/legend/cg/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package scut.legend.cg.controller; 2 | 3 | import java.util.List; 4 | 5 | import javax.annotation.Resource; 6 | 7 | import org.apache.shiro.SecurityUtils; 8 | import org.apache.shiro.authc.IncorrectCredentialsException; 9 | import org.apache.shiro.authc.UnknownAccountException; 10 | import org.apache.shiro.authc.UsernamePasswordToken; 11 | import org.apache.shiro.authc.credential.PasswordService; 12 | import org.apache.shiro.session.Session; 13 | import org.apache.shiro.subject.Subject; 14 | import org.springframework.stereotype.Controller; 15 | import org.springframework.web.bind.annotation.PathVariable; 16 | import org.springframework.web.bind.annotation.RequestBody; 17 | import org.springframework.web.bind.annotation.RequestMapping; 18 | import org.springframework.web.bind.annotation.RequestMethod; 19 | import org.springframework.web.bind.annotation.RequestParam; 20 | import org.springframework.web.bind.annotation.ResponseBody; 21 | import org.springframework.web.servlet.ModelAndView; 22 | 23 | import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.PrivateKeyResolver; 24 | 25 | import ch.qos.logback.core.net.LoginAuthenticator; 26 | import scut.legend.cg.po.User; 27 | import scut.legend.cg.service.UserService; 28 | 29 | @Controller 30 | public class UserController { 31 | @Resource 32 | private UserService userService; 33 | @Resource 34 | private PasswordService passwordService; 35 | 36 | // @RequestMapping(value="/user") 37 | // @ResponseBody 38 | // public User testUser(@RequestBody User user){ 39 | // System.out.println(user); 40 | // return user; 41 | // } 42 | // 43 | @RequestMapping(value="/user/{id}") 44 | @ResponseBody 45 | public User testList(@PathVariable("id")Integer id){ 46 | User user=userService.getUserById(id); 47 | return user; 48 | } 49 | 50 | @RequestMapping(value="/login",method=RequestMethod.POST) 51 | @ResponseBody 52 | public String login(@RequestBody User user){ 53 | UsernamePasswordToken token=new UsernamePasswordToken(user.getUsername(),user.getPassword()); 54 | try{ 55 | SecurityUtils.getSubject().login(token); 56 | return "success"; 57 | }catch(UnknownAccountException e){ 58 | return "账号不存在"; 59 | }catch(IncorrectCredentialsException e){ 60 | return "密码错误"; 61 | }catch (Exception e) { 62 | return "其他错误"; 63 | } 64 | } 65 | 66 | @RequestMapping(value="/login",method=RequestMethod.GET) 67 | public String login(){ 68 | return "login"; 69 | } 70 | 71 | @RequestMapping(value="/unauthorized") 72 | public String unauthorized(){ 73 | return "unauthorized"; 74 | } 75 | 76 | @RequestMapping(value="/encry") 77 | @ResponseBody 78 | public String encry(@RequestParam(value="password")String password){ 79 | return passwordService.encryptPassword(password); 80 | } 81 | 82 | @RequestMapping(value="/logout") 83 | public ModelAndView logout(){ 84 | SecurityUtils.getSubject().logout(); 85 | return new ModelAndView("login"); 86 | } 87 | 88 | @RequestMapping(value="/index") 89 | @ResponseBody 90 | public String index(){ 91 | return "如果你看到这个页面,说明你已经登录,否则会跳到登录页面"; 92 | } 93 | 94 | @RequestMapping(value="/index2") 95 | @ResponseBody 96 | public String index2(){ 97 | return "如果你看到这个页面,说明你已经登录或者选择了记住我选项"; 98 | } 99 | 100 | @RequestMapping(value="/user") 101 | @ResponseBody 102 | public String getUser(){ 103 | return "role为user的用户才能看到这个页面"; 104 | } 105 | 106 | @RequestMapping(value="/admin") 107 | @ResponseBody 108 | public String getAdmin(){ 109 | return "role为admin的用户才能看到这个页面"; 110 | } 111 | 112 | 113 | @RequestMapping(value="/user/view") 114 | @ResponseBody 115 | public String viewUser(){ 116 | return "拥有user:view权限的用户才能看到这个页面"; 117 | } 118 | 119 | @RequestMapping(value="/user/create") 120 | @ResponseBody 121 | public String createUser(){ 122 | return "拥有user:create权限的用户才能看到这个页面"; 123 | } 124 | 125 | 126 | 127 | } 128 | -------------------------------------------------------------------------------- /cg/src/main/java/scut/legend/cg/controller/exception/DefaultExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package scut.legend.cg.controller.exception; 2 | 3 | import org.apache.shiro.authz.UnauthorizedException; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.web.bind.annotation.ControllerAdvice; 6 | import org.springframework.web.bind.annotation.ExceptionHandler; 7 | import org.springframework.web.bind.annotation.ResponseStatus; 8 | import org.springframework.web.context.request.NativeWebRequest; 9 | import org.springframework.web.servlet.ModelAndView; 10 | 11 | @ControllerAdvice 12 | public class DefaultExceptionHandler { 13 | /** 14 | * 没有权限 异常 15 | */ 16 | @ExceptionHandler({UnauthorizedException.class}) 17 | //@ResponseStatus(HttpStatus.UNAUTHORIZED) 18 | public ModelAndView processUnauthenticatedException(NativeWebRequest request, UnauthorizedException e) { 19 | ModelAndView mv = new ModelAndView(); 20 | mv.addObject("exception", e); 21 | mv.setViewName("unauthorized"); 22 | return mv; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /cg/src/main/java/scut/legend/cg/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package scut.legend.cg.dao; 2 | 3 | import java.util.List; 4 | import java.util.Set; 5 | 6 | import scut.legend.cg.po.User; 7 | 8 | public interface UserDao { 9 | 10 | User getUserById(Integer id); 11 | 12 | User findByUsername(String username); 13 | 14 | List findRoles(String username); 15 | 16 | List findPermissions(String username); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /cg/src/main/java/scut/legend/cg/po/User.java: -------------------------------------------------------------------------------- 1 | package scut.legend.cg.po; 2 | 3 | public class User { 4 | private Integer id; 5 | 6 | private String username; 7 | 8 | private String password; 9 | 10 | public Integer getId() { 11 | return id; 12 | } 13 | 14 | public void setId(Integer id) { 15 | this.id = id; 16 | } 17 | 18 | public String getUsername() { 19 | return username; 20 | } 21 | 22 | public void setUsername(String username) { 23 | this.username = username; 24 | } 25 | 26 | public String getPassword() { 27 | return password; 28 | } 29 | 30 | public void setPassword(String password) { 31 | this.password = password; 32 | } 33 | 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /cg/src/main/java/scut/legend/cg/realm/UserRealm.java: -------------------------------------------------------------------------------- 1 | package scut.legend.cg.realm; 2 | 3 | 4 | import org.apache.shiro.authc.*; 5 | import org.apache.shiro.authz.AuthorizationInfo; 6 | import org.apache.shiro.authz.SimpleAuthorizationInfo; 7 | import org.apache.shiro.realm.AuthorizingRealm; 8 | import org.apache.shiro.subject.PrincipalCollection; 9 | 10 | import scut.legend.cg.po.User; 11 | import scut.legend.cg.service.UserService; 12 | 13 | 14 | public class UserRealm extends AuthorizingRealm { 15 | //Autowired,通过xml文件注入,否则会出错,原因不详 16 | UserService userService; 17 | 18 | 19 | public UserService getUserService() { 20 | return userService; 21 | } 22 | 23 | public void setUserService(UserService userService) { 24 | this.userService = userService; 25 | } 26 | 27 | @Override 28 | protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { 29 | String username = (String)principals.getPrimaryPrincipal(); 30 | 31 | SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo(); 32 | authorizationInfo.setRoles(userService.findRoles(username)); 33 | authorizationInfo.setStringPermissions(userService.findPermissions(username)); 34 | 35 | return authorizationInfo; 36 | } 37 | 38 | @Override 39 | protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { 40 | 41 | String username = (String)token.getPrincipal(); 42 | 43 | User user = userService.findByUsername(username); 44 | 45 | if(user == null) { 46 | throw new UnknownAccountException();//没找到帐号 47 | } 48 | 49 | // if(Boolean.TRUE.equals(user.getLocked())) { 50 | // throw new LockedAccountException(); //帐号锁定 51 | // } 52 | 53 | //交给AuthenticatingRealm使用CredentialsMatcher进行密码匹配,如果觉得人家的不好可以自定义实现 54 | SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo( 55 | user.getUsername(), //用户名 56 | user.getPassword(), 57 | getName() //realm name 58 | ); 59 | return authenticationInfo; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /cg/src/main/java/scut/legend/cg/service/UserService.java: -------------------------------------------------------------------------------- 1 | package scut.legend.cg.service; 2 | 3 | import java.util.Set; 4 | 5 | import scut.legend.cg.po.User; 6 | 7 | public interface UserService { 8 | 9 | User getUserById(Integer id); 10 | 11 | User findByUsername(String username); 12 | 13 | Set findRoles(String username); 14 | 15 | Set findPermissions(String username); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /cg/src/main/java/scut/legend/cg/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package scut.legend.cg.service.impl; 2 | 3 | import java.util.HashSet; 4 | import java.util.List; 5 | import java.util.Set; 6 | 7 | import javax.annotation.Resource; 8 | 9 | import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper; 10 | import org.springframework.stereotype.Service; 11 | 12 | import scut.legend.cg.dao.UserDao; 13 | import scut.legend.cg.po.User; 14 | import scut.legend.cg.service.UserService; 15 | @Service("userService") 16 | public class UserServiceImpl implements UserService{ 17 | @Resource 18 | private UserDao userDao; 19 | 20 | @Override 21 | public User getUserById(Integer id) { 22 | return userDao.getUserById(id); 23 | } 24 | 25 | @Override 26 | public User findByUsername(String username) { 27 | return userDao.findByUsername(username); 28 | } 29 | 30 | @Override 31 | public Set findRoles(String username) { 32 | List roleList = userDao.findRoles(username); 33 | Set roleSet=new HashSet<>(); 34 | for(String role:roleList){ 35 | roleSet.add(role); 36 | } 37 | return roleSet; 38 | } 39 | 40 | @Override 41 | public Set findPermissions(String username) { 42 | List permsList=userDao.findPermissions(username); 43 | Set permsSet=new HashSet<>(); 44 | for(String permission:permsList){ 45 | permsSet.add(permission); 46 | } 47 | return permsSet; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /cg/src/main/resources/cache/ehcache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 23 | 24 | 25 | 32 | 33 | 43 | 51 | 52 | -------------------------------------------------------------------------------- /cg/src/main/resources/jdbc.properties: -------------------------------------------------------------------------------- 1 | driver=com.mysql.jdbc.Driver 2 | url=jdbc:mysql://localhost:3306/cg?useUnicode=true&characterEncoding=utf-8 3 | jdbc.username=root 4 | password=123456 5 | 6 | -------------------------------------------------------------------------------- /cg/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /cg/src/main/resources/mapper/User.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 9 | 10 | 13 | 14 | 20 | 21 | 28 | -------------------------------------------------------------------------------- /cg/src/main/resources/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /cg/src/main/resources/spring/spring-dao.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /cg/src/main/resources/spring/spring-service.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /cg/src/main/resources/spring/spring-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 14 | 17 | 18 | 19 | 20 | 21 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | text/plain;charset=UTF-8 38 | text/html;charset=UTF-8 39 | application/json;charset=UTF-8 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /cg/src/main/webapp/WEB-INF/jsp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 |

Hello World!Sn dragon

11 | 12 | -------------------------------------------------------------------------------- /cg/src/main/webapp/WEB-INF/jsp/login.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <% String path=request.getContextPath(); %> 4 | 5 | 6 | 7 | 8 | Insert title here 9 | 10 | 11 |

登录

12 | 用户名:
13 | 密码:
14 | 15 | 16 | 17 | 18 | 19 | 39 | -------------------------------------------------------------------------------- /cg/src/main/webapp/WEB-INF/jsp/unauthorized.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 |

未授权

11 | 12 | -------------------------------------------------------------------------------- /cg/src/main/webapp/WEB-INF/sql/20170617cg.sql: -------------------------------------------------------------------------------- 1 | DROP DATABASE IF EXISTS `cg`; 2 | CREATE DATABASE `cg`; 3 | USE `cg`; 4 | -- 用户表 5 | DROP TABLE IF EXISTS `user`; 6 | create table `user`( 7 | id INT PRIMARY KEY AUTO_INCREMENT, 8 | username VARCHAR(20) NOT NULL COMMENT '用户名', 9 | password VARCHAR(255) NOT NULL COMMENT '密码' 10 | )ENGINE=InnoDB DEFAULT CHARSET=UTF8; 11 | 12 | INSERT INTO `user` 13 | VALUES 14 | (1,'admin','$shiro1$SHA-512$1$$ujJTh2rta8ItSm/1PYQGxq2GQZXtFEq1yHYhtsIztUi66uaVbfNG7IwX9eoQ817jy8UUeX7X3dMUVGTioLq0Ew=='), 15 | (2,'user','$shiro1$SHA-512$1$$ujJTh2rta8ItSm/1PYQGxq2GQZXtFEq1yHYhtsIztUi66uaVbfNG7IwX9eoQ817jy8UUeX7X3dMUVGTioLq0Ew=='); 16 | 17 | DROP TABLE IF EXISTS `role`; 18 | 19 | CREATE TABLE `role`( 20 | id INT PRIMARY KEY AUTO_INCREMENT, 21 | role_name VARCHAR(100) NOT NULL COMMENT '角色名称', 22 | role_description VARCHAR(100) NULL COMMENT '角色描述' 23 | ) ENGINE=InnoDB DEFAULT CHARSET=UTF8; 24 | 25 | INSERT INTO role 26 | VALUES(1,'admin','超级管理员'),(2,'user','普通用户'); 27 | 28 | DROP TABLE IF EXISTS `user_role`; 29 | CREATE TABLE `user_role`( 30 | id INT PRIMARY KEY AUTO_INCREMENT, 31 | user_id INT NOT NULL, 32 | role_id INT NOT NULL 33 | ) ENGINE=InnoDB DEFAULT CHARSET=UTF8; 34 | 35 | INSERT INTO user_role(user_id,role_id) 36 | VALUES(1,1),(2,2); 37 | 38 | DROP TABLE IF EXISTS `permission`; 39 | CREATE TABLE `permission`( 40 | id INT PRIMARY KEY AUTO_INCREMENT, 41 | permission_name VARCHAR(100) NOT NULL COMMENT '权限名', 42 | permission_description VARCHAR(100) NULL COMMENT '权限描述' 43 | ) ENGINE=InnoDB DEFAULT CHARSET=UTF8; 44 | 45 | INSERT INTO permission 46 | VALUES 47 | (1,'user:view','查看用户信息'), 48 | (2,'user:create','创建用户'), 49 | (3,'user:update','修改用户信息'), 50 | (4,'user:delete','删除用户'); 51 | 52 | DROP TABLE IF EXISTS role_permission; 53 | CREATE TABLE `role_permission`( 54 | id INT PRIMARY KEY AUTO_INCREMENT, 55 | role_id INT NOT NULL, 56 | permission_id INT NOT NULL 57 | ) ENGINE=InnoDB DEFAULT CHARSET=UTF8; 58 | 59 | INSERT INTO `role_permission` 60 | (role_id,permission_id) 61 | VALUES 62 | (1,1),(1,2),(1,3),(1,4), 63 | (2,1); -------------------------------------------------------------------------------- /cg/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | contextConfigLocation 10 | 11 | classpath:spring/spring-dao.xml 12 | classpath:spring/spring-service.xml 13 | classpath:spring/spring-shiro.xml 14 | 15 | 16 | 17 | 18 | 19 | 20 | SpringEncodingFilter 21 | org.springframework.web.filter.CharacterEncodingFilter 22 | 23 | encoding 24 | UTF-8 25 | 26 | 27 | forceEncoding 28 | true 29 | 30 | 31 | 32 | SpringEncodingFilter 33 | /* 34 | 35 | 36 | 37 | 38 | 39 | 40 | org.springframework.web.context.ContextLoaderListener 41 | 42 | 43 | 44 | 45 | 46 | 47 | shiroFilter 48 | org.springframework.web.filter.DelegatingFilterProxy 49 | true 50 | 51 | targetFilterLifecycle 52 | true 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | shiroFilter 61 | /* 62 | 63 | 64 | 65 | dispatcherServlet 66 | 67 | org.springframework.web.servlet.DispatcherServlet 68 | 69 | 70 | contextConfigLocation 71 | classpath:spring/spring-web.xml 72 | 73 | 1 74 | 75 | 76 | dispatcherServlet 77 | 78 | / 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /cg/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /cg/src/main/webapp/login.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <% String path=request.getContextPath(); %> 4 | 5 | 6 | 7 | 8 | Insert title here 9 | 10 | 11 |

登录

12 | 用户名:
13 | 密码:
14 | 15 | 16 | 17 | 18 | 19 | 39 | -------------------------------------------------------------------------------- /cg/src/test/java/cg/TestPath.java: -------------------------------------------------------------------------------- 1 | package cg; 2 | 3 | import org.junit.Test; 4 | 5 | public class TestPath { 6 | 7 | @Test 8 | public void test(){ 9 | System.out.println(System.getProperty("java.io.tmpdir")); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /note/maven.txt: -------------------------------------------------------------------------------- 1 | maven常用命令: 2 | mvn -v 查看maven版本 3 | compile 编译 4 | test 测试 5 | package 打包 6 | 7 | clean 删除target 8 | install 安装jar包到本地仓库中 9 | 10 | archetype插件:用于创建符合Maven规定的目录骨架 11 | 12 | mvn archetype:generate -DgroupId=组织名,公司网址的反写+项目名 13 | -DartifactId=项目名-模块名 14 | -Dversion=版本号 15 | -Dpackage=项目所在包名 16 | -DarchetypeCatalog=internal 17 | 18 | mvn archetype:generate -DarchetypeCatalog=internal按照提示进行选择 19 | 20 | 坐标 21 | 构件 22 | 仓库 23 | 本地仓库和远程仓库 24 | 镜像仓库 25 | 26 | 完整项目构建过程包括: 27 | 清理、编译、测试、打包、集成测试、验证、部署 28 | 29 | Maven生命周期: 30 | 1.clean 清理项目 31 | pre-clean 执行清理前的工作 32 | clean 清理上一次构建的所有工作 33 | post-clean 执行清理后的工作 34 | 2.default 构建项目(最核心) 35 | compile test package install 36 | 3.site 生成项目站点 37 | pre-site 在生成项目站点前要完成的工作 38 | site 生成项目站点文档 39 | post-site 在生成项目站点后要完成的工作 40 | site-deploy 发布生成的站点到服务器上 41 | 42 | clean compile test package install 43 | 44 | 45 | SNAPSHOT快照 46 | alpha 内部测试 47 | beta 公测 48 | Release 稳定 49 | GA 正式上线 50 | 51 | 依赖冲突: 52 | 1.短路优先 53 | 2.路径长度相同时,谁先声明谁优先 54 | -------------------------------------------------------------------------------- /seckill/.idea/.name: -------------------------------------------------------------------------------- 1 | Seckill -------------------------------------------------------------------------------- /seckill/.idea/artifacts/seckill_war.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/target 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /seckill/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /seckill/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /seckill/.idea/dataSources.local.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | master_key 6 | root 7 | imooc.* 8 | imooc.* 9 | 10 | 11 | master_key 12 | root 13 | seckill.* 14 | seckill.* 15 | 16 | 17 | -------------------------------------------------------------------------------- /seckill/.idea/dataSources.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | mysql 6 | true 7 | com.mysql.jdbc.Driver 8 | jdbc:mysql://localhost:3306/imooc 9 | MySQL 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | mysql 20 | true 21 | com.mysql.jdbc.Driver 22 | jdbc:mysql://localhost:3306/seckill 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /seckill/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__aopalliance_aopalliance_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__c3p0_c3p0_0_9_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__ch_qos_logback_logback_classic_1_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__ch_qos_logback_logback_core_1_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__com_dyuproject_protostuff_protostuff_api_1_0_8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__com_dyuproject_protostuff_protostuff_collectionschema_1_0_8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__com_dyuproject_protostuff_protostuff_core_1_0_8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__com_dyuproject_protostuff_protostuff_runtime_1_0_8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_8_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_8_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_8_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__commons_collections_commons_collections_3_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__commons_logging_commons_logging_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__javax_servlet_javax_servlet_api_3_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__jstl_jstl_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__junit_junit_4_12.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__mysql_mysql_connector_java_5_1_38.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__org_apache_commons_commons_pool2_2_4_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__org_mybatis_mybatis_3_2_8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__org_mybatis_mybatis_spring_1_2_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_12.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__org_springframework_spring_aop_4_1_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__org_springframework_spring_beans_4_1_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__org_springframework_spring_context_4_1_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__org_springframework_spring_core_4_1_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__org_springframework_spring_expression_4_1_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__org_springframework_spring_jdbc_4_1_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__org_springframework_spring_test_4_1_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__org_springframework_spring_tx_4_1_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__org_springframework_spring_web_4_1_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__org_springframework_spring_webmvc_4_1_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__redis_clients_jedis_2_9_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/libraries/Maven__taglibs_standard_1_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /seckill/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /seckill/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /seckill/.idea/sqldialects.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /seckill/src/main/java/org/seckill/dao/RedisDao.java: -------------------------------------------------------------------------------- 1 | package org.seckill.dao; 2 | 3 | import com.dyuproject.protostuff.*; 4 | import com.dyuproject.protostuff.runtime.*; 5 | import org.seckill.entity.*; 6 | import org.slf4j.*; 7 | import redis.clients.jedis.*; 8 | 9 | /** 10 | * Created by pc on 2017/3/8. 11 | */ 12 | public class RedisDao { 13 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 14 | private final JedisPool jedisPool; 15 | 16 | private RuntimeSchema schema =RuntimeSchema.createFrom(Seckill.class); 17 | public RedisDao(String ip,int port){ 18 | jedisPool = new JedisPool(ip, port); 19 | } 20 | 21 | public Seckill getSeckill(long seckillId){ 22 | try{ 23 | Jedis jedis=jedisPool.getResource(); 24 | try { 25 | String key="seckill:"+seckillId; 26 | //没有实现内部序列化 27 | //get->byte[]->反序列化->Object(Seckill) 28 | //采用自定义序列化 29 | //protostuff:pojo 30 | byte[] bytes=jedis.get(key.getBytes()); 31 | if(bytes!=null){ 32 | Seckill seckill=schema.newMessage(); 33 | ProtostuffIOUtil.mergeFrom(bytes,seckill,schema); 34 | //seckill被反序列化 35 | return seckill; 36 | } 37 | }finally { 38 | jedis.close(); 39 | } 40 | }catch (Exception e){ 41 | logger.error(e.getMessage(),e); 42 | } 43 | return null; 44 | } 45 | 46 | public String putSeckill(Seckill seckill){ 47 | //set Object(Seckill)->序列化->byte[] 48 | try{ 49 | Jedis jedis=jedisPool.getResource(); 50 | try { 51 | String key="seckill:"+seckill.getSeckillId(); 52 | byte[] bytes=ProtostuffIOUtil.toByteArray(seckill, schema, 53 | LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE)); 54 | //超时缓存 55 | int timeout=60*60; 56 | String result=jedis.setex(key.getBytes(),timeout, bytes); 57 | return result; 58 | }finally { 59 | jedis.close(); 60 | } 61 | }catch (Exception e){ 62 | logger.error(e.getMessage(),e); 63 | } 64 | return null; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /seckill/src/main/java/org/seckill/dao/SeckillDao.java: -------------------------------------------------------------------------------- 1 | package org.seckill.dao; 2 | 3 | import org.apache.ibatis.annotations.*; 4 | import org.seckill.entity.*; 5 | 6 | import java.util.*; 7 | 8 | /** 9 | * Created by pc on 2017/3/5. 10 | */ 11 | public interface SeckillDao { 12 | /**减库存 13 | * @param seckillId 14 | * @param killTime 15 | * @return 影响行数 16 | */ 17 | int reduceNumber(@Param("seckillId") long seckillId,@Param("killTime") Date killTime); 18 | 19 | /**根据id查询秒杀对象 20 | * @param seckillId 21 | * @return 22 | */ 23 | Seckill queryById(long seckillId); 24 | 25 | /**根据偏移量查询秒杀商品列表 26 | * @param offset 27 | * @param limit 28 | * @return 29 | */ 30 | List queryAll(@Param("offset") int offset,@Param("limit") int limit); 31 | 32 | /** 33 | * 使用存储过程执行秒杀 34 | * @param paramMap 35 | */ 36 | void killByProcedure(Map paramMap); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /seckill/src/main/java/org/seckill/dao/SuccessKilledDao.java: -------------------------------------------------------------------------------- 1 | package org.seckill.dao; 2 | 3 | import org.apache.ibatis.annotations.*; 4 | import org.seckill.entity.*; 5 | 6 | /** 7 | * Created by pc on 2017/3/5. 8 | */ 9 | public interface SuccessKilledDao { 10 | /** 11 | * 插入购买明细,可过滤重复 12 | * @param seckillId 13 | * @param userPhone 14 | * @return 15 | */ 16 | int insertSuccessKilled(@Param("seckillId") long seckillId,@Param("userPhone") long userPhone); 17 | 18 | /** 19 | * 根据id查询SuccessKilled,并携带秒杀产品对象实体 20 | * @param seckillId 21 | * @return 22 | */ 23 | SuccessKilled queryByIdWithSeckill(@Param("seckillId") long seckillId,@Param("userPhone") long userPhone); 24 | } 25 | -------------------------------------------------------------------------------- /seckill/src/main/java/org/seckill/dto/Exposer.java: -------------------------------------------------------------------------------- 1 | package org.seckill.dto; 2 | 3 | /** 4 | * 暴露秒杀地址DTO:与业务无关实体 5 | * Created by pc on 2017/3/6. 6 | */ 7 | public class Exposer { 8 | //是否开启秒杀 9 | private boolean exposed; 10 | //一种加密措施 11 | private String md5; 12 | //id 13 | private long seckillId; 14 | //系统当前时间 15 | private long now; 16 | //秒杀开启时间 17 | private long start; 18 | //秒杀结束时间 19 | private long end; 20 | 21 | public Exposer(boolean exposed, String md5, long seckillId) { 22 | this.exposed = exposed; 23 | this.md5 = md5; 24 | this.seckillId = seckillId; 25 | } 26 | 27 | public Exposer(long seckillId,boolean exposed, long now, long start, long end) { 28 | this.seckillId=seckillId; 29 | this.exposed = exposed; 30 | this.now = now; 31 | this.start = start; 32 | this.end = end; 33 | } 34 | 35 | public Exposer(long seckillId, boolean exposed) { 36 | this.seckillId = seckillId; 37 | this.exposed = exposed; 38 | } 39 | 40 | public boolean isExposed() { 41 | return exposed; 42 | } 43 | 44 | public void setExposed(boolean exposed) { 45 | this.exposed = exposed; 46 | } 47 | 48 | public String getMd5() { 49 | return md5; 50 | } 51 | 52 | public void setMd5(String md5) { 53 | this.md5 = md5; 54 | } 55 | 56 | public long getSeckillId() { 57 | return seckillId; 58 | } 59 | 60 | public void setSeckillId(long seckillId) { 61 | this.seckillId = seckillId; 62 | } 63 | 64 | public long getNow() { 65 | return now; 66 | } 67 | 68 | public void setNow(long now) { 69 | this.now = now; 70 | } 71 | 72 | public long getStart() { 73 | return start; 74 | } 75 | 76 | public void setStart(long start) { 77 | this.start = start; 78 | } 79 | 80 | public long getEnd() { 81 | return end; 82 | } 83 | 84 | public void setEnd(long end) { 85 | this.end = end; 86 | } 87 | 88 | @Override 89 | public String toString() { 90 | return "Exposer{" + 91 | "exposed=" + exposed + 92 | ", md5='" + md5 + '\'' + 93 | ", seckillId=" + seckillId + 94 | ", now=" + now + 95 | ", start=" + start + 96 | ", end=" + end + 97 | '}'; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /seckill/src/main/java/org/seckill/dto/SeckillExecution.java: -------------------------------------------------------------------------------- 1 | package org.seckill.dto; 2 | 3 | import org.seckill.entity.*; 4 | import org.seckill.enums.*; 5 | 6 | /** 7 | * 封装秒杀执行后结果 8 | * Created by pc on 2017/3/6. 9 | */ 10 | public class SeckillExecution { 11 | private long seckillId; 12 | //秒杀执行结果状态 13 | private int state; 14 | //状态表示 15 | private String stateInfo; 16 | //秒杀成功对象 17 | private SuccessKilled successKilled; 18 | //成功 19 | public SeckillExecution(long seckillId, SeckillStateEnum stateEnum, SuccessKilled successKilled) { 20 | this.seckillId = seckillId; 21 | this.state = stateEnum.getState(); 22 | this.stateInfo = stateEnum.getStateInfo(); 23 | this.successKilled = successKilled; 24 | } 25 | //失败 26 | public SeckillExecution(long seckillId, SeckillStateEnum stateEnum) { 27 | this.seckillId = seckillId; 28 | this.state = stateEnum.getState(); 29 | this.stateInfo = stateEnum.getStateInfo(); 30 | } 31 | 32 | public long getSeckillId() { 33 | return seckillId; 34 | } 35 | 36 | public void setSeckillId(long seckillId) { 37 | this.seckillId = seckillId; 38 | } 39 | 40 | public int getState() { 41 | return state; 42 | } 43 | 44 | public void setState(int state) { 45 | this.state = state; 46 | } 47 | 48 | public String getStateInfo() { 49 | return stateInfo; 50 | } 51 | 52 | public void setStateInfo(String stateInfo) { 53 | this.stateInfo = stateInfo; 54 | } 55 | 56 | public SuccessKilled getSuccessKilled() { 57 | return successKilled; 58 | } 59 | 60 | public void setSuccessKilled(SuccessKilled successKilled) { 61 | this.successKilled = successKilled; 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return "SeckillExecution{" + 67 | "seckillId=" + seckillId + 68 | ", state=" + state + 69 | ", stateInfo='" + stateInfo + '\'' + 70 | ", successKilled=" + successKilled + 71 | '}'; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /seckill/src/main/java/org/seckill/dto/SeckillResult.java: -------------------------------------------------------------------------------- 1 | package org.seckill.dto; 2 | 3 | /** 4 | * 所有Ajax请求返回类型 5 | * Created by pc on 2017/3/7. 6 | */ 7 | public class SeckillResult { 8 | private boolean success; 9 | private T data; 10 | private String error; 11 | 12 | public SeckillResult( boolean success,T data) { 13 | this.data = data; 14 | this.success = success; 15 | } 16 | 17 | public SeckillResult(boolean success, String error) { 18 | this.success = success; 19 | this.error = error; 20 | } 21 | 22 | public boolean isSuccess() { 23 | return success; 24 | } 25 | 26 | public void setSuccess(boolean success) { 27 | this.success = success; 28 | } 29 | 30 | public T getData() { 31 | return data; 32 | } 33 | 34 | public void setData(T data) { 35 | this.data = data; 36 | } 37 | 38 | public String getError() { 39 | return error; 40 | } 41 | 42 | public void setError(String error) { 43 | this.error = error; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /seckill/src/main/java/org/seckill/entity/Seckill.java: -------------------------------------------------------------------------------- 1 | package org.seckill.entity; 2 | 3 | import java.util.*; 4 | 5 | /** 6 | * Created by pc on 2017/3/5. 7 | */ 8 | public class Seckill { 9 | 10 | private long seckillId; 11 | private String name; 12 | private int number; 13 | private Date createTime; 14 | private Date startTime; 15 | private Date endTime; 16 | 17 | 18 | public long getSeckillId() { 19 | return seckillId; 20 | } 21 | 22 | public void setSeckillId(long seckillId) { 23 | this.seckillId = seckillId; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public int getNumber() { 35 | return number; 36 | } 37 | 38 | public void setNumber(int number) { 39 | this.number = number; 40 | } 41 | 42 | public Date getCreateTime() { 43 | return createTime; 44 | } 45 | 46 | public void setCreateTime(Date createTime) { 47 | this.createTime = createTime; 48 | } 49 | 50 | public Date getStartTime() { 51 | return startTime; 52 | } 53 | 54 | public void setStartTime(Date startTime) { 55 | this.startTime = startTime; 56 | } 57 | 58 | public Date getEndTime() { 59 | return endTime; 60 | } 61 | 62 | public void setEndTime(Date endTime) { 63 | this.endTime = endTime; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return "Seckill{" + 69 | "seckillId=" + seckillId + 70 | ", name='" + name + '\'' + 71 | ", number=" + number + 72 | ", createTime=" + createTime + 73 | ", startTime=" + startTime + 74 | ", endTime=" + endTime + 75 | '}'; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /seckill/src/main/java/org/seckill/entity/SuccessKilled.java: -------------------------------------------------------------------------------- 1 | package org.seckill.entity; 2 | 3 | import java.util.*; 4 | 5 | /** 6 | * Created by pc on 2017/3/5. 7 | */ 8 | public class SuccessKilled { 9 | private long seckillid; 10 | private long userPhone; 11 | private Date createTime; 12 | private short state; 13 | //多对一 14 | private Seckill seckill; 15 | 16 | 17 | public short getState() { 18 | return state; 19 | } 20 | 21 | public void setState(short state) { 22 | this.state = state; 23 | } 24 | 25 | public long getSeckillid() { 26 | return seckillid; 27 | } 28 | 29 | public void setSeckillid(long seckillid) { 30 | this.seckillid = seckillid; 31 | } 32 | 33 | public long getUserPhone() { 34 | return userPhone; 35 | } 36 | 37 | public void setUserPhone(long userPhone) { 38 | this.userPhone = userPhone; 39 | } 40 | 41 | public Date getCreateTime() { 42 | return createTime; 43 | } 44 | 45 | public void setCreateTime(Date createTime) { 46 | this.createTime = createTime; 47 | } 48 | 49 | public Seckill getSeckill() { 50 | return seckill; 51 | } 52 | 53 | public void setSeckill(Seckill seckill) { 54 | this.seckill = seckill; 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return "SuccessKilled{" + 60 | "seckillid=" + seckillid + 61 | ", userPhone=" + userPhone + 62 | ", createTime=" + createTime + 63 | ", state=" + state + 64 | '}'; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /seckill/src/main/java/org/seckill/enums/SeckillStateEnum.java: -------------------------------------------------------------------------------- 1 | package org.seckill.enums; 2 | 3 | /** 4 | * 使用枚举表述常量数据字段 5 | * Created by pc on 2017/3/6. 6 | */ 7 | public enum SeckillStateEnum { 8 | 9 | SUCCESS(1,"秒杀成功"), 10 | END(0,"秒杀结束"), 11 | REPEAT_KILL(-1,"重复秒杀"), 12 | INNER_ERROR(-2,"系统异常"), 13 | DATA_REWRITE(-3,"数据篡改"); 14 | 15 | 16 | private int state; 17 | private String stateInfo; 18 | 19 | SeckillStateEnum(int state, String stateInfo) { 20 | this.state = state; 21 | this.stateInfo = stateInfo; 22 | } 23 | 24 | public int getState() { 25 | return state; 26 | } 27 | 28 | public String getStateInfo() { 29 | return stateInfo; 30 | } 31 | 32 | public static SeckillStateEnum stateOf(int index){ 33 | for(SeckillStateEnum state:values()){ 34 | if(state.getState()==index){ 35 | return state; 36 | } 37 | } 38 | return null; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /seckill/src/main/java/org/seckill/exception/RepeatKillException.java: -------------------------------------------------------------------------------- 1 | package org.seckill.exception; 2 | 3 | 4 | /** 5 | * 重复秒杀异常(运行期异常),Spring声明式事务只支持运行时异常 6 | * Created by pc on 2017/3/6. 7 | */ 8 | public class RepeatKillException extends SeckillException{ 9 | public RepeatKillException(String message){ 10 | super(message); 11 | } 12 | 13 | public RepeatKillException(String message,Throwable cause){ 14 | super(message,cause); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /seckill/src/main/java/org/seckill/exception/SeckillCloseException.java: -------------------------------------------------------------------------------- 1 | package org.seckill.exception; 2 | 3 | 4 | /** 5 | * 秒杀关闭异常 6 | * Created by pc on 2017/3/6. 7 | */ 8 | public class SeckillCloseException extends SeckillException { 9 | public SeckillCloseException(String message) { 10 | super(message); 11 | } 12 | 13 | public SeckillCloseException(String message, Throwable cause) { 14 | super(message, cause); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /seckill/src/main/java/org/seckill/exception/SeckillException.java: -------------------------------------------------------------------------------- 1 | package org.seckill.exception; 2 | 3 | /** 4 | * 秒杀相关异常 5 | * Created by pc on 2017/3/6. 6 | */ 7 | public class SeckillException extends RuntimeException { 8 | public SeckillException(String message) { 9 | super(message); 10 | } 11 | 12 | public SeckillException(String message, Throwable cause) { 13 | super(message, cause); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /seckill/src/main/java/org/seckill/service/SeckillService.java: -------------------------------------------------------------------------------- 1 | package org.seckill.service; 2 | 3 | import org.seckill.dto.*; 4 | import org.seckill.entity.*; 5 | import org.seckill.exception.*; 6 | 7 | import java.util.*; 8 | 9 | /**业务接口:站在使用者(程序员)的角度设计接口 10 | * 三个方面:1.方法定义粒度,方法定义的要非常清楚2.参数,要越简练越好 11 | * 3.返回类型(return 类型一定要友好/或者return异常,我们允许的异常) 12 | */ 13 | public interface SeckillService { 14 | 15 | /** 16 | * 查询全部的秒杀记录 17 | * @return 18 | */ 19 | List getSeckillList(); 20 | 21 | /** 22 | * 查询单个秒杀记录 23 | * @param seckillId 24 | * @return 25 | */ 26 | Seckill getById(long seckillId); 27 | 28 | /** 29 | * 秒杀开始时输出秒杀接口地址, 30 | * 否则输出系统时间和秒杀时间 31 | * @param seckillId 32 | */ 33 | Exposer exposeSeckillUrl(long seckillId); 34 | 35 | /** 36 | * 执行秒杀 37 | * @param seckillId 38 | * @param userPhone 39 | * @param md5 40 | */ 41 | SeckillExecution executeSeckill(long seckillId,long userPhone,String md5) 42 | throws SeckillException,RepeatKillException,SeckillCloseException; 43 | } 44 | -------------------------------------------------------------------------------- /seckill/src/main/resources/jdbc.properties: -------------------------------------------------------------------------------- 1 | driver=com.mysql.jdbc.Driver 2 | url=jdbc:mysql://localhost:3306/seckill?useUnicode=true&characterEncoding=utf-8 3 | jdbc.user=root 4 | password=123456 5 | 6 | -------------------------------------------------------------------------------- /seckill/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /seckill/src/main/resources/mapper/SeckillDao.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 7 | 8 | 9 | UPDATE seckill SET number=number-1 10 | WHERE seckill_id=#{seckillId} 11 | AND start_time <= #{killTime} 12 | AND end_time >=#{killTime} 13 | AND number>0 14 | 15 | 16 | 19 | 20 | 25 | 26 | 27 | 35 | -------------------------------------------------------------------------------- /seckill/src/main/resources/mapper/SuccessKilledDao.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | INSERT ignore INTO success_killed(seckill_id,user_phone,state) 8 | VALUES (#{seckillId},#{userPhone},0) 9 | 10 | 11 | 31 | -------------------------------------------------------------------------------- /seckill/src/main/resources/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /seckill/src/main/resources/spring/spring-dao.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /seckill/src/main/resources/spring/spring-service.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | 20 | -------------------------------------------------------------------------------- /seckill/src/main/resources/spring/spring-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 17 | 18 | 19 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /seckill/src/main/sql/schema.sql: -------------------------------------------------------------------------------- 1 | -- 数据库初始化脚本 2 | -- 创建数据库 3 | DROP Database `seckill`; 4 | CREATE DATABASE `seckill`; 5 | -- 使用数据库 6 | USE `seckill`; 7 | -- 创建表 8 | 9 | CREATE TABLE seckill( 10 | `seckill_id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '商品库存id', 11 | `name` VARCHAR(120) NOT NULL COMMENT '商品名称', 12 | `number` INT NOT NULL COMMENT '库存数量', 13 | `start_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '开始时间',/*第一个TIMESTAMP字段会自动更新,要加上default*/ 14 | `end_time` TIMESTAMP NOT NULL COMMENT '结束时间', 15 | `create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', 16 | PRIMARY KEY (seckill_id), 17 | KEY idx_start_time(start_time), 18 | KEY idx_end_time(end_time) 19 | )ENGINE=InnoDB AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8 COMMENT ='秒杀明细表'; 20 | 21 | -- 初始化数据 22 | insert into seckill(name, number, start_time, end_time) 23 | VALUES 24 | ('1000元秒杀iphone6',100,'2017-03-05 00:00:00','2017-03-06 00:00:00'), 25 | ('500元秒杀ipad2',200,'2017-03-05 00:00:00','2017-03-06 00:00:00'), 26 | ('300元秒杀小米3',300,'2017-03-05 00:00:00','2017-03-06 00:00:00'), 27 | ('200元秒杀红米note',400,'2017-03-05 00:00:00','2017-03-06 00:00:00'); 28 | 29 | -- 秒杀成功明细表 30 | -- 用户登录认证相关的信息 31 | CREATE TABLE `success_killed`( 32 | `seckill_id` BIGINT NOT NULL COMMENT '秒杀商品id', 33 | `user_phone` BIGINT NOT NULL COMMENT '用户手机号', 34 | `state` TINYINT NOT NULL DEFAULT 0 COMMENT '状态标识:-1:无效 0:成功 1:已付款', 35 | `create_time` TIMESTAMP NOT NULL COMMENT '创建时间', 36 | PRIMARY KEY (seckill_id,user_phone), -- 联合主键 37 | KEY idx_create_time(create_time) 38 | )ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='秒杀成功明细表'; 39 | -------------------------------------------------------------------------------- /seckill/src/main/sql/seckill.sql: -------------------------------------------------------------------------------- 1 | -- 执行秒杀存储过程 2 | DELIMITER $$ 3 | -- 定义存储过程 4 | -- 参数:in输入参数 out输出参数 5 | -- row_count()返回上一条修改语句sql(update,insert,delete)影响的行数 6 | -- row_count:0未修改行数,>0:表示影响的行数 <0:sql错误/未执行修改sql 7 | -- 存储过程内部声明的变量不能是@开头 8 | CREATE PROCEDURE `seckill`.`execute_seckill`( 9 | in v_seckill_id bigint,in v_seckill_phone BIGINT,in v_seckill_time TIMESTAMP, 10 | out r_result int) 11 | BEGIN 12 | DECLARE insert_count int DEFAULT 0; 13 | START TRANSACTION; 14 | INSERT IGNORE INTO `success_killed`(seckill_id,user_phone,create_time) 15 | values(v_seckill_id,v_seckill_phone,v_seckill_time); 16 | SELECT row_count() INTO insert_count; 17 | IF(insert_count = 0) THEN 18 | ROLLBACK; 19 | SET r_result=-1;-- 重复秒杀 20 | ELSEIF(insert_count<0) THEN 21 | ROLLBACK; 22 | SET r_result=-2; 23 | ELSE 24 | UPDATE seckill SET number=number-1 25 | WHERE seckill_id=v_seckill_id 26 | AND seckill.start_time < v_seckill_time 27 | AND seckill.end_time >v_seckill_time 28 | AND seckill.number>0; 29 | SELECT row_count() into insert_count; 30 | IF (insert_count=0) THEN 31 | ROLLBACK; 32 | SET r_result=0; 33 | ELSEIF (insert_count<0) THEN 34 | ROLLBACK; 35 | SET r_result=-2; 36 | ELSE 37 | COMMIT; 38 | SET r_result=1; 39 | END IF ; 40 | END IF; 41 | END; 42 | $$ 43 | -- 存储过程定义结束 44 | DELIMITER ; 45 | SET @r_result=-3; 46 | -- 执行存储过程 47 | CALL seckill.execute_seckill(1003, 18826077111, now(), @r_result); 48 | -- 获取结果 49 | SELECT @r_result; 50 | 51 | 52 | -- 存储过程 53 | -- 存储过程优化:事务行级锁持有的时间 54 | -- 不要过度依赖存储过程 55 | -- 简单的逻辑可以应用存储过程 56 | -- QPS:一个秒杀单6000/QPS -------------------------------------------------------------------------------- /seckill/src/main/webapp/WEB-INF/jsp/common/head.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /seckill/src/main/webapp/WEB-INF/jsp/common/tag.jsp: -------------------------------------------------------------------------------- 1 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2 | <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 3 | <%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 4 | -------------------------------------------------------------------------------- /seckill/src/main/webapp/WEB-INF/jsp/detail.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html; charset=UTF-8" language="java" %> 2 | <%@include file="common/tag.jsp" %> 3 | 4 | 5 | 6 | 秒杀详情页 7 | <%@include file="common/head.jsp" %> 8 | 9 | 10 |
11 |
12 |
13 |

${seckill.name}

14 |
15 | 16 |
17 |

18 | <%--显示time图标--%> 19 | 20 | <%--展示倒计时--%> 21 | 22 |

23 |
24 |
25 |
26 | <%--登录弹出层 输入电话--%> 27 | 60 | 61 | 62 | <%--jQery文件,务必在bootstrap.min.js之前引入--%> 63 | 64 | 65 | <%--使用CDN 获取公共js http://www.bootcdn.cn/--%> 66 | <%--jQuery Cookie操作插件--%> 67 | 68 | <%--jQuery countDown倒计时插件--%> 69 | 70 | 71 | 72 | 73 | 83 | -------------------------------------------------------------------------------- /seckill/src/main/webapp/WEB-INF/jsp/list.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html; charset=UTF-8" language="java" %> 2 | <%@include file="common/tag.jsp"%> 3 | 4 | 5 | 6 | 秒杀商品列表 7 | <%@include file="common/head.jsp" %> 8 | 9 | 10 |
11 |
12 |
13 |

秒杀列表

14 |
15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 35 | 38 | 41 | 42 | 43 | 44 | 45 |
名称库存开始时间结束时间创建时间详情页
${sk.name}${sk.number} 33 | 34 | 36 | 37 | 39 | 40 | 详情
46 | 47 |
48 |
49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /seckill/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | seckill-dispatcher 12 | org.springframework.web.servlet.DispatcherServlet 13 | 18 | 19 | contextConfigLocation 20 | classpath:spring/spring-*.xml 21 | 22 | 23 | 24 | seckill-dispatcher 25 | 26 | / 27 | 28 | -------------------------------------------------------------------------------- /seckill/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello World!

4 | 5 | 6 | -------------------------------------------------------------------------------- /seckill/src/test/java/org/seckill/dao/RedisDaoTest.java: -------------------------------------------------------------------------------- 1 | package org.seckill.dao; 2 | 3 | import org.junit.*; 4 | import org.junit.runner.*; 5 | import org.seckill.entity.*; 6 | import org.springframework.test.context.*; 7 | import org.springframework.test.context.junit4.*; 8 | 9 | import javax.annotation.*; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Created by pc on 2017/3/8. 15 | */ 16 | @RunWith(SpringJUnit4ClassRunner.class) 17 | @ContextConfiguration("classpath:spring/spring-dao.xml") 18 | public class RedisDaoTest { 19 | private long id=1001L; 20 | 21 | @Resource 22 | private RedisDao redisDao; 23 | @Resource 24 | private SeckillDao seckillDao; 25 | 26 | 27 | @Test 28 | public void testSeckill() throws Exception { 29 | Seckill seckill=redisDao.getSeckill(id); 30 | if(seckill==null){ 31 | seckill = seckillDao.queryById(id); 32 | if(seckill!=null){ 33 | String result = redisDao.putSeckill(seckill); 34 | System.out.println(result); 35 | seckill = redisDao.getSeckill(id); 36 | System.out.println(seckill); 37 | } 38 | } 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /seckill/src/test/java/org/seckill/dao/SeckillDaoTest.java: -------------------------------------------------------------------------------- 1 | package org.seckill.dao; 2 | 3 | import org.junit.*; 4 | import org.junit.runner.*; 5 | import org.seckill.entity.*; 6 | import org.springframework.test.context.*; 7 | import org.springframework.test.context.junit4.*; 8 | 9 | import javax.annotation.*; 10 | import java.util.*; 11 | 12 | /** 13 | * Created by pc on 2017/3/5. 14 | */ 15 | //配置spring和junit整合,这样junit在启动时就会加载spring容器 16 | @RunWith(SpringJUnit4ClassRunner.class) 17 | @ContextConfiguration("classpath:spring/spring-dao.xml") 18 | public class SeckillDaoTest { 19 | //注入Dao实现类依赖 20 | @Resource 21 | private SeckillDao seckillDao; 22 | 23 | @Test 24 | public void queryById(){ 25 | long seckillId=1001; 26 | Seckill seckill=seckillDao.queryById(seckillId); 27 | System.out.println(seckill.getName()); 28 | System.out.println(seckill); 29 | } 30 | 31 | @Test 32 | public void queryAll(){ 33 | List seckillList=seckillDao.queryAll(0,100); 34 | for(Seckill seckill:seckillList){ 35 | System.out.println(seckill); 36 | } 37 | } 38 | 39 | @Test 40 | public void reduceNumber(){ 41 | long id=1000; 42 | int updateCount=seckillDao.reduceNumber(1000, new Date()); 43 | System.out.println(updateCount); 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /seckill/src/test/java/org/seckill/dao/SuccessKilledDaoTest.java: -------------------------------------------------------------------------------- 1 | package org.seckill.dao; 2 | 3 | import org.junit.*; 4 | import org.junit.runner.*; 5 | import org.seckill.entity.*; 6 | import org.springframework.test.context.*; 7 | import org.springframework.test.context.junit4.*; 8 | 9 | import javax.annotation.*; 10 | 11 | /** 12 | * Created by pc on 2017/3/5. 13 | */ 14 | @RunWith(SpringJUnit4ClassRunner.class) 15 | @ContextConfiguration("classpath:spring/spring-dao.xml") 16 | public class SuccessKilledDaoTest { 17 | @Resource 18 | private SuccessKilledDao successKilledDao; 19 | 20 | @Test 21 | public void insertSuccessKilled(){ 22 | long seckillId=1000L; 23 | long userPhone=18826077187L; 24 | int updateCount=successKilledDao.insertSuccessKilled(seckillId,userPhone); 25 | System.out.println(updateCount); 26 | } 27 | 28 | @Test 29 | public void queryByIdWithSeckill(){ 30 | 31 | SuccessKilled successKilled=successKilledDao.queryByIdWithSeckill(1000L,18826077187L); 32 | System.out.println(successKilled); 33 | System.out.println(successKilled.getSeckill()); 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /seckill/src/test/java/org/seckill/service/impl/SeckillServiceImplTest.java: -------------------------------------------------------------------------------- 1 | package org.seckill.service.impl; 2 | 3 | import org.junit.*; 4 | import org.junit.runner.*; 5 | import org.seckill.dto.*; 6 | import org.seckill.entity.*; 7 | import org.seckill.exception.*; 8 | import org.seckill.service.*; 9 | import org.slf4j.*; 10 | import org.springframework.test.context.*; 11 | import org.springframework.test.context.junit4.*; 12 | 13 | import javax.annotation.*; 14 | 15 | import java.util.*; 16 | 17 | import static org.junit.Assert.*; 18 | 19 | /** 20 | * Created by pc on 2017/3/6. 21 | */ 22 | @RunWith(SpringJUnit4ClassRunner.class) 23 | @ContextConfiguration({ 24 | "classpath:spring/spring-dao.xml", 25 | "classpath:spring/spring-service.xml" 26 | }) 27 | public class SeckillServiceImplTest { 28 | Logger logger=LoggerFactory.getLogger(this.getClass()); 29 | @Resource 30 | private SeckillService seckillService; 31 | 32 | @Test 33 | public void testGetSeckillList() throws Exception { 34 | List seckillList=seckillService.getSeckillList(); 35 | logger.info("list={}",seckillList); 36 | } 37 | 38 | @Test 39 | public void testGetById() throws Exception { 40 | Seckill seckill=seckillService.getById(1000L); 41 | logger.info("seckill={}",seckill); 42 | 43 | } 44 | //集成测试代码完整逻辑,注意可重复执行 45 | @Test 46 | public void testSeckillLogic() throws Exception { 47 | //exposer=Exposer{exposed=true, md5='ae8c840b6c3a4891c593ec70b9dc2c06', 48 | // seckillId=1000, now=0, start=0, end=0} 49 | long id=1001L; 50 | Exposer exposer=seckillService.exposeSeckillUrl(id); 51 | logger.info("exposer={}",exposer); 52 | if(exposer!=null){ 53 | //用try-catch包围才能单元测试通过,否则抛出异常视为不通过 54 | try{ 55 | long userPhone=18826077189L; 56 | SeckillExecution seckillExecution=seckillService.executeSeckill(id, userPhone, exposer.getMd5()); 57 | logger.info("seckillExecution={}",seckillExecution); 58 | }catch(RepeatKillException e){ 59 | logger.error(e.getMessage()); 60 | }catch (SeckillCloseException e){ 61 | logger.error(e.getMessage()); 62 | }catch (SeckillException e){ 63 | logger.error(e.getMessage()); 64 | } 65 | }else{ 66 | logger.warn("exposer={}",exposer); 67 | } 68 | } 69 | 70 | @Test 71 | public void testProcedure(){ 72 | long seckillId=1001L; 73 | long userPhone=18826077188L; 74 | Exposer exposer = seckillService.exposeSeckillUrl(seckillId); 75 | if(exposer.isExposed()){ 76 | String md5=exposer.getMd5(); 77 | SeckillExecution execution=seckillService.executeSeckill(seckillId, userPhone, md5); 78 | logger.info(execution.getStateInfo()); 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /seckill/架构图.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/seckill/架构图.jpg -------------------------------------------------------------------------------- /seckill/说明 .txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/seckill/说明 .txt -------------------------------------------------------------------------------- /ssh/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /ssh/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | ssh 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.jsdt.core.javascriptValidator 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.common.project.facet.core.builder 20 | 21 | 22 | 23 | 24 | org.eclipse.m2e.core.maven2Builder 25 | 26 | 27 | 28 | 29 | org.eclipse.wst.validation.validationbuilder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.jem.workbench.JavaEMFNature 36 | org.eclipse.wst.common.modulecore.ModuleCoreNature 37 | org.eclipse.jdt.core.javanature 38 | org.eclipse.m2e.core.maven2Nature 39 | org.eclipse.wst.common.project.facet.core.nature 40 | org.eclipse.wst.jsdt.core.jsNature 41 | 42 | 43 | -------------------------------------------------------------------------------- /ssh/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /ssh/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /ssh/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /ssh/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ssh/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ssh/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ssh/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /ssh/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /ssh/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /ssh/src/main/java/com/crm/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.crm.controller; 2 | 3 | 4 | import javax.annotation.Resource; 5 | 6 | import org.springframework.context.annotation.Scope; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.springframework.web.bind.annotation.ResponseBody; 11 | import org.springframework.web.servlet.ModelAndView; 12 | 13 | import com.crm.model.User; 14 | import com.crm.service.UserService; 15 | 16 | 17 | 18 | 19 | 20 | @Controller 21 | @Scope(value="prototype") 22 | @RequestMapping("/user") 23 | public class UserController { 24 | 25 | @Resource 26 | private UserService userService; 27 | 28 | @RequestMapping(value="/login",method=RequestMethod.POST) 29 | @ResponseBody 30 | public ModelAndView login(String name,String password){ 31 | ModelAndView modelAndView=new ModelAndView(); 32 | User user=userService.checkLogin(name, password); 33 | if(user!=null){ 34 | modelAndView.setViewName("welcome"); 35 | modelAndView.addObject("user",user); 36 | }else{ 37 | modelAndView.setViewName("fail"); 38 | } 39 | return modelAndView; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ssh/src/main/java/com/crm/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.crm.dao; 2 | 3 | import com.crm.model.*; 4 | 5 | 6 | public interface UserDao { 7 | public User findUserByName(String username) ; 8 | } 9 | -------------------------------------------------------------------------------- /ssh/src/main/java/com/crm/dao/impl/UserDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.crm.dao.impl; 2 | 3 | import java.util.List; 4 | 5 | import javax.persistence.EntityManager; 6 | import javax.persistence.PersistenceContext; 7 | import javax.persistence.Query; 8 | 9 | import org.springframework.stereotype.Repository; 10 | 11 | import com.crm.dao.UserDao; 12 | import com.crm.model.User; 13 | 14 | 15 | 16 | @Repository("userDao") 17 | public class UserDaoImpl implements UserDao{ 18 | @PersistenceContext 19 | private EntityManager em; 20 | 21 | 22 | @SuppressWarnings("unchecked") 23 | @Override 24 | public User findUserByName(String username) { 25 | String jpql="select u from User u where u.name=?0"; 26 | Query query=em.createQuery(jpql).setParameter(0, username); 27 | 28 | List userList=(List)query.getResultList(); 29 | User user=null; 30 | if(userList.size()!=0){ 31 | System.out.println(userList.size()); 32 | user=userList.get(0); 33 | } 34 | System.out.println(user); 35 | return user; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /ssh/src/main/java/com/crm/model/User.java: -------------------------------------------------------------------------------- 1 | package com.crm.model; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.Id; 6 | import javax.persistence.Table; 7 | 8 | @Entity 9 | @Table(name="user") 10 | public class User { 11 | private int id; 12 | private String name; 13 | private String password; 14 | private String email; 15 | private String telephone; 16 | 17 | @Id 18 | @GeneratedValue 19 | public int getId() { 20 | return id; 21 | } 22 | 23 | public void setId(int id) { 24 | this.id = id; 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | 35 | public String getPassword() { 36 | return password; 37 | } 38 | 39 | public void setPassword(String password) { 40 | this.password = password; 41 | } 42 | 43 | public String getEmail() { 44 | return email; 45 | } 46 | 47 | public void setEmail(String email) { 48 | this.email = email; 49 | } 50 | 51 | public String getTelephone() { 52 | return telephone; 53 | } 54 | 55 | public void setTelephone(String telephone) { 56 | this.telephone = telephone; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "User [id=" + id + ", name=" + name + ", password=" + password + ", email=" + email + ", telephone=" 62 | + telephone + "]"; 63 | } 64 | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /ssh/src/main/java/com/crm/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.crm.service; 2 | 3 | import com.crm.model.*; 4 | 5 | 6 | public interface UserService { 7 | 8 | public User checkLogin(String username,String password); 9 | } 10 | -------------------------------------------------------------------------------- /ssh/src/main/java/com/crm/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.crm.service.impl; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.springframework.stereotype.Service; 6 | 7 | import com.crm.dao.UserDao; 8 | import com.crm.model.User; 9 | import com.crm.service.UserService; 10 | @Service("userService") 11 | public class UserServiceImpl implements UserService { 12 | @Resource 13 | private UserDao userDao; 14 | 15 | /** 16 | * 登陆验证 17 | * @param 18 | */ 19 | public User checkLogin(String username, String password) { 20 | 21 | User user=userDao.findUserByName(username); 22 | if(user!=null&&user.getPassword().equals(password)){ 23 | return user; 24 | } 25 | return null; 26 | } 27 | 28 | public UserDao getUserDao() { 29 | return userDao; 30 | } 31 | 32 | public void setUserDao(UserDao userDao) { 33 | this.userDao = userDao; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /ssh/src/main/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | thread 59 | update 60 | true 61 | false 62 | 63 | 64 | org.hibernate.cfg.ImprovedNamingStrategy 65 | 66 | 67 | 68 | 69 | 70 | 71 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /ssh/src/main/resources/ehcache.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 16 | 17 | -------------------------------------------------------------------------------- /ssh/src/main/resources/jdbc.properties: -------------------------------------------------------------------------------- 1 | jdbc.driverClassName=com.mysql.jdbc.Driver 2 | 3 | jdbc.url=jdbc\:mysql\://localhost\:3306/funding?useUnicode\=true&characterEncoding\=UTF-8 4 | 5 | jdbc.username=root 6 | 7 | jdbc.password=123456 8 | 9 | hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect 10 | 11 | BoneCP.idleConnectionTestPeriod=60 12 | 13 | BoneCP.idleMaxAge=60 14 | 15 | BoneCP.maxConnectionsPerPartition=5 16 | 17 | BoneCP.minConnectionsPerPartition=1 18 | 19 | BoneCP.partitionCount=3 20 | 21 | BoneCP.acquireIncrement=2 22 | 23 | BoneCP.statementsCacheSize=0 24 | 25 | BoneCP.releaseHelperThreads=3 26 | 27 | -------------------------------------------------------------------------------- /ssh/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=INFO,stdout,file 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.Target=System.out 6 | log4j.appender.stdout.layout.ConversionPattern=%-d{yyyy-MM-dd HH\:mm\:ss,SSS} [%c]-[%p] %m%n 7 | 8 | log4j.appender.file=org.apache.log4j.DailyRollingFileAppender 9 | log4j.appender.file.File=${spring_springmvc_jpa.root}/shirodemo.log 10 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 11 | log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c] [%p] - %m%n 12 | 13 | log4j.logger.org.hibernate.tool.hbm2ddl=info -------------------------------------------------------------------------------- /ssh/src/main/resources/springmvc.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /ssh/src/main/webapp/WEB-INF/pages/fail.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <% 3 | String path = request.getContextPath(); 4 | String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 | %> 6 | 7 | 8 | 9 | 10 | 11 | 12 | My JSP 'index.jsp' starting page 13 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | 23 | 24 |

登录失败

25 | 26 | 27 | -------------------------------------------------------------------------------- /ssh/src/main/webapp/WEB-INF/pages/welcome.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <% 3 | String path = request.getContextPath(); 4 | String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 | %> 6 | 7 | 8 | 9 | 10 | 11 | 12 | My JSP 'index.jsp' starting page 13 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | 23 | 24 |

登录成功

25 |
26 |

welcome ${user.name}

27 | 28 | 29 | -------------------------------------------------------------------------------- /ssh/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | Archetype Created Web Application 8 | 9 | log4jConfigLocation 10 | classpath:log4j.properties 11 | 12 | 13 | 14 | log4jRefreshInterval 15 | 60000 16 | 17 | 18 | 19 | 20 | org.springframework.web.util.Log4jConfigListener 21 | 22 | 23 | 24 | 25 | contextConfigLocation 26 | classpath:applicationContext.xml 27 | 28 | 29 | 30 | 31 | org.springframework.web.context.ContextLoaderListener 32 | 33 | 34 | 35 | 36 | 37 | org.springframework.web.util.IntrospectorCleanupListener 38 | 39 | 40 | 41 | 42 | 43 | springmvc 44 | org.springframework.web.servlet.DispatcherServlet 45 | 46 | contextConfigLocation 47 | classpath:springmvc.xml 48 | 49 | 1 50 | 51 | 52 | 53 | springmvc 54 | / 55 | 56 | 57 | 58 | 59 | characterEncodingFilter 60 | org.springframework.web.filter.CharacterEncodingFilter 61 | 62 | encoding 63 | UTF-8 64 | 65 | 66 | 67 | 68 | characterEncodingFilter 69 | /* 70 | 71 | 72 | 73 | 76 | 88 | 89 | index.jsp 90 | 91 | 92 | -------------------------------------------------------------------------------- /ssh/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 |

欢迎您

11 |
12 |
登录 13 |
14 | 注册 15 |
16 | 17 | -------------------------------------------------------------------------------- /ssh/src/main/webapp/login.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <%String basePath=request.getContextPath(); %> 3 | 4 | 5 | 6 | 用户登录 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |

用户账户:

用户密码:

26 |
27 | 28 | 29 | -------------------------------------------------------------------------------- /ssh/src/main/webapp/register.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <%String path=request.getContextPath(); %> 4 | <%String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> 5 | 6 | 7 | 8 | 9 | 注册 10 | 16 | 17 | 18 |
19 | 用户名: 20 |
21 | 邮箱: 22 |
23 | 手机: 24 |
25 | 密码: 26 |
27 | 确认密码: 28 |
29 | 验证码: 30 | 验证码 31 | 看不清楚
32 | 33 |
34 | 35 | -------------------------------------------------------------------------------- /ssh/target/classes/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | thread 59 | update 60 | true 61 | false 62 | 63 | 64 | org.hibernate.cfg.ImprovedNamingStrategy 65 | 66 | 67 | 68 | 69 | 70 | 71 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /ssh/target/classes/com/crm/controller/UserController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/ssh/target/classes/com/crm/controller/UserController.class -------------------------------------------------------------------------------- /ssh/target/classes/com/crm/dao/UserDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/ssh/target/classes/com/crm/dao/UserDao.class -------------------------------------------------------------------------------- /ssh/target/classes/com/crm/dao/impl/UserDaoImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/ssh/target/classes/com/crm/dao/impl/UserDaoImpl.class -------------------------------------------------------------------------------- /ssh/target/classes/com/crm/model/User.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/ssh/target/classes/com/crm/model/User.class -------------------------------------------------------------------------------- /ssh/target/classes/com/crm/service/UserService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/ssh/target/classes/com/crm/service/UserService.class -------------------------------------------------------------------------------- /ssh/target/classes/com/crm/service/impl/UserServiceImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/ssh/target/classes/com/crm/service/impl/UserServiceImpl.class -------------------------------------------------------------------------------- /ssh/target/classes/ehcache.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 16 | 17 | -------------------------------------------------------------------------------- /ssh/target/classes/jdbc.properties: -------------------------------------------------------------------------------- 1 | jdbc.driverClassName=com.mysql.jdbc.Driver 2 | 3 | jdbc.url=jdbc\:mysql\://localhost\:3306/funding?useUnicode\=true&characterEncoding\=UTF-8 4 | 5 | jdbc.username=root 6 | 7 | jdbc.password=123456 8 | 9 | hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect 10 | 11 | BoneCP.idleConnectionTestPeriod=60 12 | 13 | BoneCP.idleMaxAge=60 14 | 15 | BoneCP.maxConnectionsPerPartition=5 16 | 17 | BoneCP.minConnectionsPerPartition=1 18 | 19 | BoneCP.partitionCount=3 20 | 21 | BoneCP.acquireIncrement=2 22 | 23 | BoneCP.statementsCacheSize=0 24 | 25 | BoneCP.releaseHelperThreads=3 26 | 27 | -------------------------------------------------------------------------------- /ssh/target/classes/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=INFO,stdout,file 2 | 3 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.Target=System.out 6 | log4j.appender.stdout.layout.ConversionPattern=%-d{yyyy-MM-dd HH\:mm\:ss,SSS} [%c]-[%p] %m%n 7 | 8 | log4j.appender.file=org.apache.log4j.DailyRollingFileAppender 9 | log4j.appender.file.File=${spring_springmvc_jpa.root}/shirodemo.log 10 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 11 | log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c] [%p] - %m%n 12 | 13 | log4j.logger.org.hibernate.tool.hbm2ddl=info -------------------------------------------------------------------------------- /ssh/target/classes/springmvc.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /ssh/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Built-By: pc 3 | Build-Jdk: 1.8.0_73 4 | Created-By: Maven Integration for Eclipse 5 | 6 | -------------------------------------------------------------------------------- /ssh/target/m2e-wtp/web-resources/META-INF/maven/com.dragon/ssh/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Maven Integration for Eclipse 2 | #Sat Dec 10 22:44:14 GMT+08:00 2016 3 | version=0.0.1-SNAPSHOT 4 | groupId=com.dragon 5 | m2e.projectName=ssh 6 | m2e.projectLocation=D\:\\javaLearning\\ssh 7 | artifactId=ssh 8 | -------------------------------------------------------------------------------- /ssh/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/ssh/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst -------------------------------------------------------------------------------- /ssh/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | D:\javaLearning\ssh\src\main\java\com\crm\service\UserService.java 2 | D:\javaLearning\ssh\src\main\java\com\crm\model\User.java 3 | D:\javaLearning\ssh\src\main\java\com\crm\service\impl\UserServiceImpl.java 4 | D:\javaLearning\ssh\src\main\java\com\crm\dao\UserDao.java 5 | D:\javaLearning\ssh\src\main\java\com\crm\controller\UserController.java 6 | -------------------------------------------------------------------------------- /ssm/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /ssm/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | mypoem 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.jsdt.core.javascriptValidator 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.common.project.facet.core.builder 20 | 21 | 22 | 23 | 24 | org.eclipse.m2e.core.maven2Builder 25 | 26 | 27 | 28 | 29 | org.eclipse.wst.validation.validationbuilder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.jem.workbench.JavaEMFNature 36 | org.eclipse.wst.common.modulecore.ModuleCoreNature 37 | org.eclipse.jdt.core.javanature 38 | org.eclipse.m2e.core.maven2Nature 39 | org.eclipse.wst.common.project.facet.core.nature 40 | org.eclipse.wst.jsdt.core.jsNature 41 | 42 | 43 | -------------------------------------------------------------------------------- /ssm/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /ssm/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.source=1.8 9 | -------------------------------------------------------------------------------- /ssm/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /ssm/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ssm/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ssm/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /ssm/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /ssm/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /ssm/src/main/java/com/crm/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.crm.controller; 2 | 3 | import javax.annotation.Resource; 4 | 5 | 6 | 7 | import org.springframework.context.annotation.Scope; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.ui.Model; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestMethod; 12 | 13 | 14 | 15 | 16 | import com.crm.model.User; 17 | import com.crm.service.UserService; 18 | 19 | 20 | 21 | @Controller 22 | @Scope(value="prototype") 23 | @RequestMapping("/user") 24 | public class UserController { 25 | 26 | @Resource 27 | private UserService userService; 28 | 29 | @RequestMapping(value="/login",method=RequestMethod.POST) 30 | public String login(User user,Model model) throws Exception { 31 | user=userService.checkLogin(user.getName(), user.getPassword()); 32 | if(user!=null){ 33 | //model.addAttribute("retCode", 0); 34 | model.addAttribute(user); 35 | return "welcome"; 36 | } 37 | //model.addAttribute("retCode", 1); 38 | return "fail"; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ssm/src/main/java/com/crm/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.crm.dao; 2 | 3 | import com.crm.model.*; 4 | 5 | 6 | public interface UserDao { 7 | public User findUserByName(String username) ; 8 | } 9 | -------------------------------------------------------------------------------- /ssm/src/main/java/com/crm/mapping/user.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 18 | 19 | -------------------------------------------------------------------------------- /ssm/src/main/java/com/crm/model/User.java: -------------------------------------------------------------------------------- 1 | package com.crm.model; 2 | 3 | public class User { 4 | private int id; 5 | private String name; 6 | private String password; 7 | private String email; 8 | private String telephone; 9 | 10 | public int getId() { 11 | return id; 12 | } 13 | 14 | public void setId(int id) { 15 | this.id = id; 16 | } 17 | 18 | public String getName() { 19 | return name; 20 | } 21 | 22 | public void setName(String name) { 23 | this.name = name; 24 | } 25 | 26 | public String getPassword() { 27 | return password; 28 | } 29 | 30 | public void setPassword(String password) { 31 | this.password = password; 32 | } 33 | 34 | public String getEmail() { 35 | return email; 36 | } 37 | 38 | public void setEmail(String email) { 39 | this.email = email; 40 | } 41 | 42 | public String getTelephone() { 43 | return telephone; 44 | } 45 | 46 | public void setTelephone(String telephone) { 47 | this.telephone = telephone; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /ssm/src/main/java/com/crm/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.crm.service; 2 | 3 | import com.crm.model.*; 4 | 5 | 6 | public interface UserService { 7 | 8 | public User checkLogin(String username,String password); 9 | } 10 | -------------------------------------------------------------------------------- /ssm/src/main/java/com/crm/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.crm.service.impl; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.springframework.stereotype.Service; 6 | 7 | import com.crm.dao.UserDao; 8 | import com.crm.model.User; 9 | import com.crm.service.UserService; 10 | @Service("userService") 11 | public class UserServiceImpl implements UserService { 12 | @Resource 13 | private UserDao userDao; 14 | 15 | /** 16 | * 登陆验证 17 | * @param 18 | */ 19 | public User checkLogin(String username, String password) { 20 | 21 | User user=userDao.findUserByName(username); 22 | if(user!=null&&user.getPassword().equals(password)){ 23 | return user; 24 | } 25 | return null; 26 | } 27 | 28 | public UserDao getUserDao() { 29 | return userDao; 30 | } 31 | 32 | public void setUserDao(UserDao userDao) { 33 | this.userDao = userDao; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /ssm/src/main/resources/database.properties: -------------------------------------------------------------------------------- 1 | mysql.driver_class=com.mysql.jdbc.Driver 2 | mysql.connection.url=jdbc:mysql://localhost:3306/funding 3 | mysql.connection.username=root 4 | mysql.connection.password=123456 -------------------------------------------------------------------------------- /ssm/src/main/resources/spring-mybatis.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | 20 | classpath:database.properties 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | ${mysql.driver_class} 31 | 32 | 33 | 34 | ${mysql.connection.url} 35 | 36 | 37 | 38 | ${mysql.connection.username} 39 | 40 | 41 | 42 | ${mysql.connection.password} 43 | 44 | 45 | 46 | 30 47 | 48 | 49 | 50 | 2 51 | 52 | 53 | 54 | 2 55 | 56 | 57 | 58 | 10 59 | 60 | 61 | 62 | 63 | 64 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | classpath:com/crm/mapping/*.xml 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /ssm/src/main/resources/springmvc.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /ssm/src/main/webapp/WEB-INF/pages/fail.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <% 3 | String path = request.getContextPath(); 4 | String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 | %> 6 | 7 | 8 | 9 | 10 | 11 | 12 | My JSP 'index.jsp' starting page 13 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | 23 | 24 |

登录失败

25 | 26 | 27 | -------------------------------------------------------------------------------- /ssm/src/main/webapp/WEB-INF/pages/welcome.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | <% 3 | String path = request.getContextPath(); 4 | String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 | %> 6 | 7 | 8 | 9 | 10 | 11 | 12 | My JSP 'index.jsp' starting page 13 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | 23 | 24 |

登录成功

25 |
26 |

welcome ${user.name}

27 | 28 | 29 | -------------------------------------------------------------------------------- /ssm/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | Archetype Created Web Application 8 | 9 | 10 | log4jConfigLocation 11 | classpath:log4j.properties 12 | 13 | 14 | 15 | log4jRefreshInterval 16 | 60000 17 | 18 | 19 | 20 | 21 | org.springframework.web.util.Log4jConfigListener 22 | 23 | 24 | 25 | 26 | contextConfigLocation 27 | classpath:spring-mybatis.xml 28 | 29 | 30 | 31 | 32 | org.springframework.web.context.ContextLoaderListener 33 | 34 | 35 | 36 | 37 | 38 | org.springframework.web.util.IntrospectorCleanupListener 39 | 40 | 41 | 42 | 43 | 44 | springmvc 45 | org.springframework.web.servlet.DispatcherServlet 46 | 47 | contextConfigLocation 48 | classpath:springmvc.xml 49 | 50 | 1 51 | 52 | 53 | 54 | springmvc 55 | / 56 | 57 | 58 | 59 | 60 | characterEncodingFilter 61 | org.springframework.web.filter.CharacterEncodingFilter 62 | 63 | encoding 64 | UTF-8 65 | 66 | 67 | 68 | 69 | characterEncodingFilter 70 | /* 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /ssm/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 |

欢迎您

11 |
12 | 登录 13 |
14 | 注册 15 |
16 | 17 | -------------------------------------------------------------------------------- /ssm/src/main/webapp/login.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | 3 | 4 | 5 | 用户登录 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |

用户账户:

用户密码:

25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /ssm/src/main/webapp/register.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <%String path=request.getContextPath(); %> 4 | <%String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> 5 | 6 | 7 | 8 | 9 | 注册 10 | 16 | 17 | 18 |
19 | 用户名: 20 |
21 | 邮箱: 22 |
23 | 手机: 24 |
25 | 密码: 26 |
27 | 确认密码: 28 |
29 | 验证码: 30 | 验证码 31 | 看不清楚
32 | 33 |
34 | 35 | -------------------------------------------------------------------------------- /ssm/target/classes/com/crm/controller/UserController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/ssm/target/classes/com/crm/controller/UserController.class -------------------------------------------------------------------------------- /ssm/target/classes/com/crm/dao/UserDao.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/ssm/target/classes/com/crm/dao/UserDao.class -------------------------------------------------------------------------------- /ssm/target/classes/com/crm/mapping/user.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 18 | 19 | -------------------------------------------------------------------------------- /ssm/target/classes/com/crm/model/User.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/ssm/target/classes/com/crm/model/User.class -------------------------------------------------------------------------------- /ssm/target/classes/com/crm/service/UserService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/ssm/target/classes/com/crm/service/UserService.class -------------------------------------------------------------------------------- /ssm/target/classes/com/crm/service/impl/UserServiceImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SnDragon/JavaLearning/64a2d77f234c71a2a1bb6a671950364a9445134f/ssm/target/classes/com/crm/service/impl/UserServiceImpl.class -------------------------------------------------------------------------------- /ssm/target/classes/database.properties: -------------------------------------------------------------------------------- 1 | mysql.driver_class=com.mysql.jdbc.Driver 2 | mysql.connection.url=jdbc:mysql://localhost:3306/funding 3 | mysql.connection.username=root 4 | mysql.connection.password=123456 -------------------------------------------------------------------------------- /ssm/target/classes/spring-mybatis.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | 20 | classpath:database.properties 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | ${mysql.driver_class} 31 | 32 | 33 | 34 | ${mysql.connection.url} 35 | 36 | 37 | 38 | ${mysql.connection.username} 39 | 40 | 41 | 42 | ${mysql.connection.password} 43 | 44 | 45 | 46 | 30 47 | 48 | 49 | 50 | 2 51 | 52 | 53 | 54 | 2 55 | 56 | 57 | 58 | 10 59 | 60 | 61 | 62 | 63 | 64 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | classpath:com/crm/mapping/*.xml 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /ssm/target/classes/springmvc.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /ssm/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Built-By: pc 3 | Build-Jdk: 1.8.0_73 4 | Created-By: Maven Integration for Eclipse 5 | 6 | -------------------------------------------------------------------------------- /ssm/target/m2e-wtp/web-resources/META-INF/maven/com.scut.sf/mypoem/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Maven Integration for Eclipse 2 | #Fri Sep 16 23:34:09 GMT+08:00 2016 3 | version=0.0.1-SNAPSHOT 4 | groupId=com.scut.sf 5 | m2e.projectName=mypoem 6 | m2e.projectLocation=D\:\\javaEEd1\\mypoem 7 | artifactId=mypoem 8 | --------------------------------------------------------------------------------