项目结构

在src/main/java创建com.mst包,在包内创建启动类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 	package com.mst;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication(scanBasePackages = "com.mst")
@EnableScheduling
@EnableTransactionManagement
public class HelloWaterBootV1Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(HelloWaterBootV1Application.class, args);
}

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(HelloWaterBootV1Application.class);
}
}

在src/main/resources创建sql文件夹,在文件夹内创建mapper的xml文件

在src/main/java创建com.mst.dao包,在包内创建Dao接口

在src/main/java创建com.mst.entity包,在包内创建实体类

在src/main/java创建com.mst.service包,在包内创建service接口和接口的实现类

在src/main/java创建com.mst.web包,在包内创建controller类

EasyUI的使用

登录,注册涉及的实体类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 	public class TongYiUserLoginModel {
private int userId;
private String userPhone;
private String userPassword;
private String userName;
private String userCompany;
private int userRole;
private int userStatus;
private String userOpenId;
private String userCreateTime;
private int userBluetooth;
private String userBluetoothTime;
private String userCheck;
private String userCheckTime;
private String userRemark;
private String uloginName;
private String uloginPassword;
}

public class TongYiUserAndPlatform {
private int userId;
private int platformId;
private String loginName;
private String loginPassword;
private String yingshouName;
private String yingshouPassword;
}

public class TongYiPlatform {
private int platformId;
private String platformCode;
private String platformUrl;
private int platformType;
private int platformLocation;
private int platformYingShou;
private String platformAdmin;
private String platformPassword;
private String platformName;
private String platformTcp;
private String platformUdp;
private String yingShouAccount;
private String yingShouPassword;
private String platformRemark;
}

注册,form表单post提交,后台java代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
   @RequestMapping("/enroll")
@ApiImplicitParams({
@ApiImplicitParam(name="userPhone",value="用户电话",required = true),
@ApiImplicitParam(name="userPassword",value="密码",required = true),
@ApiImplicitParam(name="userName",value="用户名",required = true),
@ApiImplicitParam(name="userCompany",value="公司",required = true),
@ApiImplicitParam(name="loginName",value="平台登录账户",required = true),
@ApiImplicitParam(name="loginPassword",value="平台登录密码",required = true)
})
@ResponseBody
public ModelAndView enroll(HttpSession session,String userPhone,
String userPassword,String userName,
String userCompany,String loginName,String loginPassword)
throws Exception {
String md5password="";
if(userPassword!=null){
//md5加密密码
md5password=AppMD5Util.MD5(userPassword);
}
ModelAndView modelAndView = new ModelAndView();
String res = mainService.enrollUser(userPhone,md5password,userName,userCompany,loginName,loginPassword);
modelAndView.setViewName("index");
return modelAndView;
}

// md5加密
public static String MD5(String s) {
char hexDigits[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
try {
byte[] btInput = s.getBytes();
// 获得MD5摘要算法的 MessageDigest 对象
MessageDigest mdInst = MessageDigest.getInstance("MD5");
// 使用指定的字节更新摘要
mdInst.update(btInput);
// 获得密文
byte[] md = mdInst.digest();
// 把密文转换成十六进制的字符串形式
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
return new String(str);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
// md5加密后解密
public static String JM(String inStr) {
char[] a = inStr.toCharArray();
for (int i = 0; i < a.length; i++) {
a[i] = (char) (a[i] ^ 't');
}
String k = new String(a);
return k;
}

@Override
public String enrollUser(String userPhone,
String userPassword,String userName,
String userCompany,String loginName,String loginPassword) {
String res = "";
try {
int i =mainMapper.findUserLoginCount(userPhone);
if(i>0) {
res = "此手机号已注册,请直接登录!";
return res;
}
TongYiUserLoginModel userLogin = new TongYiUserLoginModel();
TongYiUserAndPlatform uap = new TongYiUserAndPlatform();
//userLogin.setUserId();
userLogin.setUserPhone(userPhone);
userLogin.setUserPassword(userPassword);
userLogin.setUserName(userName);
userLogin.setUserCompany(userCompany);
userLogin.setUserRole(-1);
userLogin.setUserStatus(0);
//userLogin.setUserOpenId("");
//userLogin.setUserCreateTime("");
//userLogin.setUserBluetooth();
userLogin.setUserBluetoothTime(null);
//userLogin.setUserCheck("");
userLogin.setUserCheckTime(null);
userLogin.setUserRemark("");
userLogin.setUloginName(loginName);
userLogin.setUloginPassword(loginPassword);
mainMapper.saveUserLogin(userLogin);
res = "注册成功";
} catch (Exception e) {
res = "注册失败";
}
return res;
}

<select id="findUserLoginCount" resultType="int">
select count(*) from t_login_user where UserPhone = #{userPhone}
</select>
<insert id="saveUserLogin">
<selectKey keyProperty="userId" resultType="int" order="AFTER">
select @@identity
</selectKey>
INSERT INTO t_login_user(UserPhone, UserPassword, UserName, UserCompany, UserRole, UserStatus, UserOpenId, UserCreateTime,
UserBluetooth, UserBluetoothTime, UserCheck, UserCheckTime, UserRemark,UloginName,UloginPassword)
VALUES (#{userPhone},#{userPassword},#{userName},
#{userCompany},#{userRole},#{userStatus},#{userOpenId},
sysdate(),#{userBluetooth},#{userBluetoothTime},
#{userCheck},#{userCheckTime},#{userRemark},#{uloginName},#{uloginPassword});
</insert>

登录,form表单post提交,后台java代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@ApiOperation("登陆验证接口")
@ApiImplicitParams({
@ApiImplicitParam(name="username",value="用户名",required = true),
@ApiImplicitParam(name="password",value="密码",required = true)
})
@RequestMapping("/login")
public ModelAndView login(HttpSession session,HttpServletRequest request,String username,String password)
throws Exception {
logger.info("登录用户 :" + username);
if(session.getAttribute("lang") == null || session.getAttribute("lang") =="" ) {
session.setAttribute("lang","zh_CN");
}

String md5pass="";
if(password!=null){
md5pass=AppMD5Util.MD5(password);
}
String userPhone = username;
//url的文件/后的地址
String path = request.getContextPath();
ModelAndView modelAndView = new ModelAndView();
//服务器域名+端口号+/后的地址
String basePath = request.getServerName()+":"+request.getServerPort()+path;
modelAndView.addObject("path", path);
modelAndView.addObject("basePath", basePath);
TongYiUserLoginModel login= mainService.findLoginUser(userPhone,md5pass);

if(login!=null){
try {
if(login.getUserStatus()==0) {
modelAndView.addObject("errMsg", "未审核,不允许登录平台");
modelAndView.setViewName("index");
return modelAndView;
}
List<UserPlatformModel> uap= mainService.findAllPlatByUserId(login.getUserId());
if(uap.size()==1 && login.getUserRole()!=0) {
String url ="redirect:http://"+uap.get(0).getPlatformUrl()+"main/login.do?username="+
uap.get(0).getLoginName()+"&password="+uap.get(0).getLoginPassword()+"&language=0";
return new ModelAndView(url);
}else {
modelAndView.addObject("user", JSON.toJSONString(login));
modelAndView.setViewName("main");
}

} catch (Exception e) {
e.printStackTrace();
modelAndView.setViewName("index");
}

}else{
//登录失败
modelAndView.addObject("errMsg", "用户名或密码错误");
modelAndView.setViewName("index");
}
return modelAndView;
}

@Override
public TongYiUserLoginModel findLoginUser(String userPhone, String password) {
return mainMapper.findLoginUser(userPhone,password);
}
@Override
public List<UserPlatformModel> findAllPlatByUserId(int userId) {
return mainMapper.findAllPlatByUserId(userId);
}

<select id="findLoginUser" resultType="TongYiUserLoginModel">
select * from t_login_user where UserPhone = #{userPhone} and UserPassword = #{userPassword}
</select>
<select id="findAllPlatByUserId" resultType="UserPlatformModel">
SELECT
p.PlatformUrl as platformUrl,
t.LoginName as loginName,
t.LoginPassword as loginPassword
FROM
t_platform p
LEFT JOIN t_user_platform t on p.PlatformId = t.PlatformId
LEFT JOIN t_login_user u on u.UserId = t.UserId
WHERE
u.UserId = #{userId}
GROUP BY p.PlatformId
</select>