登录功能的实现

master
Allen 6 years ago
parent 941c7feb89
commit 28c43358ab

@ -6,13 +6,47 @@ Page({
'userid': e.detail.value.userid,
'userpassword': e.detail.value.userpassword,
},
header: {
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
methods: {
method: "POST",
}
})
},
success: function (res) {
console.log(res.data);
if (res.data == "111") {
wx.showModal({
title: '登录消息',
content: '密码正确',
confirmColor: "rgba(253, 153, 65, 1)",
success: function (res) {
if (res.confirm) {
wx.switchTab({
url: '../shouye/shouye',
})
}
}
})
}
else if (res.data == "100") {
wx.showModal({
title: '登录消息',
content: '密码错误',
confirmColor: "rgba(253, 153, 65, 1)"
})
}
else if (res.data == "001") {
wx.showModal({
title: '登录消息',
content: '用户名不存在',
confirmColor: "rgba(253, 153, 65, 1)"
})
}
},
fail: function (res) {
console.log("失败");
}
})
}
})

@ -1,9 +1,15 @@
<!--denglu/denglu.wxml-->
<view class="container">
<view class="flex-row" style="display: flex;"><text class="text1" data-c_e_id="wx_text_ed857dc8">学号</text><input class="inputnumber" data-c_e_id="wx_input_40f209dc" maxlength="15" name="input1" placeholder="请输入您的学号" type="number"/></view>
<view class="flex-row" style="display: flex;"><text class="password" data-c_e_id="1">密码</text></view>
<view class="flex-row" style="display: flex;"><input class="inputpassword" data-c_e_id="wx_input_dfbcd57f" password="true" name="input1" placeholder="默认身份证号后六位" type="number"/>
</view>
<button class="button1" bindtap="logBtn"form-type="submt">
登 录</button>
</view>
<form bindsubmit="formSubmit" >
<view class="flex-row" style="display: flex;">
<text class="text1" >学号</text>
<input class="inputnumber" maxlength="15" name="userid" placeholder=" 请输入您的学号" type="number" value="{{idTxt}}"/>
</view>
<view class="flex-row" style="display: flex;">
<text class="password" >密码</text></view>
<view class="flex-row" style="display: flex;">
<input class="inputpassword" password="true" name="userpassword" placeholder=" 默认身份证号后六位" type="number"value="{{passwordTxt}}"/>
</view>
<button class="button1" formType="submit" >
登 录</button>
</form>

@ -1,6 +1,5 @@
// 首页/shouye.js
const app = getApp()
Page({
data: {
motto: 'Hello',
@ -9,7 +8,7 @@ Page({
canIUse: wx.canIUse('button.open-type.getUserInfo')
},
//事件处理函数
bindViewTap: function() {
bindViewTap: function () {
wx.navigateTo({
url: '../logs/logs'
})
@ -20,7 +19,7 @@ Page({
userInfo: app.globalData.userInfo,
hasUserInfo: true
})
} else if (this.data.canIUse){
} else if (this.data.canIUse) {
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userInfoReadyCallback = res => {
@ -42,12 +41,26 @@ Page({
})
}
},
getUserInfo: function(e) {
getUserInfo: function (e) {
console.log(e)
app.globalData.userInfo = e.detail.userInfo
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
},
denglusubmit: function (e) {
wx.showModal({
title: '退出登录',
content: '是否退出登录',
confirmColor: "rgba(253, 153, 65, 1)",
success: function (res) {
if (res.confirm) {
wx.navigateTo({
url: '../denglu/denglu',
})
}
}
})
}
})
})

@ -13,7 +13,8 @@
<button class='button1'><view>个人信息</view></button>
<button class='button2'><view>借阅记录</view></button>
<button class='button3'><view>退出登录</view></button>
<button class='button3'bindtap="denglusubmit"><view>退出登录</view></button>
</page>

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>zxlogin</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/webapp"/>
<classpathentry kind="src" path="target/m2e-wtp/web-resources"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>

@ -0,0 +1,3 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF8
encoding/<project>=UTF-8

@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="zxlogin">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="context-root" value="zxlogin"/>
<property name="java-output-path" value="/zxlogin/target/classes"/>
</wb-module>
</project-modules>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.5"/>
<installed facet="jst.web" version="2.3"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>

@ -0,0 +1,2 @@
disabled=06target
eclipse.preferences.version=1

@ -0,0 +1,154 @@
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>zxtsgl</groupId>
<artifactId>zxlogin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>zxlogin Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<!-- Generic properties -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- Spring -->
<spring.version>4.3.10.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- mysql数据库驱动类 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
<!-- 导入MyBatis生成器 -->
<!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-core -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>
<!-- Spring -->
<!-- 1)包含Spring 框架基本的核心工具类。Spring 其它组件要都要使用到这个包里的类, 是其它组件的基本核心 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- 2)这个jar 文件是所有应用都要用到的它包含访问配置文件、创建和管理bean 以及进行Inversion of Control
/ Dependency InjectionIoC/DI操作相关的所有类。如果应用只需基本的IoC/DI 支持引入spring-core.jar
及spring-beans.jar 文件就可以了。 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- 3)这个jar 文件为Spring 核心提供了大量扩展。可以找到使用Spring ApplicationContext特性时所需的全部类JDNI
所需的全部类instrumentation组件以及校验Validation 方面的相关类。 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- 4) 这个jar 文件包含对Spring 对JDBC 数据访问进行封装的所有类。 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- 5) 为JDBC、Hibernate、JDO、JPA等提供的一致的声明式和编程式事务管理。 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- 6)Spring web 包含Web应用开发时用到Spring框架时所需的核心类包括自动载入WebApplicationContext特性的类、Struts与JSF集成类、文件上传的支持类、Filter类和大量工具辅助类。 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- 7)包含SpringMVC框架相关的所有类。 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- 8)Spring test 对JUNIT等测试框架的简单封装 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<!-- DAO: MyBatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<!-- 连接技术 -->
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<!-- Servlet web -->
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 配置JDK插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF8</encoding>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
<configuration>
<!--配置文件的路径 -->
<configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugins>
<finalName>zxlogin</finalName>
</build>
</project>

@ -0,0 +1,56 @@
package controller;
import java.io.IOException;
import java.io.Writer;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import service.LoginService;
import domain.UserPO;
@Controller
public class LoginController {
@Autowired@Qualifier("LoginServiceImpl")
private LoginService loginService;
@RequestMapping("/login")
public void login(int userid, int userpassword,
HttpServletRequest request, HttpServletResponse response) throws IOException {
UserPO userPO=this.loginService.FindByUserid(userid);
response.setContentType("text/html;charset=utf-8");
/* 设置响应头允许ajax跨域访问 */
response.setHeader("Access-Control-Allow-Origin", "*");
/* 星号表示所有的异域请求都可以接受, */
response.setHeader("Access-Control-Allow-Methods", "GET,POST");
System.out.println(userid);
if(userPO!=null)
if(userpassword==userPO.getUserpassword())
{
System.out.println("密码正确");
Writer out = response.getWriter();
out.write("111");
out.flush();
}
else{
System.out.println("密码错误");
Writer out = response.getWriter();
out.write("100");
out.flush();
}
else{
System.out.println("不存在用户名");
Writer out = response.getWriter();
out.write("001");
out.flush();
}
}
}

@ -0,0 +1,29 @@
package domain;
import java.io.Serializable;
public class UserPO implements Serializable{
private int userid;
private int userpassword;
private String username;
public int getUserid() {
return userid;
}
public void setUserid(int userid) {
this.userid = userid;
}
public int getUserpassword() {
return userpassword;
}
public void setUserpassword(int userpassword) {
this.userpassword = userpassword;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}

@ -0,0 +1,12 @@
package mapperDAO;
import org.springframework.stereotype.Repository;
import domain.UserPO;
@Repository("UserDAO")
public interface UserDAO {
public UserPO FindByUserid(int userid);
}

@ -0,0 +1,8 @@
package service;
import domain.UserPO;
public interface LoginService{
public UserPO FindByUserid(int userid);
}

@ -0,0 +1,22 @@
package serviceimpl;
import mapperDAO.UserDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import domain.UserPO;
import service.LoginService;
@Component("LoginServiceImpl")
public class LoginServiceImpl implements LoginService{
@Autowired@Qualifier("UserDAO")
private UserDAO userDAO;
public UserPO FindByUserid(int userid){
return this.userDAO.FindByUserid(userid);
}
}

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
<generatorConfiguration>
<!-- JDBC数据库驱动jar文件 -->
<classPathEntry location="D:\maven\repository\mysql\mysql-connector-java\5.1.46\mysql-connector-java-5.1.46.jar" />
<context id="context1" defaultModelType="flat">
<!-- PO序列化 -->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin">
</plugin>
<commentGenerator>
<!-- 是否去除自动生成的注释 true false:否 -->
<property name="suppressAllComments" value="false" />
</commentGenerator>
<!-- 配置一个连接 -->
<jdbcConnection
driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/zx"
userId="root"
password="zjh19990323">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!--生成实体类存放位置 -->
<javaModelGenerator targetPackage="domain"
targetProject="src/main/java">
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!--生成映射文件存放位置 -->
<sqlMapGenerator targetPackage="mapper"
targetProject="src/main/resources">
<property name="trimStrings" value="true" />
</sqlMapGenerator>
<!--生成Mapper接口存放位置 -->
<javaClientGenerator targetPackage="mapperDAO"
targetProject="src/main/java" type="XMLMAPPER" />
<table schema="zx" tableName="student" enableCountByExample="false"
enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false">
</table>
</context>
</generatorConfiguration>

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="mapperDAO.UserDAO">
<resultMap id="UserMap" type="domain.UserPO">
<id column="s_id" jdbcType="INTEGER" property="userid" />
<result column="s_name" jdbcType="VARCHAR" property="username" />
<result column="s_password" jdbcType="INTEGER" property="userpassword" />
</resultMap>
<select id="FindByUserid" resultMap="UserMap" parameterType="int">
SELECT
student.s_id,
student.s_name,
student.s_password
FROM student WHERE
student.s_id=#{userid}
</select>
</mapper>

@ -0,0 +1,5 @@
<?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>
</configuration>

@ -0,0 +1,11 @@
<?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"
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-4.3.xsd">
<!-- 打开Spring的注解 -->
<context:annotation-config />
<context:component-scan base-package="mapperDAO,controller,serviceimpl"/>
</beans>

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
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">
<!-- 打开SpringMVC的注解 -->
<annotation-driven />
<!-- 配置静态资源的目录 -->
<resources mapping="/resources/**" location="/resources/" />
<!-- 配置视图处理器 -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 视图前缀 -->
<beans:property name="prefix" value="/WEB-INF/view/" />
<!-- 视图后缀 -->
<beans:property name="suffix" value=".jsp" />
</beans:bean>
</beans:beans>

@ -0,0 +1,38 @@
<?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: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-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
<!-- 整合MyBatis 开始 -->
<!--创建jdbc数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="username" value="root" />
<property name="password" value="zjh19990323" />
<property name="url"
value="jdbc:mysql://127.0.0.1:3306/zx?useUnicode=true&amp;characterEncoding=utf8" />
</bean>
<!-- 配置MyBatis的sqlSession -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:mybatis.xml" />
<property name="mapperLocations" value="classpath:mapper/*.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 映射Mapper目录 -->
<!-- Mapper接口所在包名Spring会自动查找其下的Mapper -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="mapperDAO" />
</bean>
<!-- 可通过注解控制事务 -->
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 整合MyBatis 结束 -->
</beans>

@ -0,0 +1,20 @@
<!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>
<display-name>Archetype Created Web Application</display-name>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-*.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
<generatorConfiguration>
<!-- JDBC数据库驱动jar文件 -->
<classPathEntry location="D:\maven\repository\mysql\mysql-connector-java\5.1.46\mysql-connector-java-5.1.46.jar" />
<context id="context1" defaultModelType="flat">
<!-- PO序列化 -->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin">
</plugin>
<commentGenerator>
<!-- 是否去除自动生成的注释 true false:否 -->
<property name="suppressAllComments" value="false" />
</commentGenerator>
<!-- 配置一个连接 -->
<jdbcConnection
driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/zx"
userId="root"
password="zjh19990323">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!--生成实体类存放位置 -->
<javaModelGenerator targetPackage="domain"
targetProject="src/main/java">
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!--生成映射文件存放位置 -->
<sqlMapGenerator targetPackage="mapper"
targetProject="src/main/resources">
<property name="trimStrings" value="true" />
</sqlMapGenerator>
<!--生成Mapper接口存放位置 -->
<javaClientGenerator targetPackage="mapperDAO"
targetProject="src/main/java" type="XMLMAPPER" />
<table schema="zx" tableName="student" enableCountByExample="false"
enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false">
</table>
</context>
</generatorConfiguration>

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="mapperDAO.UserDAO">
<resultMap id="UserMap" type="domain.UserPO">
<id column="s_id" jdbcType="INTEGER" property="userid" />
<result column="s_name" jdbcType="VARCHAR" property="username" />
<result column="s_password" jdbcType="INTEGER" property="userpassword" />
</resultMap>
<select id="FindByUserid" resultMap="UserMap" parameterType="int">
SELECT
student.s_id,
student.s_name,
student.s_password
FROM student WHERE
student.s_id=#{userid}
</select>
</mapper>

@ -0,0 +1,5 @@
<?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>
</configuration>

@ -0,0 +1,11 @@
<?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"
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-4.3.xsd">
<!-- 打开Spring的注解 -->
<context:annotation-config />
<context:component-scan base-package="mapperDAO,controller,serviceimpl"/>
</beans>

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
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">
<!-- 打开SpringMVC的注解 -->
<annotation-driven />
<!-- 配置静态资源的目录 -->
<resources mapping="/resources/**" location="/resources/" />
<!-- 配置视图处理器 -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 视图前缀 -->
<beans:property name="prefix" value="/WEB-INF/view/" />
<!-- 视图后缀 -->
<beans:property name="suffix" value=".jsp" />
</beans:bean>
</beans:beans>

@ -0,0 +1,38 @@
<?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: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-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
<!-- 整合MyBatis 开始 -->
<!--创建jdbc数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="username" value="root" />
<property name="password" value="zjh19990323" />
<property name="url"
value="jdbc:mysql://127.0.0.1:3306/zx?useUnicode=true&amp;characterEncoding=utf8" />
</bean>
<!-- 配置MyBatis的sqlSession -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:mybatis.xml" />
<property name="mapperLocations" value="classpath:mapper/*.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 映射Mapper目录 -->
<!-- Mapper接口所在包名Spring会自动查找其下的Mapper -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="mapperDAO" />
</bean>
<!-- 可通过注解控制事务 -->
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 整合MyBatis 结束 -->
</beans>

@ -0,0 +1,5 @@
Manifest-Version: 1.0
Built-By: zhujiehuang
Build-Jdk: 1.8.0_152
Created-By: Maven Integration for Eclipse

@ -0,0 +1,7 @@
#Generated by Maven Integration for Eclipse
#Thu Jan 10 00:26:11 CST 2019
version=0.0.1-SNAPSHOT
groupId=zxtsglxt
m2e.projectName=zxlogin
m2e.projectLocation=D\:\\sts worksapce\\zxlogin
artifactId=zxlogin

@ -0,0 +1,21 @@
<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>zxtsglxt</groupId>
<artifactId>zxlogin</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>zxlogin Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>zxlogin</finalName>
</build>
</project>
Loading…
Cancel
Save