This commit is contained in:
qiurunze 2018-09-14 13:02:35 +08:00
parent 145eb2d1d1
commit 7c512b0d46
2 changed files with 116 additions and 309 deletions

View File

@ -2,86 +2,7 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="59bd24de-7908-4982-927f-6d236db7e416" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/.idea/compiler.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/encodings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__ch_qos_logback_logback_classic_1_1_11.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__ch_qos_logback_logback_core_1_1_11.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__com_alibaba_druid_1_0_5.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__com_alibaba_fastjson_1_2_38.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__com_fasterxml_classmate_1_3_4.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_8_0.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_8_10.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_8_10.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__javax_validation_validation_api_1_1_0_Final.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__mysql_mysql_connector_java_5_1_44.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__nz_net_ultraq_thymeleaf_thymeleaf_layout_dialect_1_4_0.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__ognl_ognl_3_0_8.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_apache_commons_commons_pool2_2_4_3.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_core_8_5_23.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_el_8_5_23.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_websocket_8_5_23.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_apache_tomcat_tomcat_annotations_api_8_5_23.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_apache_tomcat_tomcat_jdbc_8_5_23.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_apache_tomcat_tomcat_juli_8_5_23.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_codehaus_groovy_groovy_2_4_13.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_hibernate_hibernate_validator_5_3_6_Final.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_javassist_javassist_3_21_0_GA.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_jboss_logging_jboss_logging_3_3_1_Final.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_mybatis_mybatis_3_4_5.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_mybatis_mybatis_spring_1_3_1.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_mybatis_spring_boot_mybatis_spring_boot_autoconfigure_1_3_1.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_mybatis_spring_boot_mybatis_spring_boot_starter_1_3_1.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_slf4j_jcl_over_slf4j_1_7_25.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_slf4j_jul_to_slf4j_1_7_25.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_slf4j_log4j_over_slf4j_1_7_25.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_boot_spring_boot_1_5_9_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_boot_spring_boot_autoconfigure_1_5_9_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_1_5_9_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_jdbc_1_5_9_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_logging_1_5_9_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_thymeleaf_1_5_9_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_tomcat_1_5_9_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_web_1_5_9_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_spring_aop_4_3_13_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_spring_beans_4_3_13_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_spring_context_4_3_13_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_spring_core_4_3_13_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_spring_expression_4_3_13_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_spring_jdbc_4_3_13_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_spring_tx_4_3_13_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_spring_web_4_3_13_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_springframework_spring_webmvc_4_3_13_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_thymeleaf_thymeleaf_2_1_6_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_thymeleaf_thymeleaf_spring4_2_1_6_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_unbescape_unbescape_1_1_0_RELEASE.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_yaml_snakeyaml_1_17.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/libraries/Maven__redis_clients_jedis_2_9_0.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/uiDesigner.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/miaosha.iml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/readme.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/controller/DemoController.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/controller/finanical.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/dao/DruidConfig.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/dao/UserDao.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/domain/User.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/redis/BasePrefix.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/redis/KeyPrefix.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/redis/OrderKey.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/redis/RedisConfig.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/redis/RedisPoolFactory.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/redis/RedisService.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/redis/UserKey.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/result/CodeMsg.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/result/Result.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/service/UserService.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/eekQMainApplication.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/application.properties" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/templates/hello.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/readme.txt" beforeDir="false" afterPath="$PROJECT_DIR$/readme.txt" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/target/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@ -108,6 +29,7 @@
<entry key="finanacial" value="1" />
<entry key="html" value="1" />
<entry key="java" value="9" />
<entry key="txt" value="1" />
<entry key="xml" value="1" />
</counts>
</usages-collector>
@ -115,7 +37,7 @@
<counts>
<entry key="HTML" value="1" />
<entry key="JAVA" value="9" />
<entry key="PLAIN_TEXT" value="1" />
<entry key="PLAIN_TEXT" value="2" />
<entry key="UML" value="1" />
<entry key="XML" value="1" />
</counts>
@ -140,7 +62,7 @@
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="true">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/eekQMainApplication.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="132">
@ -149,6 +71,15 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/readme.txt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2222">
<caret line="101" lean-forward="true" selection-start-line="101" selection-end-line="101" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/dao/DruidConfig.java">
<provider selected="true" editor-type-id="text-editor">
@ -216,6 +147,7 @@
<option value="$PROJECT_DIR$/pom.xml" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/eekQMainApplication.java" />
<option value="$PROJECT_DIR$/src/main/java/com/geekq/miaosha/dao/UserDao.java" />
<option value="$PROJECT_DIR$/readme.txt" />
</list>
</option>
</component>
@ -225,9 +157,9 @@
<detection-done>true</detection-done>
<sorting>DEFINITION_ORDER</sorting>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="99" />
<option name="y" value="64" />
<component name="ProjectFrameBounds">
<option name="x" value="444" />
<option name="y" value="361" />
<option name="width" value="1392" />
<option name="height" value="989" />
</component>
@ -302,7 +234,7 @@
<property name="RequestMappingsPanelWidth2" value="75" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1536899509159" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1536901265737" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
@ -381,17 +313,18 @@
<workItem from="1536724872611" duration="2924000" />
<workItem from="1536762424112" duration="2194000" />
<workItem from="1536852892148" duration="3221000" />
<workItem from="1536888067376" duration="2179000" />
<workItem from="1536888067376" duration="3854000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="12601000" />
<option name="totallyTimeSpent" value="14276000" />
</component>
<component name="ToolWindowManager">
<frame x="-1" y="29" width="1922" height="1025" extended-state="6" />
<frame x="444" y="361" width="1392" height="989" extended-state="0" />
<editor active="true" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.25079873" />
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.34940654" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Designer" order="2" />
<window_info id="Image Layers" order="3" />
@ -401,14 +334,14 @@
<window_info id="Web" order="7" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" sideWeight="0.8966986" visible="true" weight="0.40111732" />
<window_info anchor="bottom" id="Run" order="2" sideWeight="0.86053413" visible="true" weight="0.41792783" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Spring" order="7" />
<window_info anchor="bottom" id="Terminal" order="8" />
<window_info anchor="bottom" id="Event Log" order="9" sideWeight="0.10330138" side_tool="true" visible="true" weight="0.40111732" />
<window_info anchor="bottom" id="Event Log" order="9" sideWeight="0.13946587" side_tool="true" visible="true" weight="0.41792783" />
<window_info anchor="bottom" id="Messages" order="10" />
<window_info anchor="bottom" id="Java Enterprise" order="11" />
<window_info anchor="bottom" id="Database Changes" order="12" show_stripe_button="false" />
@ -516,6 +449,13 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/readme.txt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2222">
<caret line="101" lean-forward="true" selection-start-line="101" selection-end-line="101" />
</state>
</provider>
</entry>
</component>
<component name="masterDetails">
<states>

View File

@ -1,234 +1,101 @@
1.springboot quick start
https://projects.spring.io/spring-boot/
https://docs.spring.io/spring-boot/docs/1.5.8.RELEASE/reference/htmlsingle/
Springboot 秒杀设计:
一: springboot 环境搭建
① 集成thymleaf + result 结果封装
② 集成Mybatis + Druid
③ 集成 Jedis + redis + 通用key封装
二: 登录设计
① 数据库设计
② 明文密码二次md5加密 + 全局异常处理器
③ JRS303参数检验 + 全局异常处理器
④分布式session
三:实现秒杀功能
① 秒杀数据库设计
② 商品列表页设计
③ 商品详情页设计
④ 订单详情页
压测jmeter
① jmeter压测入门
② 自定义变量与用户测试
③ 页面优化技术
五:缓存优化提高效率
① 页面优化+ url缓存+对象缓存
② 页面静态化
③ 静态资源
④ cdn优化
六:接口优化
① redis预减少库存访问
② 内存标记减少redis访问
③ rabbitmq安装与springboot集成
④rabbitmq异步下单
⑤ 访问Nginx水平扩展
七: 安全优化
① 秒杀地址隐藏
② 数学公式验证码
③ 接口防刷限流
如何应对互联网大并发 如何利用缓存, 如何使用异步 如何编写优雅的代码
一: springboot 环境搭建 springmvc会有大量的配置
1. 新建project -- maven -- 选择 maven-archtype-quickstart 项目
2.pom.xml文件
主要的 springboot的pom文件 項目直接导入就可以
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
</parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
3.<2E>޸<EFBFBD>pom<6F><6D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
4.<2E><><EFBFBD><EFBFBD>Ŀ¼<C4BF><EFBFBD><E1B9B9>controller<65><72>service<63><65>dao
5.<2E><><EFBFBD><EFBFBD>MainApplication DemoController
@SpringBootApplication
public class MainApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(MainApplication.class, args);
}
}
6. /hello/api <20>ӿ<EFBFBD>
7.<2E><><EFBFBD><EFBFBD>Result
8.<2E><><EFBFBD><EFBFBD>CodeMsg
9.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> http://localhost:8080/demo/hello/api
10.<2E><><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>thymeleaf
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>application.properties
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ո<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD>ģ<EFBFBD><C4A3>
11./hello<6C>ӿ<EFBFBD> template/hello.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'hello:'+${name}" ></p>
</body>
</html>
类的构思讲解:
Result类
结果类Result 类封装成一个通用类用一个codemsg错误码来直接返回不需要每次返回再去new一个对象按照模块来定义错误码
12.<2E><><EFBFBD><EFBFBD>mybatis
http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.5</version>
</dependency>
Redis类
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>druid
#mybatis
mybatis.type-aliases-package=com.imooc.miaosha.domain
mybatis.mapperLocations = classpath:com/imooc/miaosha/dao/*.xml
mybatis.configuration.map-underscore-to-camel-case=true
#datasource
spring.datasource.url=jdbc:mysql://10.110.3.62:3333/miaosha?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#druid
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.filters=stat
spring.datasource.maxActive=2
spring.datasource.initialSize=1
spring.datasource.maxWait=60000
spring.datasource.minIdle=1
spring.datasource.timeBetweenEvictionRunsMillis=60000
spring.datasource.minEvictableIdleTimeMillis=300000
spring.datasource.validationQuery=select 'x'
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false
spring.datasource.poolPreparedStatements=true
spring.datasource.maxOpenPreparedStatements=20
自己封装的 jedis ,使用它自带的temple总觉得不好使 key的定义保证不重复 生成 set--get--exist......方法自己可以添加
<EFBFBD><EFBFBD><EFBFBD>config<EFBFBD><EFBFBD>
public class DruidConfig {
private String url;
private String username;
private String password;
private String driverClassName;
private String type;
private String filters;
private int maxActive;
private int initialSize;
private int minIdle;
private long maxWait;
private long timeBetweenEvictionRunsMillis;
private long minEvictableIdleTimeMillis;
private String validationQuery;
private boolean testWhileIdle;
private boolean testOnBorrow;
private boolean testOnReturn;
private boolean poolPreparedStatements;
private int maxOpenPreparedStatements;
密码 --MD5 二次明文加密处理 设计
密码设计: MD5MD5pass明文 + 固定salt + salt 处理
二次MD5
用户端: PASS = MD5 (明文 + 固定 Salt)
服务端: PASS = MD5(用户输入 + 随机Salt)
Js 前端进行第一个MD5 后端进行第二次 后端第二次salt随机生成入库然后登录时取出对比
===============
注解JSR303与 自定义注解来完成手机号和登录验证,防刷限流等功能
分布式session
登录成功之后给用户生成一个类似于sessionid的东西 token 标识用户写到cookie当中传递给客户端客户端在随后的访问中都在cookie中上传这个token 然后在服务端拿到这个token来取到用户信息
把token uuid标识 存到 redis缓存中 设置过期时间然后别的页面访问的时候依旧根据这个cookie token的值拿到用户信息。
接口防刷限流:
如果有缓存的话 这个功能实现起来就和简单,在一个用户访问接口的时候我们把访问次数写到缓存中,在加上一个有效期。
通过拦截器. 做一个注解 @AccessLimit 然后封装这个注解,可以有效的设置每次访问多少次,有效时间是否需要登录!
数据库采用mybatis
@Bean
public DataSource druidDataSource() {
DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(url);
datasource.setUsername(username);
datasource.setPassword(password);
datasource.setDriverClassName(driverClassName);
datasource.setInitialSize(initialSize);
datasource.setMinIdle(minIdle);
datasource.setMaxActive(maxActive);
datasource.setMaxWait(maxWait);
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
datasource.setValidationQuery(validationQuery);
datasource.setTestWhileIdle(testWhileIdle);
datasource.setTestOnBorrow(testOnBorrow);
datasource.setTestOnReturn(testOnReturn);
datasource.setPoolPreparedStatements(poolPreparedStatements);
datasource.setMaxOpenPreparedStatements(maxOpenPreparedStatements);
try {
datasource.setFilters(filters);
} catch (SQLException e) {
e.printStackTrace();
}
return datasource;
}
}
@Bean
public ServletRegistrationBean druidStatServlet() {
ServletRegistrationBean reg = new ServletRegistrationBean();
reg.setServlet(new StatViewServlet());
reg.addUrlMappings("/druid/*");
reg.addInitParameter("loginUsername", "caAdmin");
reg.addInitParameter("loginPassword", "caPass123");
reg.addInitParameter("logSlowSql", "true");
reg.addInitParameter("slowSqlMillis", "1000");
return reg;
}
<EFBFBD><EFBFBD><EFBFBD>mysql-connctor<6F><72>druid<69><64><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD>User<EFBFBD><EFBFBD>Service<EFBFBD><EFBFBD>Dao<EFBFBD><EFBFBD>Domain
CREATE TABLE `user` (
`id` int(11) NOT NULL,
`name` varchar(24) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
@Selectע<74><D7A2>
xml:
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="UserDao">
</mapper>
<EFBFBD><EFBFBD>1<EFBFBD><EFBFBD>getById
<EFBFBD><EFBFBD>2<EFBFBD><EFBFBD>tx @Transactional <20><>ʾ
13.<2E><><EFBFBD><EFBFBD>redis
<EFBFBD><EFBFBD>1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>װredis
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>redis<EFBFBD><EFBFBD>װ<EFBFBD>ļ<EFBFBD> http://redis.io/ redis-4.0.2.tar.gz
tar -zvxf redis-4.0.2.tar.gz
cd redis-4.0.2
make
make install
src/redis-server & //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
src/redis-cli //<2F>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
util/install_server.sh <20><>װ<EFBFBD><D7B0>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>
chkconfig <20>C-list | grep redis <20><EFBFBD>Ƿ񿪻<C7B7><F1BFAABB><EFBFBD><EFBFBD><EFBFBD>
(2)<29><><EFBFBD><EFBFBD>
daemonize
bind
requirepass
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>jedis<EFBFBD><EFBFBD>fastjson<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.38</version>
</dependency>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>
#redis
redis.host=10.110.3.62
redis.port=6379
redis.timeout=3
redis.password=123456
redis.poolMaxTotal=10
redis.poolMaxIdle=10
redis.poolMaxWait=3
java<EFBFBD><EFBFBD>
@ConfigurationProperties(prefix="redis")
@Component
public class RedisConfig {
private String host;
private int port;
private int timeout;//<2F><>
private String password;
private int poolMaxTotal;
private int poolMaxIdle;
private int poolMaxWait;//<2F><>
}
<EFBFBD><EFBFBD>дRedisSerive KeyPrefix BaseKey