diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 505bdbd..e187800 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -11,6 +11,7 @@
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
index b26911b..be2f94a 100644
--- a/.idea/encodings.xml
+++ b/.idea/encodings.xml
@@ -2,5 +2,6 @@
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index dc8eb08..b3fa79e 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,20 +2,49 @@
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -25,184 +54,168 @@
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
+
+
+
+
-
-
+
+
-
+
-
+
+
+
-
-
+
+
-
-
+
+
+
+
-
+
+
-
-
-
+
+
+
+
-
-
-
+
+
+
-
+
-
+
+
-
-
-
-
+
+
+
+
-
+
-
-
-
-
-
+
+
+
+
+
-
+
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -226,6 +239,11 @@
/path
UserContext
user
+ update
+ my
+ Base_Column_List
+ sw
+ getMiaoShaUserById
@@ -234,32 +252,6 @@
@@ -308,8 +326,8 @@
-
-
+
+
@@ -331,6 +349,9 @@
+
+
+
@@ -364,6 +385,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -377,7 +416,16 @@
-
+
+
+
+
+
+
+
+
+
+
@@ -387,9 +435,6 @@
-
-
-
@@ -401,30 +446,33 @@
-
-
+
+
-
+
+
-
+
+
+
@@ -440,7 +488,7 @@
-
+
@@ -493,6 +541,13 @@
+
+
+
+
+
+
+
@@ -507,6 +562,7 @@
+
@@ -515,9 +571,9 @@
+
-
@@ -551,11 +607,21 @@
+
+
+
+
+
+
+
+
+
+
-
+
@@ -570,7 +636,7 @@
-
+
@@ -579,16 +645,50 @@
-
-
-
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -598,43 +698,9 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
@@ -653,60 +719,66 @@
-
+
file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/service/OrderService.java
34
-
+
file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/controller/MiaoshaController.java
104
-
+
file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/rabbitmq/MQReceiver.java
35
-
+
file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/controller/MiaoshaController.java
118
-
+
file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/service/OrderService.java
50
-
+
file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/service/MiaoshaService.java
34
-
+
file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/service/MiaoshaService.java
46
-
+
file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/access/AccessInterceptor.java
31
-
+
file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/service/MiaoShaUserService.java
- 81
+ 94
+
+ file://$PROJECT_DIR$/src/main/java/com/geekq/miaosha/controller/LoginController.java
+ 65
+
+
+
@@ -738,311 +810,17 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
@@ -1053,47 +831,312 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/README.md b/README.md
index 346f8c0..25f2d45 100644
--- a/README.md
+++ b/README.md
@@ -121,4 +121,8 @@ redis的数量不是库存,他的作用仅仅只是为了阻挡多余的请求
块时产生的同步访问,那么,让每个线程拥有它自己的对象实例
注意:局部变量是同步或局部线程的一个好的替代,它总是能够保证线程安全。唯一可能限制你这样做的是你的应用设计约束
- 所以设计threadlocal存储user不会对对象产生影响,每次进来一个请求都会产生自身的线程变量来存储
\ No newline at end of file
+ 所以设计threadlocal存储user不会对对象产生影响,每次进来一个请求都会产生自身的线程变量来存储
+
+ ### 15.mybatis如何使用注解与xml配置?
+本文使用的是注解方法开发所以不做过多解释
+下面仔细讲解以下如何详细使用xml开发
\ No newline at end of file
diff --git a/gitignore b/gitignore
new file mode 100644
index 0000000..e69de29
diff --git a/pom.xml b/pom.xml
index cae2ac4..f864f10 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,111 +1,119 @@
- 4.0.0
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
- com.geekq
- miaosha
- 0.0.1-SNAPSHOT
- jar
-
- org.springframework.boot
- spring-boot-starter-parent
- 1.5.8.RELEASE
-
+ com.geekq
+ miaosha
+ 0.0.1-SNAPSHOT
+ jar
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 1.5.8.RELEASE
+
- miaosha
- http://maven.apache.org
-
- UTF-8
-
+ miaosha
+ http://maven.apache.org
+
+ UTF-8
+
-
+
-
- org.springframework.boot
- spring-boot-starter-web
-
-
- com.google.guava
- guava
- 18.0
-
-
- org.springframework.boot
- spring-boot-starter-thymeleaf
-
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ com.google.guava
+ guava
+ 18.0
+
+
+ org.springframework.boot
+ spring-boot-starter-thymeleaf
+
-
- org.mybatis.spring.boot
- mybatis-spring-boot-starter
- 1.3.1
-
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+ 1.3.1
+
-
- mysql
- mysql-connector-java
-
+
+ mysql
+ mysql-connector-java
+
-
- com.alibaba
- druid
- 1.0.5
-
+
+ com.alibaba
+ druid
+ 1.0.5
+
-
- redis.clients
- jedis
-
+
+ redis.clients
+ jedis
+
-
- com.alibaba
- fastjson
- 1.2.38
-
+
+ com.alibaba
+ fastjson
+ 1.2.38
+
-
- commons-codec
- commons-codec
-
-
- org.apache.commons
- commons-lang3
- 3.6
-
+
+ commons-codec
+ commons-codec
+
+
+ org.apache.commons
+ commons-lang3
+ 3.6
+
-
- commons-codec
- commons-codec
-
-
- org.apache.commons
- commons-lang3
- 3.6
-
+
+ commons-codec
+ commons-codec
+
+
+ org.apache.commons
+ commons-lang3
+ 3.6
+
-
- org.springframework.boot
- spring-boot-starter-validation
-
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
-
- org.springframework.boot
- spring-boot-starter-amqp
-
+
+ org.springframework.boot
+ spring-boot-starter-amqp
+
-
- org.springframework.boot
- spring-boot-starter-amqp
-
+
+ org.springframework.boot
+ spring-boot-starter-amqp
+
+
-
+
+ ${project.artifactId}
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+ src/main/java
+
+ **/*.xml
+
+
+
+
-
- ${project.artifactId}
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
diff --git a/src/main/java/com/geekq/miaosha/Test.java b/src/main/java/com/geekq/miaosha/Test.java
index 8e26828..ef8005a 100644
--- a/src/main/java/com/geekq/miaosha/Test.java
+++ b/src/main/java/com/geekq/miaosha/Test.java
@@ -1,15 +1,30 @@
package com.geekq.miaosha;
+import com.geekq.miaosha.domain.MiaoshaUser;
+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 java.io.IOException;
+import java.io.Reader;
+
+/**
+ * mybatis xml 写法的配置测试类
+ */
public class Test {
- public static void main(String[] args) {
- DemoTask demoTask = new DemoTask();
- DemoTask demoTask1 = new DemoTask();
- DemoTask demoTask2 = new DemoTask();
- Thread t = new Thread(demoTask);
- t.start();
- new Thread(demoTask).start();
- new Thread(demoTask2).start();
+ public static void main(String[] args) throws IOException {
+
+ //读取配置文件
+ Reader reader = Resources.getResourceAsReader("config.xml");
+ SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader);
+ SqlSession session = sessionFactory.openSession();
+
+ String statement = "com.geekq.miaosha.dao.UserMapper.getMiaoShaUserById" ;
+ MiaoshaUser user = session.selectOne(statement,"18612766134");
+
+ System.out.println(user.toString());
}
}
diff --git a/src/main/java/com/geekq/miaosha/common/ResponseCode.java b/src/main/java/com/geekq/miaosha/common/ResponseCode.java
new file mode 100644
index 0000000..0e75e16
--- /dev/null
+++ b/src/main/java/com/geekq/miaosha/common/ResponseCode.java
@@ -0,0 +1,27 @@
+package com.geekq.miaosha.common;
+
+/**
+ * 响应类
+ */
+public enum ResponseCode {
+ SUCCESS(0, "SUCCESS"),
+ ERROR(1, "ERROR"),
+ NEED_LOGIN(10, "NEED_LOGIN"),
+ ILLEGAL_ARGUMENT(2, "ILLEGAL_ARGUMENT");
+
+ private final int code;
+ private final String desc;
+
+ private ResponseCode(int code, String desc) {
+ this.code = code;
+ this.desc = desc;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public String getDesc() {
+ return desc;
+ }
+}
diff --git a/src/main/java/com/geekq/miaosha/common/ServerResponse.java b/src/main/java/com/geekq/miaosha/common/ServerResponse.java
new file mode 100644
index 0000000..69f8b79
--- /dev/null
+++ b/src/main/java/com/geekq/miaosha/common/ServerResponse.java
@@ -0,0 +1,78 @@
+package com.geekq.miaosha.common;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
+import java.io.Serializable;
+
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+//保证序列化的时候 不会有空
+public class ServerResponse implements Serializable {
+
+ private int status ;
+ private String msg ;
+ private T data ;
+ private ServerResponse( int status ){
+ this.status =status;
+ }
+ private ServerResponse( int status ,T data){
+ this.status =status;
+ this.data = data;
+ }
+ private ServerResponse( int status ,String msg ,T data){
+ this.status =status;
+ this.msg = msg ;
+ this.data = data;
+ }
+
+ private ServerResponse( int status ,String msg ){
+ this.status =status;
+ this.msg = msg ;
+ }
+
+ @JsonIgnore
+ public boolean isSuccess(){
+ return this.status == ResponseCode.SUCCESS.getCode();
+ }
+
+ public int getStatus() {
+ return status;
+ }
+
+ public String getMsg() {
+ return msg;
+ }
+
+ public T getData() {
+ return data;
+ }
+
+ public static ServerResponse createBySuccess(){
+ return new ServerResponse(ResponseCode.SUCCESS.getCode());
+ }
+
+ public static ServerResponse createBySuccessMessage(String msg){
+ return new ServerResponse(ResponseCode.SUCCESS.getCode(),msg);
+ }
+
+ public static ServerResponse createBySuccess(T data){
+ return new ServerResponse(ResponseCode.SUCCESS.getCode(),data);
+ }
+
+ public static ServerResponse createBySuccess(String msg,T data){
+ return new ServerResponse(ResponseCode.SUCCESS.getCode(),msg,data);
+ }
+
+ public static ServerResponse createByError(){
+ return new ServerResponse(ResponseCode.ERROR.getCode(),ResponseCode.ERROR.getDesc());
+ }
+
+ public static ServerResponse createByErrorMessage(String errorMsg){
+ return new ServerResponse(ResponseCode.ERROR.getCode(),errorMsg);
+ }
+ public static ServerResponse createByErrorCodeMessage(int errorCode , String errorMsg){
+ return new ServerResponse(errorCode,errorMsg);
+ }
+
+
+}
diff --git a/src/main/java/com/geekq/miaosha/controller/LoginController.java b/src/main/java/com/geekq/miaosha/controller/LoginController.java
index 9694724..aaddec8 100644
--- a/src/main/java/com/geekq/miaosha/controller/LoginController.java
+++ b/src/main/java/com/geekq/miaosha/controller/LoginController.java
@@ -1,14 +1,17 @@
package com.geekq.miaosha.controller;
-import com.geekq.miaosha.result.CodeMsg;
+import com.geekq.miaosha.dao.UserMapper;
+import com.geekq.miaosha.domain.MiaoshaUser;
import com.geekq.miaosha.result.Result;
import com.geekq.miaosha.service.MiaoShaUserService;
import com.geekq.miaosha.vo.LoginVo;
+import org.apache.ibatis.annotations.Mapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletResponse;
@@ -18,24 +21,54 @@ import javax.validation.Valid;
@RequestMapping("/login")
public class LoginController {
- private static Logger log = LoggerFactory.getLogger(LoginController.class) ;
+ private static Logger log = LoggerFactory.getLogger(LoginController.class);
@Autowired
- private MiaoShaUserService userService ;
+ private MiaoShaUserService userService;
+ @Autowired
+ private UserMapper userMapper;
+
@RequestMapping("/to_login")
- public String tologin(LoginVo loginVo ){
+ public String tologin(LoginVo loginVo) {
log.info(loginVo.toString());
- return "login" ;
+ return "login";
}
@RequestMapping("/do_login")
@ResponseBody
- public Result dologin(HttpServletResponse response , @Valid LoginVo loginVo ){
+ public Result dologin(HttpServletResponse response, @Valid LoginVo loginVo) {
log.info(loginVo.toString());
- userService.login(response , loginVo);
- return Result.success(true);
+ userService.login(response, loginVo);
+ return Result.success(true);
+ }
+
+
+ @RequestMapping(value = "/register", method = RequestMethod.POST)
+ public Result register(MiaoshaUser user) {
+ return userService.insertMiaoShaUser(user);
+ }
+
+ @RequestMapping("/mybatis")
+ public void mybatisXml() {
+ //
+ int count = userMapper.getMiaoShaUserNum();
+ System.out.println(count);
+ MiaoshaUser user = userMapper.getMiaoShaUserById(Long.valueOf("18612766134"));
+ System.out.println(user);
+//
+// MiaoshaUser miaoshaUser =new MiaoshaUser();
+// miaoshaUser.setId(Long.valueOf("1234569879"));
+// miaoshaUser.setNickname("test");
+// Long num = userMapper.insertMiaoShaUser(miaoshaUser);
+
+ MiaoshaUser upmiaoshaUser =new MiaoshaUser();
+ upmiaoshaUser.setId(Long.valueOf("1234569879"));
+ upmiaoshaUser.setNickname("test1");
+ userMapper.updateMiaoShaUser(upmiaoshaUser);
+
+ userMapper.deleteMiaoShaUser(Long.valueOf("1234569879"));
}
}
diff --git a/src/main/java/com/geekq/miaosha/controller/UserController.java b/src/main/java/com/geekq/miaosha/controller/UserController.java
new file mode 100644
index 0000000..8ed2be0
--- /dev/null
+++ b/src/main/java/com/geekq/miaosha/controller/UserController.java
@@ -0,0 +1,24 @@
+package com.geekq.miaosha.controller;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+import javax.servlet.http.HttpSession;
+
+@Controller
+@RequestMapping("/user/")
+public class UserController {
+ /**
+ * 用户登录
+ * @param username
+ * @param password
+ * @param session
+ * @return
+ */
+ @RequestMapping(value = "/login",method = RequestMethod.POST)
+ public Object login(String username , String password , HttpSession session){
+
+ return null;
+ }
+}
diff --git a/src/main/java/com/geekq/miaosha/dao/MiaoShaUserDao.java b/src/main/java/com/geekq/miaosha/dao/MiaoShaUserDao.java
index e24bf96..9805df8 100644
--- a/src/main/java/com/geekq/miaosha/dao/MiaoShaUserDao.java
+++ b/src/main/java/com/geekq/miaosha/dao/MiaoShaUserDao.java
@@ -1,10 +1,7 @@
package com.geekq.miaosha.dao;
import com.geekq.miaosha.domain.MiaoshaUser;
-import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.annotations.Select;
-import org.apache.ibatis.annotations.Update;
+import org.apache.ibatis.annotations.*;
@Mapper
public interface MiaoShaUserDao {
@@ -15,4 +12,9 @@ public interface MiaoShaUserDao {
@Update("update miaosha_user set password = #{password} where id = #{id}")
public void update(MiaoshaUser toBeUpdate);
-}
+
+
+ @Insert("insert into miaosha_user (id , nickname ,password , salt ,head,register_date,last_login_date)value (#{id},#{nickname},#{password},#{salt},#{nickname},#{head},#{register_date},#{last_login_date}) ")
+ public long insertMiaoShaUser(MiaoshaUser miaoshaUser);
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/geekq/miaosha/dao/MiaoshaUserDao.java b/src/main/java/com/geekq/miaosha/dao/MiaoshaUserDao.java
deleted file mode 100644
index 8344194..0000000
--- a/src/main/java/com/geekq/miaosha/dao/MiaoshaUserDao.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.geekq.miaosha.dao;
-
-import com.geekq.miaosha.domain.MiaoshaUser;
-import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.annotations.Select;
-
-@Mapper
-public interface MiaoshaUserDao {
-
- @Select("select * from miaosha_user where id = #{id}")
- public MiaoshaUser getById(@Param("id") long id);
-}
diff --git a/src/main/java/com/geekq/miaosha/dao/UserMapper.java b/src/main/java/com/geekq/miaosha/dao/UserMapper.java
new file mode 100644
index 0000000..b9e301e
--- /dev/null
+++ b/src/main/java/com/geekq/miaosha/dao/UserMapper.java
@@ -0,0 +1,30 @@
+package com.geekq.miaosha.dao;
+
+import com.geekq.miaosha.domain.MiaoshaUser;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+/**
+ * mybatis xml 写法
+ */
+@Mapper
+public interface UserMapper {
+ int countbyMenuId();
+ MiaoshaUser getMiaoShaUserById(Long phoneId);
+ //秒杀对象获取 mybatis的#与$的区别
+ List queryMiaoShaUserOrderByColumn(String column);
+
+
+ //查询总条数
+ public int getMiaoShaUserNum();
+
+ public Long insertMiaoShaUser(MiaoshaUser user);
+
+ //更改表数据
+ void updateMiaoShaUser(MiaoshaUser user) ;
+
+ //删除表数据
+
+ void deleteMiaoShaUser(long id );
+}
diff --git a/src/main/java/com/geekq/miaosha/domain/MiaoshaUser.java b/src/main/java/com/geekq/miaosha/domain/MiaoshaUser.java
index f3f71ce..121e695 100644
--- a/src/main/java/com/geekq/miaosha/domain/MiaoshaUser.java
+++ b/src/main/java/com/geekq/miaosha/domain/MiaoshaUser.java
@@ -59,4 +59,18 @@ public class MiaoshaUser {
public void setLoginCount(Integer loginCount) {
this.loginCount = loginCount;
}
+
+ @Override
+ public String toString() {
+ return "MiaoshaUser{" +
+ "id=" + id +
+ ", nickname='" + nickname + '\'' +
+ ", password='" + password + '\'' +
+ ", salt='" + salt + '\'' +
+ ", head='" + head + '\'' +
+ ", registerDate=" + registerDate +
+ ", lastLoginDate=" + lastLoginDate +
+ ", loginCount=" + loginCount +
+ '}';
+ }
}
diff --git a/src/main/java/com/geekq/miaosha/result/CodeMsg.java b/src/main/java/com/geekq/miaosha/result/CodeMsg.java
index fc5df35..933e2c5 100644
--- a/src/main/java/com/geekq/miaosha/result/CodeMsg.java
+++ b/src/main/java/com/geekq/miaosha/result/CodeMsg.java
@@ -7,6 +7,11 @@ public class CodeMsg {
//通用的错误码
public static CodeMsg SUCCESS = new CodeMsg(0, "success");
+
+ public static CodeMsg SUCCESS_RESIGETER = new CodeMsg(200,"注册成功!");
+
+ public static CodeMsg RESIGETER_FAIL = new CodeMsg(300,"注册失败!");
+
public static CodeMsg SERVER_ERROR = new CodeMsg(500100, "服务端异常");
public static CodeMsg BIND_ERROR = new CodeMsg(500101, "参数校验异常:%s");
public static CodeMsg REQUEST_ILLEGAL = new CodeMsg(500102, "请求非法");
diff --git a/src/main/java/com/geekq/miaosha/result/Result.java b/src/main/java/com/geekq/miaosha/result/Result.java
index 72f8706..dea7c11 100644
--- a/src/main/java/com/geekq/miaosha/result/Result.java
+++ b/src/main/java/com/geekq/miaosha/result/Result.java
@@ -1,45 +1,66 @@
package com.geekq.miaosha.result;
public class Result {
- private int code ;
- private String msg ;
- private T data ;
+ private int code;
+ private String msg;
+ private T data;
/**
* 成功时候的调用
+ *
* @param data
* @param
* @return
*/
- public static Result success( T data ){
- return new Result(data) ;
+ public static Result success(T data) {
+ return new Result(data);
+ }
+
+ /**
+ * 注册时候调用
+ *
+ * @param msg
+ * @param data
+ * @param
+ * @return
+ */
+ public static Result success(CodeMsg msg) {
+
+ return new Result(CodeMsg.SUCCESS_RESIGETER);
+
}
/**
* 失败的时候调用
+ *
* @param cm
* @param
* @return
*/
- public static Result error(CodeMsg cm){
- return new Result(cm) ;
+ public static Result error(CodeMsg cm) {
+ return new Result(cm);
}
+// public Result(CodeMsg msg, T data) {
+// this.code = msg.getCode();
+// this.msg = msg.getMsg();
+// this.data = data;
+// }
- private Result(CodeMsg cm) {
- if(cm ==null){
- return ;
+ private Result(CodeMsg cm) {
+ if (cm == null) {
+ return;
}
- this.code = cm.getCode() ;
- this.msg = cm.getMsg() ;
+ this.code = cm.getCode();
+ this.msg = cm.getMsg();
}
- private Result(T data) {
- this.code = 0 ;
- this.msg = "success" ;
- this.data = data ;
+ private Result(T data) {
+ this.code = 0;
+ this.msg = "success";
+ this.data = data;
}
public int getCode() {
diff --git a/src/main/java/com/geekq/miaosha/service/IUserService.java b/src/main/java/com/geekq/miaosha/service/IUserService.java
new file mode 100644
index 0000000..fceac58
--- /dev/null
+++ b/src/main/java/com/geekq/miaosha/service/IUserService.java
@@ -0,0 +1,7 @@
+package com.geekq.miaosha.service;
+
+public interface IUserService {
+
+ Object login(String username , String password) ;
+
+}
diff --git a/src/main/java/com/geekq/miaosha/service/MiaoShaUserService.java b/src/main/java/com/geekq/miaosha/service/MiaoShaUserService.java
index 9c3cb80..c29d3fd 100644
--- a/src/main/java/com/geekq/miaosha/service/MiaoShaUserService.java
+++ b/src/main/java/com/geekq/miaosha/service/MiaoShaUserService.java
@@ -7,8 +7,10 @@ import com.geekq.miaosha.exception.GlobleException;
import com.geekq.miaosha.redis.MiaoShaUserKey;
import com.geekq.miaosha.redis.RedisService;
import com.geekq.miaosha.result.CodeMsg;
+import com.geekq.miaosha.result.Result;
import com.geekq.miaosha.utils.UUIDUtil;
import com.geekq.miaosha.vo.LoginVo;
+import com.sun.org.apache.bcel.internal.classfile.Code;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -74,6 +76,17 @@ public class MiaoShaUserService {
return true;
}
+ public Result insertMiaoShaUser(MiaoshaUser miaoshaUser){
+
+ long resultRegister = miaoShaUserDao.insertMiaoShaUser(miaoshaUser);
+
+ if(resultRegister == 0){
+ throw new GlobleException(CodeMsg.RESIGETER_FAIL);
+ }
+
+ return Result.success(CodeMsg.SUCCESS_RESIGETER);
+ }
+
public boolean login(HttpServletResponse response , LoginVo loginVo) {
if(loginVo ==null){
throw new GlobleException(CodeMsg.SERVER_ERROR);
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index f13a5f6..927242c 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -8,10 +8,13 @@ spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML5
#mybatis
-mybatis.type-aliases-package=com.imooc.miaosha.domain
+mybatis.type-aliases-package=com.geekq.miaosha.domain
#开启驼峰转换
mybatis.configuration.map-underscore-to-camel-case=true
-mybatis.mapperLocations = classpath:com/imooc/miaosha/dao/*.xml
+#mybatis.mapperLocations = classpath:com/geekq/miaosha/dao/*.xml
+mybatis.mapperLocations=classpath:mybatis/mapper/*.xml
+#add mybatis
+mybatis.config-locations=classpath:mybatis/config.xml
#datasource
spring.datasource.url=jdbc:mysql://localhost:3306/miaosha?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
spring.datasource.username=root
diff --git a/src/main/resources/mybatis/config.xml b/src/main/resources/mybatis/config.xml
new file mode 100644
index 0000000..fe0f5e4
--- /dev/null
+++ b/src/main/resources/mybatis/config.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/mybatis/mapper/UserMapper.xml b/src/main/resources/mybatis/mapper/UserMapper.xml
new file mode 100644
index 0000000..18da536
--- /dev/null
+++ b/src/main/resources/mybatis/mapper/UserMapper.xml
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ insert into miaosha_user (id, nickname, salt, register_date,last_login_date,login_Count ) values
+ (#{id,jdbcType=BIGINT},#{nickname,jdbcType=VARCHAR},
+ #{salt,jdbcType=VARCHAR},#{registerDate,jdbcType=DATE},#{lastLoginDate,jdbcType=DATE},
+ #{loginCount,jdbcType=INTEGER}
+ )
+
+
+
+
+
+ update miaosha_user set nickname = #{nickname},
+ login_Count = #{loginCount}
+ where id=#{id}
+
+
+
+
+ delete from miaosha_user
+ where id = #{id,jdbcType=BIGINT}
+
+
+
+ id, nickname, salt, register_date,last_login_date,login_Count
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html
index f04c028..fb816af 100644
--- a/src/main/resources/templates/login.html
+++ b/src/main/resources/templates/login.html
@@ -48,10 +48,10 @@
diff --git a/target/classes/application.properties b/target/classes/application.properties
index f13a5f6..927242c 100644
--- a/target/classes/application.properties
+++ b/target/classes/application.properties
@@ -8,10 +8,13 @@ spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML5
#mybatis
-mybatis.type-aliases-package=com.imooc.miaosha.domain
+mybatis.type-aliases-package=com.geekq.miaosha.domain
#开启驼峰转换
mybatis.configuration.map-underscore-to-camel-case=true
-mybatis.mapperLocations = classpath:com/imooc/miaosha/dao/*.xml
+#mybatis.mapperLocations = classpath:com/geekq/miaosha/dao/*.xml
+mybatis.mapperLocations=classpath:mybatis/mapper/*.xml
+#add mybatis
+mybatis.config-locations=classpath:mybatis/config.xml
#datasource
spring.datasource.url=jdbc:mysql://localhost:3306/miaosha?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
spring.datasource.username=root
diff --git a/target/classes/com/geekq/miaosha/Test.class b/target/classes/com/geekq/miaosha/Test.class
index 44178aa..463f8b9 100644
Binary files a/target/classes/com/geekq/miaosha/Test.class and b/target/classes/com/geekq/miaosha/Test.class differ
diff --git a/target/classes/com/geekq/miaosha/common/ResponseCode.class b/target/classes/com/geekq/miaosha/common/ResponseCode.class
new file mode 100644
index 0000000..303ef69
Binary files /dev/null and b/target/classes/com/geekq/miaosha/common/ResponseCode.class differ
diff --git a/target/classes/com/geekq/miaosha/common/ServerResponse.class b/target/classes/com/geekq/miaosha/common/ServerResponse.class
new file mode 100644
index 0000000..2aad957
Binary files /dev/null and b/target/classes/com/geekq/miaosha/common/ServerResponse.class differ
diff --git a/target/classes/com/geekq/miaosha/controller/LoginController.class b/target/classes/com/geekq/miaosha/controller/LoginController.class
index f700d72..868a238 100644
Binary files a/target/classes/com/geekq/miaosha/controller/LoginController.class and b/target/classes/com/geekq/miaosha/controller/LoginController.class differ
diff --git a/target/classes/com/geekq/miaosha/controller/UserController.class b/target/classes/com/geekq/miaosha/controller/UserController.class
new file mode 100644
index 0000000..8b0c055
Binary files /dev/null and b/target/classes/com/geekq/miaosha/controller/UserController.class differ
diff --git a/target/classes/com/geekq/miaosha/dao/MiaoShaUserDao.class b/target/classes/com/geekq/miaosha/dao/MiaoShaUserDao.class
index cee5635..54b9bc3 100644
Binary files a/target/classes/com/geekq/miaosha/dao/MiaoShaUserDao.class and b/target/classes/com/geekq/miaosha/dao/MiaoShaUserDao.class differ
diff --git a/target/classes/com/geekq/miaosha/dao/MiaoshaUserDao.class b/target/classes/com/geekq/miaosha/dao/MiaoshaUserDao.class
deleted file mode 100644
index 09d712a..0000000
Binary files a/target/classes/com/geekq/miaosha/dao/MiaoshaUserDao.class and /dev/null differ
diff --git a/target/classes/com/geekq/miaosha/dao/UserMapper.class b/target/classes/com/geekq/miaosha/dao/UserMapper.class
new file mode 100644
index 0000000..e1dbc1d
Binary files /dev/null and b/target/classes/com/geekq/miaosha/dao/UserMapper.class differ
diff --git a/target/classes/com/geekq/miaosha/domain/MiaoshaUser.class b/target/classes/com/geekq/miaosha/domain/MiaoshaUser.class
index 2b7c5fe..fd4b78a 100644
Binary files a/target/classes/com/geekq/miaosha/domain/MiaoshaUser.class and b/target/classes/com/geekq/miaosha/domain/MiaoshaUser.class differ
diff --git a/target/classes/com/geekq/miaosha/result/CodeMsg.class b/target/classes/com/geekq/miaosha/result/CodeMsg.class
index 9330f7f..0f76fc6 100644
Binary files a/target/classes/com/geekq/miaosha/result/CodeMsg.class and b/target/classes/com/geekq/miaosha/result/CodeMsg.class differ
diff --git a/target/classes/com/geekq/miaosha/result/Result.class b/target/classes/com/geekq/miaosha/result/Result.class
index a921905..c007502 100644
Binary files a/target/classes/com/geekq/miaosha/result/Result.class and b/target/classes/com/geekq/miaosha/result/Result.class differ
diff --git a/target/classes/com/geekq/miaosha/service/IUserService.class b/target/classes/com/geekq/miaosha/service/IUserService.class
new file mode 100644
index 0000000..b39e955
Binary files /dev/null and b/target/classes/com/geekq/miaosha/service/IUserService.class differ
diff --git a/target/classes/com/geekq/miaosha/service/MiaoShaUserService.class b/target/classes/com/geekq/miaosha/service/MiaoShaUserService.class
index 0dc2cec..2a213f6 100644
Binary files a/target/classes/com/geekq/miaosha/service/MiaoShaUserService.class and b/target/classes/com/geekq/miaosha/service/MiaoShaUserService.class differ
diff --git a/target/classes/mybatis/config.xml b/target/classes/mybatis/config.xml
new file mode 100644
index 0000000..fe0f5e4
--- /dev/null
+++ b/target/classes/mybatis/config.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/target/classes/mybatis/mapper/UserMapper.xml b/target/classes/mybatis/mapper/UserMapper.xml
new file mode 100644
index 0000000..18da536
--- /dev/null
+++ b/target/classes/mybatis/mapper/UserMapper.xml
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ insert into miaosha_user (id, nickname, salt, register_date,last_login_date,login_Count ) values
+ (#{id,jdbcType=BIGINT},#{nickname,jdbcType=VARCHAR},
+ #{salt,jdbcType=VARCHAR},#{registerDate,jdbcType=DATE},#{lastLoginDate,jdbcType=DATE},
+ #{loginCount,jdbcType=INTEGER}
+ )
+
+
+
+
+
+ update miaosha_user set nickname = #{nickname},
+ login_Count = #{loginCount}
+ where id=#{id}
+
+
+
+
+ delete from miaosha_user
+ where id = #{id,jdbcType=BIGINT}
+
+
+
+ id, nickname, salt, register_date,last_login_date,login_Count
+
+
+
+
+
+
+
+
+
+
+
diff --git a/target/classes/templates/login.html b/target/classes/templates/login.html
index f04c028..fb816af 100644
--- a/target/classes/templates/login.html
+++ b/target/classes/templates/login.html
@@ -48,10 +48,10 @@