34 changed files with 2078 additions and 0 deletions
-
38.gitignore
-
8.idea/.gitignore
-
30.idea/dataSources.xml
-
7.idea/encodings.xml
-
14.idea/misc.xml
-
124.idea/uiDesigner.xml
-
10.idea/webContexts.xml
-
239pom.xml
-
60src/main/java/cn/star/common/ApiResponse.java
-
178src/main/java/cn/star/controller/UserController.java
-
24src/main/java/cn/star/dao/UsersDao.java
-
45src/main/java/cn/star/domian/Users.java
-
91src/main/java/cn/star/interceptor/TokenInterceptor.java
-
15src/main/java/cn/star/service/UsersService.java
-
38src/main/java/cn/star/service/impl/UsersServiceImpl.java
-
61src/main/java/cn/star/test/MybatisTest.java
-
18src/main/java/cn/star/test/SpringTest.java
-
79src/main/java/cn/star/util/JwtUtil.java
-
567src/main/java/cn/star/util/RedisUtil.java
-
66src/main/resources/application-redis.xml
-
4src/main/resources/jdbc.properties
-
18src/main/resources/log4j.properties
-
23src/main/resources/mybatis.xml
-
18src/main/resources/redis.properties
-
41src/main/resources/spring-mvc.xml
-
45src/main/resources/spring.xml
-
18src/main/webapp/WEB-INF/pages/Users.jsp
-
17src/main/webapp/WEB-INF/pages/falselogin.jsp
-
17src/main/webapp/WEB-INF/pages/success.jsp
-
17src/main/webapp/WEB-INF/pages/successlogin.jsp
-
47src/main/webapp/WEB-INF/web.xml
-
0src/main/webapp/images
-
94src/main/webapp/index.jsp
-
7src/main/webapp/static/css/styles.css
@ -0,0 +1,38 @@ |
|||
target/ |
|||
!.mvn/wrapper/maven-wrapper.jar |
|||
!**/src/main/**/target/ |
|||
!**/src/test/**/target/ |
|||
|
|||
### IntelliJ IDEA ### |
|||
.idea/modules.xml |
|||
.idea/jarRepositories.xml |
|||
.idea/compiler.xml |
|||
.idea/libraries/ |
|||
*.iws |
|||
*.iml |
|||
*.ipr |
|||
|
|||
### Eclipse ### |
|||
.apt_generated |
|||
.classpath |
|||
.factorypath |
|||
.project |
|||
.settings |
|||
.springBeans |
|||
.sts4-cache |
|||
|
|||
### NetBeans ### |
|||
/nbproject/private/ |
|||
/nbbuild/ |
|||
/dist/ |
|||
/nbdist/ |
|||
/.nb-gradle/ |
|||
build/ |
|||
!**/src/main/**/build/ |
|||
!**/src/test/**/build/ |
|||
|
|||
### VS Code ### |
|||
.vscode/ |
|||
|
|||
### Mac OS ### |
|||
.DS_Store |
|||
@ -0,0 +1,8 @@ |
|||
# Default ignored files |
|||
/shelf/ |
|||
/workspace.xml |
|||
# Editor-based HTTP Client requests |
|||
/httpRequests/ |
|||
# Datasource local storage ignored files |
|||
/dataSources/ |
|||
/dataSources.local.xml |
|||
@ -0,0 +1,30 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true"> |
|||
<data-source source="LOCAL" name="@localhost" uuid="34dbace9-6521-48bb-bb16-5626163f9e16"> |
|||
<driver-ref>mysql_aurora_aws</driver-ref> |
|||
<synchronize>true</synchronize> |
|||
<jdbc-driver>software.aws.rds.jdbc.mysql.Driver</jdbc-driver> |
|||
<jdbc-url>jdbc:mysql:aws://localhost:3306</jdbc-url> |
|||
<jdbc-additional-properties> |
|||
<property name="com.intellij.clouds.kubernetes.db.host.port" /> |
|||
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" /> |
|||
<property name="com.intellij.clouds.kubernetes.db.resource.type" value="Deployment" /> |
|||
<property name="com.intellij.clouds.kubernetes.db.container.port" /> |
|||
</jdbc-additional-properties> |
|||
<working-dir>$ProjectFileDir$</working-dir> |
|||
</data-source> |
|||
<data-source source="LOCAL" name="0@localhost" uuid="79cc8c48-2dfb-497f-8761-233f87fc16b2"> |
|||
<driver-ref>redis</driver-ref> |
|||
<synchronize>true</synchronize> |
|||
<jdbc-driver>jdbc.RedisDriver</jdbc-driver> |
|||
<jdbc-url>jdbc:redis://localhost:6379/0</jdbc-url> |
|||
<jdbc-additional-properties> |
|||
<property name="com.intellij.clouds.kubernetes.db.host.port" /> |
|||
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" /> |
|||
<property name="com.intellij.clouds.kubernetes.db.container.port" /> |
|||
</jdbc-additional-properties> |
|||
<working-dir>$ProjectFileDir$</working-dir> |
|||
</data-source> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,7 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="Encoding"> |
|||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" /> |
|||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" /> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,14 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="ExternalStorageConfigurationManager" enabled="true" /> |
|||
<component name="MavenProjectsManager"> |
|||
<option name="originalFiles"> |
|||
<list> |
|||
<option value="$PROJECT_DIR$/pom.xml" /> |
|||
</list> |
|||
</option> |
|||
</component> |
|||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK"> |
|||
<output url="file://$PROJECT_DIR$/out" /> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,124 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="Palette2"> |
|||
<group name="Swing"> |
|||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> |
|||
</item> |
|||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> |
|||
</item> |
|||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> |
|||
</item> |
|||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true"> |
|||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> |
|||
</item> |
|||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> |
|||
<initial-values> |
|||
<property name="text" value="Button" /> |
|||
</initial-values> |
|||
</item> |
|||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> |
|||
<initial-values> |
|||
<property name="text" value="RadioButton" /> |
|||
</initial-values> |
|||
</item> |
|||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> |
|||
<initial-values> |
|||
<property name="text" value="CheckBox" /> |
|||
</initial-values> |
|||
</item> |
|||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> |
|||
<initial-values> |
|||
<property name="text" value="Label" /> |
|||
</initial-values> |
|||
</item> |
|||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> |
|||
<preferred-size width="150" height="-1" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> |
|||
<preferred-size width="150" height="-1" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> |
|||
<preferred-size width="150" height="-1" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
|||
<preferred-size width="150" height="50" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
|||
<preferred-size width="150" height="50" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
|||
<preferred-size width="150" height="50" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> |
|||
</item> |
|||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
|||
<preferred-size width="150" height="50" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> |
|||
<preferred-size width="150" height="50" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> |
|||
<preferred-size width="150" height="50" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> |
|||
<preferred-size width="200" height="200" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> |
|||
<preferred-size width="200" height="200" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> |
|||
</item> |
|||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> |
|||
</item> |
|||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> |
|||
</item> |
|||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> |
|||
</item> |
|||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> |
|||
<preferred-size width="-1" height="20" /> |
|||
</default-constraints> |
|||
</item> |
|||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false"> |
|||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> |
|||
</item> |
|||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false"> |
|||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> |
|||
</item> |
|||
</group> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,10 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project version="4"> |
|||
<component name="WebContextManager"> |
|||
<option name="state"> |
|||
<map> |
|||
<entry key="file://$PROJECT_DIR$/src/main/webapp/index.jsp" value="file://$PROJECT_DIR$/src/main/webapp" /> |
|||
</map> |
|||
</option> |
|||
</component> |
|||
</project> |
|||
@ -0,0 +1,239 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
|
|||
<groupId>com.xs</groupId> |
|||
<artifactId>myssm</artifactId> |
|||
<packaging>war</packaging> |
|||
<version>1.0-SNAPSHOT</version> |
|||
|
|||
<name>myssm Maven Webapp</name> |
|||
<url>http://maven.apache.org</url> |
|||
|
|||
<properties> |
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
|||
<maven.compiler.source>11</maven.compiler.source> |
|||
<maven.compiler.target>11</maven.compiler.target> |
|||
<spring.version>5.0.2.RELEASE</spring.version> |
|||
<slf4j.version>1.6.6</slf4j.version> |
|||
<log4j.version>1.2.12</log4j.version> |
|||
<mysql.version>8.0.33</mysql.version> |
|||
<mybatis.version>3.4.5</mybatis.version> |
|||
</properties> |
|||
|
|||
<dependencies> |
|||
<!--spring --> |
|||
|
|||
<dependency> |
|||
<groupId>org.aspectj</groupId> |
|||
<artifactId>aspectjweaver</artifactId> |
|||
<version>1.6.8</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework</groupId> |
|||
<artifactId>spring-aop</artifactId> |
|||
<version>${spring.version}</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework</groupId> |
|||
<artifactId>spring-context</artifactId> |
|||
<version>${spring.version}</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework</groupId> |
|||
<artifactId>spring-web</artifactId> |
|||
<version>${spring.version}</version> |
|||
</dependency> |
|||
|
|||
|
|||
<dependency> |
|||
<groupId>org.springframework</groupId> |
|||
<artifactId>spring-webmvc</artifactId> |
|||
<version>${spring.version}</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework</groupId> |
|||
<artifactId>spring-test</artifactId> |
|||
<version>${spring.version}</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework</groupId> |
|||
<artifactId>spring-tx</artifactId> |
|||
<version>${spring.version}</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework</groupId> |
|||
<artifactId>spring-jdbc</artifactId> |
|||
<version>${spring.version}</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.springframework</groupId> |
|||
<artifactId>spring-core</artifactId> |
|||
<version>5.3.27</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>mysql</groupId> |
|||
<artifactId>mysql-connector-java</artifactId> |
|||
<version>${mysql.version}</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>javax.servlet</groupId> |
|||
<artifactId>servlet-api</artifactId> |
|||
<version>2.5</version> |
|||
<scope>provided</scope> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>javax.servlet.jsp</groupId> |
|||
<artifactId>jsp-api</artifactId> |
|||
<version>2.0</version> |
|||
<scope>provided</scope> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>jstl</groupId> |
|||
<artifactId>jstl</artifactId> |
|||
<version>1.2</version> |
|||
</dependency> |
|||
|
|||
<!-- log start --> |
|||
<dependency> |
|||
<groupId>log4j</groupId> |
|||
<artifactId>log4j</artifactId> |
|||
<version>${log4j.version}</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.slf4j</groupId> |
|||
<artifactId>slf4j-api</artifactId> |
|||
<version>${slf4j.version}</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.slf4j</groupId> |
|||
<artifactId>slf4j-log4j12</artifactId> |
|||
<version>${slf4j.version}</version> |
|||
</dependency> |
|||
<!-- log end --> |
|||
<dependency> |
|||
<groupId>org.mybatis</groupId> |
|||
<artifactId>mybatis</artifactId> |
|||
<version>${mybatis.version}</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.mybatis</groupId> |
|||
<artifactId>mybatis-spring</artifactId> |
|||
<version>1.3.0</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>c3p0</groupId> |
|||
<artifactId>c3p0</artifactId> |
|||
<version>0.9.1.2</version> |
|||
<type>jar</type> |
|||
<scope>compile</scope> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>junit</groupId> |
|||
<artifactId>junit</artifactId> |
|||
<version>4.13.2</version> |
|||
<scope>compile</scope> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>javax.annotation</groupId> |
|||
<artifactId>javax.annotation-api</artifactId> |
|||
<version>1.3.2</version> |
|||
</dependency> |
|||
<!--easy-captcha 图形验证码 --> |
|||
<dependency> |
|||
<groupId>com.github.whvcse</groupId> |
|||
<artifactId>easy-captcha</artifactId> |
|||
<version>1.6.2</version> |
|||
</dependency> |
|||
<!-- redis --> |
|||
<dependency> |
|||
<groupId>redis.clients</groupId> |
|||
<artifactId>jedis</artifactId> |
|||
<version>3.8.0</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.data</groupId> |
|||
<artifactId>spring-data-redis</artifactId> |
|||
<version>2.7.11</version> |
|||
</dependency> |
|||
<!--token生成--> |
|||
<dependency> |
|||
<groupId>com.auth0</groupId> |
|||
<artifactId>java-jwt</artifactId> |
|||
<version>3.4.0</version> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>com.alibaba</groupId> |
|||
<artifactId>fastjson</artifactId> |
|||
<version>1.2.76</version> |
|||
</dependency> |
|||
</dependencies> |
|||
<build> |
|||
<finalName>myssm</finalName> |
|||
<pluginManagement> |
|||
<plugins> |
|||
<plugin> |
|||
<artifactId>maven-clean-plugin</artifactId> |
|||
<version>3.1.0</version> |
|||
</plugin> |
|||
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --> |
|||
<plugin> |
|||
<artifactId>maven-resources-plugin</artifactId> |
|||
<version>3.0.2</version> |
|||
</plugin> |
|||
<plugin> |
|||
<artifactId>maven-compiler-plugin</artifactId> |
|||
<version>3.8.0</version> |
|||
</plugin> |
|||
<plugin> |
|||
<artifactId>maven-surefire-plugin</artifactId> |
|||
<version>2.22.1</version> |
|||
</plugin> |
|||
<plugin> |
|||
<artifactId>maven-war-plugin</artifactId> |
|||
<version>3.2.2</version> |
|||
</plugin> |
|||
<plugin> |
|||
<artifactId>maven-install-plugin</artifactId> |
|||
<version>2.5.2</version> |
|||
</plugin> |
|||
<plugin> |
|||
<artifactId>maven-deploy-plugin</artifactId> |
|||
<version>2.8.2</version> |
|||
</plugin> |
|||
</plugins> |
|||
</pluginManagement> |
|||
<plugins> |
|||
<plugin> |
|||
<groupId>org.apache.tomcat.maven</groupId> |
|||
<artifactId>tomcat7-maven-plugin</artifactId> |
|||
<version>2.2</version> <!-- 推荐使用稳定版本 --> |
|||
<!-- 可选配置:自定义端口、上下文路径等 --> |
|||
<configuration> |
|||
<port>8080</port> <!-- 端口号 --> |
|||
<path>/</path> <!-- 项目访问路径(根路径) --> |
|||
<uriEncoding>UTF-8</uriEncoding> <!-- 解决中文乱码 --> |
|||
</configuration> |
|||
</plugin> |
|||
</plugins> |
|||
</build> |
|||
</project> |
|||
@ -0,0 +1,60 @@ |
|||
package cn.star.common; |
|||
|
|||
public class ApiResponse<T> { |
|||
// 状态码:200表示成功,其他表示错误 |
|||
private int code; |
|||
// 响应消息:成功或错误描述 |
|||
private String message; |
|||
// 响应数据:成功时返回的数据 |
|||
private T data; |
|||
|
|||
// 无参构造方法(JSON序列化需要) |
|||
public ApiResponse() {} |
|||
|
|||
// 全参构造方法 |
|||
public ApiResponse(int code, String message, T data) { |
|||
this.code = code; |
|||
this.message = message; |
|||
this.data = data; |
|||
} |
|||
|
|||
// 静态方法:快速创建成功响应(带数据) |
|||
public static <T> ApiResponse<T> success(T data) { |
|||
return new ApiResponse<>(200, "操作成功", data); |
|||
} |
|||
|
|||
// 静态方法:快速创建成功响应(无数据) |
|||
public static <T> ApiResponse<T> success() { |
|||
return new ApiResponse<>(200, "操作成功", null); |
|||
} |
|||
|
|||
// 静态方法:快速创建错误响应 |
|||
public static <T> ApiResponse<T> error(int code, String message) { |
|||
return new ApiResponse<>(code, message, null); |
|||
} |
|||
|
|||
// getter和setter方法(JSON序列化需要) |
|||
public int getCode() { |
|||
return code; |
|||
} |
|||
|
|||
public void setCode(int code) { |
|||
this.code = code; |
|||
} |
|||
|
|||
public String getMessage() { |
|||
return message; |
|||
} |
|||
|
|||
public void setMessage(String message) { |
|||
this.message = message; |
|||
} |
|||
|
|||
public T getData() { |
|||
return data; |
|||
} |
|||
|
|||
public void setData(T data) { |
|||
this.data = data; |
|||
} |
|||
} |
|||
@ -0,0 +1,178 @@ |
|||
package cn.star.controller; |
|||
|
|||
//创建用户控制层UserController类 |
|||
|
|||
|
|||
import cn.star.domian.Users; |
|||
import cn.star.service.UsersService; |
|||
|
|||
|
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Controller; |
|||
import org.springframework.ui.Model; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.servlet.mvc.support.RedirectAttributes; |
|||
|
|||
|
|||
import javax.imageio.ImageIO; |
|||
import javax.servlet.http.HttpServletRequest; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
import javax.servlet.http.HttpSession; |
|||
import java.awt.*; |
|||
import java.awt.font.FontRenderContext; |
|||
import java.awt.geom.Rectangle2D; |
|||
import java.awt.image.BufferedImage; |
|||
import java.io.ByteArrayOutputStream; |
|||
import javax.servlet.ServletOutputStream; |
|||
import java.io.IOException; |
|||
import java.util.List; |
|||
import java.util.Random; |
|||
|
|||
@Controller |
|||
@RequestMapping("/users") |
|||
public class UserController { |
|||
@Autowired |
|||
private UsersService usersService; |
|||
|
|||
private static final Logger logger = LoggerFactory.getLogger(UserController.class); |
|||
|
|||
@RequestMapping("/findUsers") |
|||
/*public String findUsers() { |
|||
System.out.println("表现层:查询用户"); |
|||
//调用service对象得方法进行测试 |
|||
usersService.findUsers(); |
|||
return "Users"; |
|||
}*/ |
|||
public String findUsers(Model model) { |
|||
System.out.println("表现层:查询用户"); |
|||
List<Users> list = usersService.findUsers(); |
|||
model.addAttribute("list",list); |
|||
return "Users"; |
|||
} |
|||
|
|||
@RequestMapping("/insert") |
|||
public String insert(Users users) { |
|||
System.out.println("注册"); |
|||
usersService.insertUsers(users); |
|||
return "success"; |
|||
} |
|||
|
|||
@RequestMapping("/login") |
|||
public String login(HttpServletRequest request, HttpSession session, RedirectAttributes redirectAttributes) |
|||
{ |
|||
//先获取请求参数-验证码、账号、密码 |
|||
String verifyCode = request.getParameter("verifyCode"); |
|||
String username = request.getParameter("username"); |
|||
String password = request.getParameter("password"); |
|||
|
|||
//获取session中存储的验证码 |
|||
String sessionVerifyCode = (String) session.getAttribute("verifyCodeValue"); |
|||
|
|||
//执行你的验证码校验 |
|||
if (!verifyCode.equals(sessionVerifyCode)) { |
|||
logger.info("登陆失败,验证码输入有误"); |
|||
redirectAttributes.addFlashAttribute("message", "验证码输入有误"); |
|||
return "falselogin"; |
|||
} |
|||
//验证用户名密码 |
|||
Users users = new Users(); |
|||
users.setUsername(username); |
|||
users.setPassword(password); |
|||
if(usersService.login(users)) { |
|||
session.setAttribute("users",users); |
|||
return "successlogin"; |
|||
} |
|||
else { |
|||
redirectAttributes.addFlashAttribute("message","用户名或密码错误"); |
|||
return "falselogin"; |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
/*System.out.println("登录"); |
|||
if(usersService.login(users)) { |
|||
return "successlogin"; |
|||
} |
|||
else { |
|||
return "falselogin"; |
|||
}*/ |
|||
|
|||
|
|||
/* 获取校验码 */ |
|||
@RequestMapping("/getVerifyCode") |
|||
public void generate(HttpServletResponse response, HttpSession session) { |
|||
response.setContentType("image/jpeg");//保证浏览器正确解析图片 |
|||
ByteArrayOutputStream output = new ByteArrayOutputStream(); |
|||
String verifyCodeValue = drawImg(output); |
|||
// 将校验码保存到session中 |
|||
session.setAttribute("verifyCodeValue", verifyCodeValue); |
|||
|
|||
try { |
|||
ServletOutputStream out = response.getOutputStream(); |
|||
output.writeTo(out); |
|||
} catch (IOException e) { |
|||
logger.info("<--验证码前端写出.出现异常-->"); |
|||
e.printStackTrace(); |
|||
|
|||
} |
|||
} |
|||
|
|||
/* 绘制验证码 */ |
|||
private String drawImg(ByteArrayOutputStream output) { |
|||
String code = ""; |
|||
// 随机产生4个字符 |
|||
for (int i = 0; i < 4; i++) { |
|||
code += randomChar(); |
|||
} |
|||
int width = 70; |
|||
int height = 25; |
|||
BufferedImage bi = new BufferedImage(width, height, |
|||
BufferedImage.TYPE_3BYTE_BGR); |
|||
Font font = new Font("Times New Roman", Font.PLAIN, 20); |
|||
// 调用Graphics2D绘画验证码 |
|||
Graphics2D g = bi.createGraphics(); |
|||
g.setFont(font); |
|||
Color color = new Color(66, 2, 82); |
|||
g.setColor(color); |
|||
g.setBackground(new Color(226, 226, 240)); |
|||
g.clearRect(0, 0, width, height); |
|||
FontRenderContext context = g.getFontRenderContext(); |
|||
Rectangle2D bounds = font.getStringBounds(code, context); |
|||
double x = (width - bounds.getWidth()) / 2; |
|||
double y = (height - bounds.getHeight()) / 2; |
|||
double ascent = bounds.getY(); |
|||
double baseY = y - ascent; |
|||
g.drawString(code, (int) x, (int) baseY); |
|||
g.dispose(); |
|||
try { |
|||
ImageIO.write(bi, "jpg", output); |
|||
} catch (IOException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return code; |
|||
} |
|||
|
|||
/* 获取随机参数 */ |
|||
private char randomChar() { |
|||
Random r = new Random(); |
|||
String s = "ABCDEFGHJKLMNPRSTUVWXYZ0123456789"; |
|||
return s.charAt(r.nextInt(s.length())); |
|||
} |
|||
|
|||
/*@Resource |
|||
private RedisUtil redisUtil; |
|||
|
|||
@RequestMapping("/test") |
|||
public String testRedis() { |
|||
if(!redisUtil.hasKey("test01")) { |
|||
redisUtil.set("test01","测试redis"); |
|||
} |
|||
System.out.println(redisUtil.get("test01")); |
|||
return "success"; |
|||
}*/ |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
package cn.star.dao; |
|||
|
|||
import cn.star.domian.Users; |
|||
import org.apache.ibatis.annotations.Insert; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
import org.apache.ibatis.annotations.Select; |
|||
import org.springframework.stereotype.Repository; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Repository//注入dao数据 |
|||
//这里是创建一个数据访问层UserDao接口 |
|||
public interface UsersDao { |
|||
//查询所有用户 |
|||
@Select("select * from users") |
|||
public List<Users> findUsers(); |
|||
//用户注册 |
|||
@Insert("INSERT INTO USERS (username,password) VALUES(#{username},#{password})") |
|||
public void insertUsers(Users users); |
|||
//用户登录 |
|||
@Select("select * from users where username=#{username} and password=#{password}") |
|||
public Users login(Users users); |
|||
|
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
package cn.star.domian; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
public class Users implements Serializable { |
|||
private Integer id; |
|||
private String username; |
|||
private String password; |
|||
|
|||
public String getPassword() { |
|||
return password; |
|||
} |
|||
|
|||
public void setPassword(String password) { |
|||
this.password = password; |
|||
} |
|||
|
|||
|
|||
|
|||
public Integer getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(Integer id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public String getUsername() { |
|||
return username; |
|||
} |
|||
|
|||
public void setUsername(String username) { |
|||
this.username = username; |
|||
} |
|||
|
|||
//这段代码都敲不明白 |
|||
@Override |
|||
public String toString(){ |
|||
return "Users{" + |
|||
"id=" + id + |
|||
", username='" + username + '\'' + |
|||
", password='" + password + '\'' + |
|||
'}'; |
|||
} |
|||
} |
|||
@ -0,0 +1,91 @@ |
|||
/*package cn.star.interceptor; |
|||
|
|||
import cn.star.common.ApiResponse; |
|||
import cn.star.util.JwtUtil; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import org.springframework.web.method.HandlerMethod; |
|||
import org.springframework.web.servlet.HandlerInterceptor; |
|||
import org.springframework.web.servlet.ModelAndView; |
|||
|
|||
import javax.servlet.http.Cookie; |
|||
import javax.servlet.http.HttpServletRequest; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.io.IOException; |
|||
import java.io.PrintWriter; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
public class TokenInterceptor implements HandlerInterceptor { |
|||
|
|||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException { |
|||
|
|||
// 只处理HandlerMethod类型的处理器(排除静态资源等) |
|||
if (!(handler instanceof HandlerMethod)) { |
|||
return true; |
|||
} |
|||
|
|||
System.out.println("执行方法之前执行这步操作"); |
|||
response.setCharacterEncoding("utf-8"); |
|||
|
|||
Cookie cookie = getCookieByName(request,"COOKIE_NAME"); |
|||
|
|||
if(null != cookie) { |
|||
boolean result = JwtUtil.verify(cookie.getValue()); |
|||
if(!result) { |
|||
response.sendRedirect(request.getContextPath() + "/login"); |
|||
return false; |
|||
} |
|||
return true; |
|||
} |
|||
else { |
|||
response.sendRedirect(request.getContextPath() + "/login"); |
|||
|
|||
return false; |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) |
|||
throws Exception { |
|||
} |
|||
|
|||
@Override |
|||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {} |
|||
|
|||
//根据名字获取cookie |
|||
public static Cookie getCookieByName(HttpServletRequest request , String name) { |
|||
Map<String,Cookie> cookieMap = ReadCookieMap(request); |
|||
if (cookieMap.containsKey(name)) { |
|||
Cookie cookie = cookieMap.get(name); |
|||
return cookie; |
|||
} |
|||
else { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
private static Map<String,Cookie> ReadCookieMap(HttpServletRequest request) { |
|||
Map<String,Cookie> cookieMap = new HashMap<String,Cookie>(); |
|||
Cookie[] cookies = request.getCookies(); |
|||
if (cookies != null) { |
|||
for (Cookie cookie : cookies) { |
|||
cookieMap.put(cookie.getName(), cookie); |
|||
} |
|||
} |
|||
return cookieMap; |
|||
} |
|||
|
|||
private void responseMessage(HttpServletRequest request, HttpServletResponse response, PrintWriter out, ApiResponse apiResponse) |
|||
throws IOException |
|||
{ |
|||
response.setContentType("text/html;charset=utf-8"); |
|||
out.print(JSONObject.toJSONString(apiResponse));//这个ApiResponse需要创建一个类然后调用 |
|||
out.flush(); |
|||
out.close(); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
}*/ |
|||
@ -0,0 +1,15 @@ |
|||
package cn.star.service; |
|||
|
|||
import cn.star.domian.Users; |
|||
|
|||
import java.util.List; |
|||
|
|||
//创建一个业务层UsersService接口 |
|||
public interface UsersService { |
|||
//查询所有用户 |
|||
public List<Users> findUsers(); |
|||
//用户注册 |
|||
public void insertUsers(Users users); |
|||
//用户登录 |
|||
public boolean login(Users users); |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
package cn.star.service.impl; |
|||
|
|||
import cn.star.dao.UsersDao; |
|||
import cn.star.domian.Users; |
|||
import cn.star.service.UsersService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Service("usersService")//把service交给IOC容器管理 |
|||
public class UsersServiceImpl implements UsersService { |
|||
@Autowired |
|||
private UsersDao usersDao;//注入dao得数据 |
|||
|
|||
@Override |
|||
public List<Users> findUsers() { |
|||
System.out.println("业务层:查询用户"); |
|||
return usersDao.findUsers();//改 |
|||
} |
|||
|
|||
@Override |
|||
public void insertUsers(Users users) { |
|||
System.out.println("业务层:用户注册"); |
|||
usersDao.insertUsers(users);//有修改 |
|||
} |
|||
|
|||
@Override |
|||
public boolean login(Users users) { |
|||
System.out.println("业务层:用户登录"); |
|||
if(usersDao.login(users) == null) { |
|||
return false; |
|||
} |
|||
else { |
|||
return true; |
|||
}//有修改 |
|||
} |
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
package cn.star.test; |
|||
|
|||
import cn.star.dao.UsersDao; |
|||
import cn.star.domian.Users; |
|||
import org.apache.ibatis.io.Resources; |
|||
import org.apache.ibatis.session.SqlSession; |
|||
import org.apache.ibatis.session.SqlSessionFactory; |
|||
import org.apache.ibatis.session.SqlSessionFactoryBuilder; |
|||
import org.junit.Test; |
|||
|
|||
import java.io.InputStream; |
|||
import java.util.List; |
|||
|
|||
//测试用户查询和注册,创建测试类 |
|||
public class MybatisTest { |
|||
|
|||
@Test |
|||
public void run1() throws Exception { |
|||
//加载配置文件 |
|||
InputStream in = Resources.getResourceAsStream("mybatis.xml"); |
|||
//创建sqlSessionFactory对象 |
|||
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in); |
|||
//创建SqlSession对象 |
|||
SqlSession session = factory.openSession(); |
|||
//获取代理对象 |
|||
UsersDao dao = session.getMapper(UsersDao.class); |
|||
//查询所有数据 |
|||
List<Users> list = dao.findUsers(); |
|||
for(Users users : list){ |
|||
System.out.println(users); |
|||
} |
|||
session.close(); |
|||
in.close();//关闭资源 |
|||
} |
|||
|
|||
@Test |
|||
public void run2() throws Exception { |
|||
Users users = new Users(); |
|||
users.setUsername("threestar"); |
|||
users.setPassword("789"); |
|||
|
|||
//加载配置文件 |
|||
InputStream in = Resources.getResourceAsStream("mybatis.xml"); |
|||
//创建SqlSessionFactory对象 |
|||
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in); |
|||
//创建SqlSession对象 |
|||
SqlSession session = factory.openSession(); |
|||
//获取到代理对象 |
|||
UsersDao dao = session.getMapper(UsersDao.class); |
|||
|
|||
//保存 |
|||
dao.insertUsers(users); |
|||
|
|||
//提交事务 |
|||
session.commit(); |
|||
|
|||
//关闭资源 |
|||
session.close(); |
|||
in.close(); |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
package cn.star.test; |
|||
|
|||
import cn.star.service.UsersService; |
|||
import org.junit.Test; |
|||
import org.springframework.context.ApplicationContext; |
|||
import org.springframework.context.support.ClassPathXmlApplicationContext; |
|||
|
|||
public class SpringTest { |
|||
@Test |
|||
public void Test(){ |
|||
//加载配置文件 |
|||
ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:spring.xml"); |
|||
//获取对象 |
|||
UsersService us = (UsersService) ac.getBean("usersService"); |
|||
//调用方法 |
|||
us.findUsers(); |
|||
} |
|||
} |
|||
@ -0,0 +1,79 @@ |
|||
package cn.star.util; |
|||
|
|||
import com.auth0.jwt.JWT; |
|||
import com.auth0.jwt.JWTVerifier; |
|||
import com.auth0.jwt.algorithms.Algorithm; |
|||
import com.auth0.jwt.interfaces.DecodedJWT; |
|||
|
|||
import java.io.UnsupportedEncodingException; |
|||
import java.util.Date; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
import static java.lang.System.currentTimeMillis; |
|||
|
|||
public class JwtUtil { |
|||
|
|||
private static final long EXPIRE_TIME = 24 * 60 * 60 * 1000; //expire-到期时间 |
|||
|
|||
// token私匙 |
|||
private static final String TOKEN_SECRET = "f26e587c28064d0e855e72c0a6a0e618";//只是模拟自己设置的? |
|||
|
|||
//校验token是否正确 |
|||
public static boolean verify(String token) { |
|||
try { |
|||
Algorithm algorithm = Algorithm.HMAC256(TOKEN_SECRET); |
|||
JWTVerifier verifier = JWT.require(algorithm).build(); |
|||
DecodedJWT jwt = verifier.verify(token); |
|||
return true; |
|||
} catch (Exception e) { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
//return token包含的用户名 |
|||
public static String getUsername(String token) { |
|||
try { |
|||
DecodedJWT jwt = JWT.decode(token); |
|||
return jwt.getClaim("username").asString(); |
|||
} catch (Exception e) { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
//获取登录用户id |
|||
public static String getUserId(String token) { |
|||
try { |
|||
DecodedJWT jwt = JWT.decode(token); |
|||
return jwt.getClaim("userId").asString(); |
|||
} catch (Exception e) { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
//生成签名,15min后过期 |
|||
public static String sign(String username,String userId) { |
|||
// 过期时间 |
|||
Date date = new Date(System.currentTimeMillis() + EXPIRE_TIME); |
|||
// 私钥及加密算法 |
|||
Algorithm algorithm = Algorithm.HMAC256(TOKEN_SECRET); |
|||
// 设置头部信息 |
|||
Map<String, Object> header = new HashMap<>(2); |
|||
header.put("typ", "JWT"); |
|||
header.put("alg", "HS256"); |
|||
// 附带username,userId信息,生成签名 |
|||
return JWT.create() |
|||
.withHeader(header) |
|||
.withClaim("loginName", username) |
|||
.withClaim("userId",userId) |
|||
.withExpiresAt(date) |
|||
.sign(algorithm); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
@ -0,0 +1,567 @@ |
|||
package cn.star.util; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.data.redis.core.RedisTemplate; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.util.CollectionUtils; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.Set; |
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
@Component |
|||
public final class RedisUtil { |
|||
|
|||
@Autowired |
|||
private RedisTemplate redisTemplate; |
|||
|
|||
public void setEx(String key, String value, long timeout, TimeUnit unit) { |
|||
redisTemplate.opsForValue().set(key, value, timeout, unit); |
|||
} |
|||
|
|||
/** |
|||
* 指定缓存失效时间 |
|||
* |
|||
* @param key 键 |
|||
* @param time 时间(秒) |
|||
* @return |
|||
*/ |
|||
public boolean expire(String key, long time) { |
|||
try { |
|||
if (time > 0) { |
|||
redisTemplate.expire(key, time, TimeUnit.SECONDS); |
|||
} |
|||
return true; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 根据key 获取过期时间 |
|||
* |
|||
* @param key 键 不能为null |
|||
* @return 时间(秒) 返回0代表为永久有效 |
|||
*/ |
|||
public long getExpire(String key) { |
|||
return redisTemplate.getExpire(key, TimeUnit.SECONDS); |
|||
} |
|||
|
|||
/** |
|||
* 判断key是否存在 |
|||
* |
|||
* @param key 键 |
|||
* @return true 存在 false不存在 |
|||
*/ |
|||
public boolean hasKey(String key) { |
|||
try { |
|||
return redisTemplate.hasKey(key); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 删除缓存 |
|||
* |
|||
* @param key 可以传一个值 或多个 |
|||
*/ |
|||
@SuppressWarnings("unchecked") |
|||
public void del(String... key) { |
|||
if (key != null && key.length > 0) { |
|||
if (key.length == 1) { |
|||
redisTemplate.delete(key[0]); |
|||
} else { |
|||
redisTemplate.delete(CollectionUtils.arrayToList(key)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 普通缓存获取 |
|||
* |
|||
* @param key 键 |
|||
* @return 值 |
|||
*/ |
|||
public Object get(String key) { |
|||
return key == null ? null : redisTemplate.opsForValue().get(key); |
|||
} |
|||
|
|||
/** |
|||
* 普通缓存放入 |
|||
* |
|||
* @param key 键 |
|||
* @param value 值 |
|||
* @return true成功 false失败 |
|||
*/ |
|||
public boolean set(String key, Object value) { |
|||
try { |
|||
redisTemplate.opsForValue().set(key, value); |
|||
return true; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return false; |
|||
} |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 普通缓存放入并设置时间 |
|||
* |
|||
* @param key 键 |
|||
* @param value 值 |
|||
* @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 |
|||
* @return true成功 false 失败 |
|||
*/ |
|||
public boolean set(String key, Object value, long time) { |
|||
try { |
|||
if (time > 0) { |
|||
redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS); |
|||
} else { |
|||
set(key, value); |
|||
} |
|||
return true; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 递增 |
|||
* |
|||
* @param key 键 |
|||
* @param delta 要增加几(大于0) |
|||
* @return |
|||
*/ |
|||
public long incr(String key, long delta) { |
|||
if (delta < 0) { |
|||
throw new RuntimeException("递增因子必须大于0"); |
|||
} |
|||
return redisTemplate.opsForValue().increment(key, delta); |
|||
} |
|||
|
|||
/** |
|||
* 递减 |
|||
* |
|||
* @param key 键 |
|||
* @param delta 要减少几(小于0) |
|||
* @return |
|||
*/ |
|||
public long decr(String key, long delta) { |
|||
if (delta < 0) { |
|||
throw new RuntimeException("递减因子必须大于0"); |
|||
} |
|||
return redisTemplate.opsForValue().increment(key, -delta); |
|||
} |
|||
|
|||
// ================================Map================================= |
|||
|
|||
/** |
|||
* HashGet |
|||
* |
|||
* @param key 键 不能为null |
|||
* @param item 项 不能为null |
|||
* @return 值 |
|||
*/ |
|||
public Object hget(String key, String item) { |
|||
return redisTemplate.opsForHash().get(key, item); |
|||
} |
|||
|
|||
/** |
|||
* 获取hashKey对应的所有键值 |
|||
* |
|||
* @param key 键 |
|||
* @return 对应的多个键值 |
|||
*/ |
|||
public Map<Object, Object> hmget(String key) { |
|||
return redisTemplate.opsForHash().entries(key); |
|||
} |
|||
|
|||
/** |
|||
* HashSet |
|||
* |
|||
* @param key 键 |
|||
* @param map 对应多个键值 |
|||
* @return true 成功 false 失败 |
|||
*/ |
|||
public boolean hmset(String key, Map<String, Object> map) { |
|||
try { |
|||
redisTemplate.opsForHash().putAll(key, map); |
|||
return true; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* HashSet 并设置时间 |
|||
* |
|||
* @param key 键 |
|||
* @param map 对应多个键值 |
|||
* @param time 时间(秒) |
|||
* @return true成功 false失败 |
|||
*/ |
|||
public boolean hmset(String key, Map<String, Object> map, long time) { |
|||
try { |
|||
redisTemplate.opsForHash().putAll(key, map); |
|||
if (time > 0) { |
|||
expire(key, time); |
|||
} |
|||
return true; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 向一张hash表中放入数据,如果不存在将创建 |
|||
* |
|||
* @param key 键 |
|||
* @param item 项 |
|||
* @param value 值 |
|||
* @return true 成功 false失败 |
|||
*/ |
|||
public boolean hset(String key, String item, Object value) { |
|||
try { |
|||
redisTemplate.opsForHash().put(key, item, value); |
|||
return true; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 向一张hash表中放入数据,如果不存在将创建 |
|||
* |
|||
* @param key 键 |
|||
* @param item 项 |
|||
* @param value 值 |
|||
* @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间 |
|||
* @return true 成功 false失败 |
|||
*/ |
|||
public boolean hset(String key, String item, Object value, long time) { |
|||
try { |
|||
redisTemplate.opsForHash().put(key, item, value); |
|||
if (time > 0) { |
|||
expire(key, time); |
|||
} |
|||
return true; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 删除hash表中的值 |
|||
* |
|||
* @param key 键 不能为null |
|||
* @param item 项 可以使多个 不能为null |
|||
*/ |
|||
public void hdel(String key, Object... item) { |
|||
redisTemplate.opsForHash().delete(key, item); |
|||
} |
|||
|
|||
/** |
|||
* 判断hash表中是否有该项的值 |
|||
* |
|||
* @param key 键 不能为null |
|||
* @param item 项 不能为null |
|||
* @return true 存在 false不存在 |
|||
*/ |
|||
public boolean hHasKey(String key, String item) { |
|||
return redisTemplate.opsForHash().hasKey(key, item); |
|||
} |
|||
|
|||
/** |
|||
* hash递增 如果不存在,就会创建一个 并把新增后的值返回 |
|||
* |
|||
* @param key 键 |
|||
* @param item 项 |
|||
* @param by 要增加几(大于0) |
|||
* @return |
|||
*/ |
|||
public double hincr(String key, String item, double by) { |
|||
return redisTemplate.opsForHash().increment(key, item, by); |
|||
} |
|||
|
|||
/** |
|||
* hash递减 |
|||
* |
|||
* @param key 键 |
|||
* @param item 项 |
|||
* @param by 要减少记(小于0) |
|||
* @return |
|||
*/ |
|||
public double hdecr(String key, String item, double by) { |
|||
return redisTemplate.opsForHash().increment(key, item, -by); |
|||
} |
|||
|
|||
// ============================set============================= |
|||
|
|||
/** |
|||
* 根据key获取Set中的所有值 |
|||
* |
|||
* @param key 键 |
|||
* @return |
|||
*/ |
|||
public Set<Object> sGet(String key) { |
|||
try { |
|||
return redisTemplate.opsForSet().members(key); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 根据value从一个set中查询,是否存在 |
|||
* |
|||
* @param key 键 |
|||
* @param value 值 |
|||
* @return true 存在 false不存在 |
|||
*/ |
|||
public boolean sHasKey(String key, Object value) { |
|||
try { |
|||
return redisTemplate.opsForSet().isMember(key, value); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 将数据放入set缓存 |
|||
* |
|||
* @param key 键 |
|||
* @param values 值 可以是多个 |
|||
* @return 成功个数 |
|||
*/ |
|||
public long sSet(String key, Object... values) { |
|||
try { |
|||
return redisTemplate.opsForSet().add(key, values); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 将set数据放入缓存 |
|||
* |
|||
* @param key 键 |
|||
* @param time 时间(秒) |
|||
* @param values 值 可以是多个 |
|||
* @return 成功个数 |
|||
*/ |
|||
public long sSetAndTime(String key, long time, Object... values) { |
|||
try { |
|||
Long count = redisTemplate.opsForSet().add(key, values); |
|||
if (time > 0) |
|||
expire(key, time); |
|||
return count; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 获取set缓存的长度 |
|||
* |
|||
* @param key 键 |
|||
* @return |
|||
*/ |
|||
public long sGetSetSize(String key) { |
|||
try { |
|||
return redisTemplate.opsForSet().size(key); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 移除值为value的 |
|||
* |
|||
* @param key 键 |
|||
* @param values 值 可以是多个 |
|||
* @return 移除的个数 |
|||
*/ |
|||
public long setRemove(String key, Object... values) { |
|||
try { |
|||
Long count = redisTemplate.opsForSet().remove(key, values); |
|||
return count; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return 0; |
|||
} |
|||
} |
|||
// ===============================list================================= |
|||
|
|||
/** |
|||
* 获取list缓存的内容 |
|||
* |
|||
* @param key 键 |
|||
* @param start 开始 |
|||
* @param end 结束 0 到 -1代表所有值 |
|||
* @return |
|||
*/ |
|||
public List<Object> lGet(String key, long start, long end) { |
|||
try { |
|||
return redisTemplate.opsForList().range(key, start, end); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 获取list缓存的长度 |
|||
* |
|||
* @param key 键 |
|||
* @return |
|||
*/ |
|||
public long lGetListSize(String key) { |
|||
try { |
|||
return redisTemplate.opsForList().size(key); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 通过索引 获取list中的值 |
|||
* |
|||
* @param key 键 |
|||
* @param index 索引 index>0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推 |
|||
* @return |
|||
*/ |
|||
public Object lGetIndex(String key, long index) { |
|||
try { |
|||
return redisTemplate.opsForList().index(key, index); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 将list放入缓存 |
|||
* |
|||
* @param key 键 |
|||
* @param value 值 |
|||
* @return |
|||
*/ |
|||
public boolean lSet(String key, Object value) { |
|||
try { |
|||
redisTemplate.opsForList().rightPush(key, value); |
|||
return true; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 将list放入缓存 |
|||
* |
|||
* @param key 键 |
|||
* @param value 值 |
|||
* @param time 时间(秒) |
|||
* @return |
|||
*/ |
|||
public boolean lSet(String key, Object value, long time) { |
|||
try { |
|||
redisTemplate.opsForList().rightPush(key, value); |
|||
if (time > 0) |
|||
expire(key, time); |
|||
return true; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 将list放入缓存 |
|||
* |
|||
* @param key 键 |
|||
* @param value 值 |
|||
* @return |
|||
*/ |
|||
public boolean lSet(String key, List<Object> value) { |
|||
try { |
|||
redisTemplate.opsForList().rightPushAll(key, value); |
|||
return true; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 将list放入缓存 |
|||
* |
|||
* @param key 键 |
|||
* @param value 值 |
|||
* @param time 时间(秒) |
|||
* @return |
|||
*/ |
|||
public boolean lSet(String key, List<Object> value, long time) { |
|||
try { |
|||
redisTemplate.opsForList().rightPushAll(key, value); |
|||
if (time > 0) |
|||
expire(key, time); |
|||
return true; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 根据索引修改list中的某条数据 |
|||
* |
|||
* @param key 键 |
|||
* @param index 索引 |
|||
* @param value 值 |
|||
* @return |
|||
*/ |
|||
public boolean lUpdateIndex(String key, long index, Object value) { |
|||
try { |
|||
redisTemplate.opsForList().set(key, index, value); |
|||
return true; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 移除N个值为value |
|||
* |
|||
* @param key 键 |
|||
* @param count 移除多少个 |
|||
* @param value 值 |
|||
* @return 移除的个数 |
|||
*/ |
|||
public long lRemove(String key, long count, Object value) { |
|||
try { |
|||
Long remove = redisTemplate.opsForList().remove(key, count, value); |
|||
return remove; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,66 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<beans xmlns="http://www.springframework.org/schema/beans" |
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xmlns:p="http://www.springframework.org/schema/p" |
|||
xmlns:context="http://www.springframework.org/schema/context" |
|||
xsi:schemaLocation=" |
|||
http://www.springframework.org/schema/beans |
|||
http://www.springframework.org/schema/beans/spring-beans.xsd |
|||
http://www.springframework.org/schema/context |
|||
http://www.springframework.org/schema/context/spring-context.xsd"> |
|||
<!--扫描redis配置文件--> |
|||
<context:property-placeholder ignore-unresolvable="true" location="classpath:redis.properties"/> |
|||
<!--设置连接池--> |
|||
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig"> |
|||
<!-- 最大空闲连接数 --> |
|||
<property name="maxIdle" value="${redis.maxIdle}"/> |
|||
<!-- 最大连接数 --> |
|||
<property name="maxTotal" value="${redis.maxTotal}" /> |
|||
<!-- 每次释放连接的最大数目 --> |
|||
<property name="numTestsPerEvictionRun" value="${redis.numTestsPerEvictionRun}" /> |
|||
<!-- 释放连接的扫描间隔(毫秒) --> |
|||
<property name="timeBetweenEvictionRunsMillis" value="${redis.timeBetweenEvictionRunsMillis}" /> |
|||
<!-- 连接最小空闲时间 --> |
|||
<property name="minEvictableIdleTimeMillis" value="${redis.minEvictableIdleTimeMillis}" /> |
|||
<!-- 获取连接时的最大等待毫秒数,小于零:阻塞不确定的时间,默认-1 --> |
|||
<property name="maxWaitMillis" value="${redis.maxWaitMillis}" /> |
|||
<!-- 在获取连接的时候检查有效性, 默认false --> |
|||
<property name="testOnBorrow" value="${redis.testOnBorrow}" /> |
|||
<property name="testOnReturn" value="${redis.testOnReturn}" /> |
|||
<!-- 在空闲时检查有效性, 默认false --> |
|||
<property name="testWhileIdle" value="${redis.testWhileIdle}" /> |
|||
<!-- 连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true --> |
|||
<property name="blockWhenExhausted" value="${redis.blockWhenExhausted}" /> |
|||
</bean> |
|||
<!--Spring整合Jedis,设置连接属性--> |
|||
<bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" |
|||
p:hostName="${redis.host}" |
|||
p:port="${redis.port}" |
|||
p:password="${redis.password}" |
|||
p:pool-config-ref="poolConfig" |
|||
p:timeout="100000"/> |
|||
|
|||
<bean id="redisTemplate" |
|||
class="org.springframework.data.redis.core.StringRedisTemplate"> |
|||
<property name="connectionFactory" ref="connectionFactory" /> |
|||
<!-- 如果不配置Serializer,那么存储的时候只能使用String,如果用对象类型存储,那么会提示错误 can't cast to String!!!--> |
|||
<property name="keySerializer"> |
|||
<!--对key的默认序列化器。默认值是StringSerializer--> |
|||
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/> |
|||
</property> |
|||
<!--是对value的默认序列化器,默认值是取自DefaultSerializer的JdkSerializationRedisSerializer。--> |
|||
<property name="valueSerializer"> |
|||
<bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/> |
|||
</property> |
|||
<!--存储Map时key需要的序列化配置--> |
|||
<property name="hashKeySerializer"> |
|||
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/> |
|||
</property> |
|||
<!--存储Map时value需要的序列化配置--> |
|||
<property name="hashValueSerializer"> |
|||
<bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/> |
|||
</property> |
|||
</bean> |
|||
<!--配置redis工具类bean--> |
|||
<bean id="redisUtils" class="cn.star.util.RedisUtil"/> |
|||
</beans> |
|||
@ -0,0 +1,4 @@ |
|||
spring.datasource.jdbcUrl="jdbc:mysql:///myssm" |
|||
spring.datasource.user=root |
|||
spring.datasource.password=123456789chen |
|||
spring.datasource.driverClass=com.mysql.cj.jdbc.Driver |
|||
@ -0,0 +1,18 @@ |
|||
# Set root category priority to INFO and its only appender to CONSOLE. |
|||
#log4j.rootCategory=INFO, CONSOLE debug info warn error fatal |
|||
log4j.rootCategory=info, CONSOLE, LOGFILE |
|||
|
|||
# Set the enterprise logger category to FATAL and its only appender to CONSOLE. |
|||
log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE |
|||
|
|||
# CONSOLE is set to be a ConsoleAppender using a PatternLayout. |
|||
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender |
|||
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout |
|||
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m\n |
|||
|
|||
# LOGFILE is set to be a File appender using a PatternLayout. |
|||
log4j.appender.LOGFILE=org.apache.log4j.FileAppender |
|||
log4j.appender.LOGFILE.File=d:\axis.log |
|||
log4j.appender.LOGFILE.Append=true |
|||
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout |
|||
log4j.appender.LOGFILE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m\n |
|||
@ -0,0 +1,23 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE configuration |
|||
PUBLIC "-//mybatis.org//DTD Config 3.0//EN" |
|||
"http://mybatis.org/dtd/mybatis-3-config.dtd"> |
|||
<configuration> |
|||
|
|||
<!-- 配置环境 --> |
|||
<environments default="mysql"> |
|||
<environment id="mysql"> |
|||
<transactionManager type="JDBC"/> |
|||
<dataSource type="POOLED"> |
|||
<property name="driver" value="com.mysql.cj.jdbc.Driver"/> |
|||
<property name="url" value="jdbc:mysql:///myssm"/> |
|||
<property name="username" value="root"/> |
|||
<property name="password" value="123456789chen"/> |
|||
</dataSource> |
|||
</environment> |
|||
</environments> |
|||
<!-- 引入映射配置文件 --> |
|||
<mappers> |
|||
<package name="cn.star.dao"/> |
|||
</mappers> |
|||
</configuration> |
|||
@ -0,0 +1,18 @@ |
|||
redis.host=127.0.0.1 |
|||
redis.port=6397 |
|||
redis.password=123456 |
|||
|
|||
#????? |
|||
redis.maxIdle=300 |
|||
#??????????????????????????????????-1??????? |
|||
redis.maxWaitMillis=1000 |
|||
#????? ??8 |
|||
redis.maxTotal=500 |
|||
#????????????????????????????????????????? |
|||
redis.testOnBorrow=true |
|||
redis.testOnReturn=true |
|||
redis.testWhileIdle=true |
|||
redis.blockWhenExhausted=false |
|||
redis.numTestsPerEvictionRun=1024 |
|||
redis.timeBetweenEvictionRunsMillis=30000 |
|||
redis.minEvictableIdleTimeMillis=1800000 |
|||
@ -0,0 +1,41 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<beans xmlns="http://www.springframework.org/schema/beans" |
|||
xmlns:mvc="http://www.springframework.org/schema/mvc" |
|||
xmlns:context="http://www.springframework.org/schema/context" |
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xsi:schemaLocation="http://www.springframework.org/schema/beans |
|||
http://www.springframework.org/schema/beans/spring-beans.xsd |
|||
http://www.springframework.org/schema/mvc |
|||
http://www.springframework.org/schema/mvc/spring-mvc.xsd |
|||
http://www.springframework.org/schema/context |
|||
http://www.springframework.org/schema/context/spring-context.xsd"> |
|||
|
|||
<!--开启注解扫描,只扫描Controller注解--> |
|||
<context:component-scan base-package="cn.star"> |
|||
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> |
|||
</context:component-scan> |
|||
|
|||
<!--配置的视图解析器对象--> |
|||
<bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> |
|||
<property name="prefix" value="/WEB-INF/pages/"/> |
|||
<property name="suffix" value=".jsp"/> |
|||
</bean> |
|||
|
|||
<!--过滤静态资源--> |
|||
<mvc:resources location="/static/css" mapping="/css/**" /> |
|||
<mvc:resources location="/static/images/" mapping="/images/**" /> |
|||
<mvc:resources location="/static/js/" mapping="/js/**" /> |
|||
|
|||
<!--开启SpringMVC注解的支持--> |
|||
<mvc:annotation-driven/> |
|||
|
|||
<mvc:default-servlet-handler/> |
|||
<!--自定义拦截器 |
|||
<mvc:interceptors> |
|||
<mvc:interceptor> |
|||
<mvc:mapping path="/**"/> |
|||
<mvc:exclude-mapping path="checkLogin"/> |
|||
<bean class="cn.star.interceptor.TokenInterceptor"/> |
|||
</mvc:interceptor> |
|||
</mvc:interceptors>--> |
|||
</beans> |
|||
@ -0,0 +1,45 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<beans xmlns="http://www.springframework.org/schema/beans" |
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xmlns:context="http://www.springframework.org/schema/context" |
|||
xmlns:aop="http://www.springframework.org/schema/aop" |
|||
xmlns:tx="http://www.springframework.org/schema/tx" |
|||
xsi:schemaLocation="http://www.springframework.org/schema/beans |
|||
http://www.springframework.org/schema/beans/spring-beans.xsd |
|||
http://www.springframework.org/schema/context |
|||
http://www.springframework.org/schema/context/spring-context.xsd |
|||
http://www.springframework.org/schema/aop |
|||
http://www.springframework.org/schema/aop/spring-aop.xsd |
|||
http://www.springframework.org/schema/tx |
|||
http://www.springframework.org/schema/tx/spring-tx.xsd"> |
|||
|
|||
|
|||
<!--开启注解扫描,这里service和dao是需要扫描的,controller是不需要扫描的--> |
|||
<context:component-scan base-package="cn.star"> |
|||
<!--配置要忽略的注解--> |
|||
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> |
|||
</context:component-scan> |
|||
|
|||
<context:property-placeholder ignore-unresolvable="true" location="classpath:jdbc.properties"/> |
|||
<!-- 连接池 --> |
|||
<bean id="datasource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> |
|||
<property name="driverClass" value="com.mysql.cj.jdbc.Driver"/> |
|||
<property name="jdbcUrl" value="jdbc:mysql:///myssm"/> |
|||
<property name="user" value="root"/> |
|||
<property name="password" value="123456789chen"/> |
|||
</bean> |
|||
|
|||
<!--配置SqlSessionFactory工厂 --> |
|||
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> |
|||
<property name="dataSource" ref="datasource"/> |
|||
</bean> |
|||
|
|||
<!--配置UserDao接口所在包 --> |
|||
<bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> |
|||
<property name="basePackage" value="cn.star.dao"/> |
|||
</bean> |
|||
|
|||
<import resource="classpath:application-redis.xml"/> |
|||
<!--配置好以后就没有mybatis.xml的事了,可以删去--> |
|||
</beans> |
|||
|
|||
@ -0,0 +1,18 @@ |
|||
<%-- |
|||
Created by IntelliJ IDEA. |
|||
User: yuuuu |
|||
Date: 2025/8/11 |
|||
Time: 10:42 |
|||
To change this template use File | Settings | File Templates. |
|||
--%> |
|||
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %> |
|||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> |
|||
<html> |
|||
<head> |
|||
<title>查询用户界面</title> |
|||
</head> |
|||
<body> |
|||
<h3>查询所有用户</h3> |
|||
${list} |
|||
</body> |
|||
</html> |
|||
@ -0,0 +1,17 @@ |
|||
<%-- |
|||
Created by IntelliJ IDEA. |
|||
User: yuuuu |
|||
Date: 2025/8/11 |
|||
Time: 下午3:55 |
|||
To change this template use File | Settings | File Templates. |
|||
--%> |
|||
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %> |
|||
|
|||
<html> |
|||
<head> |
|||
<title>登陆失败</title> |
|||
</head> |
|||
<body> |
|||
<h1>登陆失败</h1> |
|||
</body> |
|||
</html> |
|||
@ -0,0 +1,17 @@ |
|||
<%-- |
|||
Created by IntelliJ IDEA. |
|||
User: yuuuu |
|||
Date: 2025/8/11 |
|||
Time: 下午3:54 |
|||
To change this template use File | Settings | File Templates. |
|||
--%> |
|||
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %> |
|||
|
|||
<html> |
|||
<head> |
|||
<title>注册成功</title> |
|||
</head> |
|||
<body> |
|||
<h1>注册成功</h1> |
|||
</body> |
|||
</html> |
|||
@ -0,0 +1,17 @@ |
|||
<%-- |
|||
Created by IntelliJ IDEA. |
|||
User: yuuuu |
|||
Date: 2025/8/11 |
|||
Time: 下午3:55 |
|||
To change this template use File | Settings | File Templates. |
|||
--%> |
|||
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %> |
|||
|
|||
<html> |
|||
<head> |
|||
<title>登陆成功</title> |
|||
</head> |
|||
<body> |
|||
<h1>登陆成功</h1> |
|||
</body> |
|||
</html> |
|||
@ -0,0 +1,47 @@ |
|||
<!DOCTYPE web-app PUBLIC |
|||
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" |
|||
"http://java.sun.com/dtd/web-app_2_3.dtd" > |
|||
|
|||
<web-app> |
|||
<!-- 1. 过滤器(必须在 servlet 之前) --> |
|||
<context-param> |
|||
<param-name>contextConfigLocation</param-name> |
|||
<param-value>classpath:spring.xml</param-value> |
|||
</context-param> |
|||
<filter> |
|||
<filter-name>characterEncodingFilter</filter-name> |
|||
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> |
|||
<init-param> |
|||
<param-name>encoding</param-name> |
|||
<param-value>UTF-8</param-value> |
|||
</init-param> |
|||
</filter> |
|||
<!-- 2. 过滤器映射(紧跟在对应 filter 之后) --> |
|||
<filter-mapping> |
|||
<filter-name>characterEncodingFilter</filter-name> |
|||
<url-pattern>/*</url-pattern> |
|||
</filter-mapping> |
|||
|
|||
<listener> |
|||
<listener-class>org.springframework.web.context.ContextCleanupListener</listener-class> |
|||
</listener> |
|||
|
|||
<!-- 3. Servlet 定义(在 filter 之后) --> |
|||
<servlet> |
|||
<servlet-name>dispatcherServlet</servlet-name> |
|||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> |
|||
<!-- 加载 spring-mvc.xml 和spring.xml 配置文件 --> |
|||
<init-param> |
|||
<param-name>contextConfigLocation</param-name> |
|||
<param-value>classpath:spring-mvc.xml,classpath:spring.xml</param-value> |
|||
</init-param> |
|||
<!-- 启动服务器时创建该 servlet --> |
|||
<load-on-startup>1</load-on-startup> |
|||
</servlet> |
|||
<!-- 4. Servlet 映射(紧跟在对应 servlet 之后) --> |
|||
<servlet-mapping> |
|||
<servlet-name>dispatcherServlet</servlet-name> |
|||
<url-pattern>/</url-pattern> |
|||
</servlet-mapping> |
|||
|
|||
</web-app> |
|||
@ -0,0 +1,94 @@ |
|||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> |
|||
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %> |
|||
<html> |
|||
<head> |
|||
<title>主界面</title> |
|||
<link rel="stylesheet" href="static/css/styles.css"> |
|||
<style> |
|||
.my-class { |
|||
text-align: center; |
|||
} |
|||
/* 新增样式:登录表单容器 */ |
|||
.login-container { |
|||
position: relative; /* 相对定位,用于子元素绝对定位 */ |
|||
width: 300px; /* 固定宽度 */ |
|||
margin: 20px auto; /* 居中显示 */ |
|||
padding: 20px; |
|||
border: 1px solid #eee; /* 轻微边框 */ |
|||
} |
|||
/* 按钮容器样式 */ |
|||
.button-group { |
|||
display: flex; /* 弹性布局 */ |
|||
justify-content: space-between; /* 两端对齐 */ |
|||
margin-top: 15px; /* 与上方内容间距 */ |
|||
} |
|||
/* 基础按钮样式 */ |
|||
.base-btn { |
|||
padding: 6px 12px; |
|||
border: 1px solid #ccc; |
|||
background-color: #f5f5f5; |
|||
cursor: pointer; /* 鼠标悬停显示手型 */ |
|||
text-decoration: none; /* 去除链接下划线 */ |
|||
color: #333; /* 文字颜色 */ |
|||
font-size: 14px; |
|||
} |
|||
.base-btn:hover { |
|||
background-color: #e0e0e0; /* 悬停效果 */ |
|||
} |
|||
</style> |
|||
</head> |
|||
<body> |
|||
<a href="users/findUsers">测试查询</a> |
|||
<hr> |
|||
|
|||
<!-- 登录区域 --> |
|||
<div class="login-container"> |
|||
<div class="my-class"> |
|||
<h3>用户登录</h3> |
|||
<form method="post" action="<c:url value="/users/login"/>"> |
|||
用户:<input type="text" name="username"><br><br> |
|||
密码:<input type="password" name="password"><br><br> |
|||
|
|||
<div class="input-icon"> |
|||
<input class="form-control" style="width:180px;" type="text" id="verifyCode" name="verifyCode" placeholder="验证码" maxlength="4"> |
|||
<img style="position:absolute;right: 40px;top: 168px;" src="<c:url value="/users/getVerifyCode"/>" width="110" height=24" id="verifyCodeImage" onclick="changeImage();"> |
|||
</div> |
|||
<br> |
|||
|
|||
<div class="button-group"> |
|||
<a href="#" class="base-btn" onclick="document.getElementById('registerForm').submit()">注册</a> |
|||
<input type="submit" value="登录" class="base-btn"> |
|||
</div> |
|||
<br> |
|||
|
|||
|
|||
</form> |
|||
</div> |
|||
</div> |
|||
|
|||
<!-- 注册表单(保持原有逻辑,隐藏显示) --> |
|||
<div style="display:none;"> |
|||
<form id="registerForm" method="post" action="<c:url value="/users/insert"/>"> |
|||
<!-- 注册表单字段会自动获取页面中输入的用户名和密码 --> |
|||
<input type="hidden" name="username" id="regUsername"> |
|||
<input type="hidden" name="password" id="regPassword"> |
|||
</form> |
|||
</div> |
|||
|
|||
<script> |
|||
// 验证码刷新逻辑 |
|||
function changeImage() { |
|||
const img = document.getElementById("verifyCodeImage"); |
|||
const newSrc = "${pageContext.request.contextPath}/users/getVerifyCode?t=" + new Date().getTime(); |
|||
img.src = newSrc; |
|||
} |
|||
|
|||
// 同步注册表单与登录表单的输入值(点击注册时使用当前输入的用户名密码) |
|||
document.querySelector('input[name="username"]').addEventListener('input', function() { |
|||
document.getElementById('regUsername').value = this.value; |
|||
}); |
|||
</script> |
|||
|
|||
<hr> |
|||
</body> |
|||
</html> |
|||
@ -0,0 +1,7 @@ |
|||
a { |
|||
color: #f80d43; |
|||
} |
|||
|
|||
.center-text { |
|||
text-align: center; |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue