Skip to content

Commit d5d69c5

Browse files
committed
4. 登录JSON自定义数据成功 14:42
1 parent e15ffb5 commit d5d69c5

41 files changed

Lines changed: 73 additions & 56 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 2 additions & 2 deletions

src/main/java/com/tencent/controller/TsmcpUserControl.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.tencent.controller;
22

3+
import com.alibaba.fastjson.JSONArray;
34
import com.tencent.pojo.TsmcpUser;
45
import com.tencent.service.ITsmcpUserService;
56
import org.springframework.beans.factory.annotation.Autowired;
@@ -8,7 +9,6 @@
89
import org.springframework.web.bind.annotation.RestController;
910

1011
import java.util.List;
11-
import java.util.Map;
1212

1313
/**
1414
* @ClassName TsmcpUserControl.java
@@ -30,11 +30,12 @@ public List<TsmcpUser> selectAll(){
3030
}
3131

3232
@PostMapping("/Login")
33-
public Map<Boolean,String> login(String username, String password){
34-
Map<Boolean,String> tsmcpUser = iTsmcpUserService.Login(username,password);
35-
return tsmcpUser;
33+
public JSONArray Login(String username, String password){
34+
JSONArray tsmcpUsers = iTsmcpUserService.Login(username,password);
35+
return tsmcpUsers;
3636
}
3737

38+
3839
/**
3940
* 判断用户名是否已存在
4041
* @param username
@@ -51,6 +52,8 @@ public Boolean isExistUsername(String username){
5152

5253
/**
5354
* 获取所有的工厂ID
55+
* 返回前端的是数组格式
56+
* 如 [1,2,3,4]
5457
* @return
5558
* @author xianxian
5659
* @create:2019-10-29

src/main/java/com/tencent/service/ITsmcpUserService.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.tencent.service;
22

3+
import com.alibaba.fastjson.JSONArray;
34
import com.tencent.pojo.TsmcpUser;
45

56
import java.util.List;
6-
import java.util.Map;
77

88
/**
99
* @author xianxian
@@ -15,16 +15,16 @@
1515
public interface ITsmcpUserService {
1616

1717
/**
18-
* @param user_name
19-
* @param user_password
20-
* @return Boolean
18+
*
19+
* @param username
20+
* @param password
21+
* @return
2122
* @author xianxian
22-
* @create:2019-10-29
23+
* @create:2019-11-05
2324
* @Description
2425
* 用户登录
2526
*/
26-
// public List<TsmcpUser> Login(String user_name, String user_password);
27-
public Map<Boolean,String> Login(String user_name, String user_password);
27+
public JSONArray Login(String username, String password);
2828

2929
public List<TsmcpUser> selectAll();
3030

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.tencent.service.impl;
22

3+
import com.alibaba.fastjson.JSONArray;
4+
import com.alibaba.fastjson.JSONObject;
35
import com.tencent.mapper.TsmcpUserMapper;
46
import com.tencent.pojo.TsmcpUser;
57
import com.tencent.service.ITsmcpUserService;
@@ -8,9 +10,7 @@
810
import org.springframework.transaction.annotation.Transactional;
911

1012
import java.io.Serializable;
11-
import java.util.HashMap;
1213
import java.util.List;
13-
import java.util.Map;
1414

1515
/**
1616
* @ClassName ITsmcpUserServiceImpl.java
@@ -27,46 +27,42 @@ public class ITsmcpUserServiceImpl implements ITsmcpUserService , Serializable {
2727
@Autowired
2828
private TsmcpUserMapper tsmcpUserMapper;
2929

30-
// @Override
31-
// public List<TsmcpUser> Login(String user_name, String user_password) {
32-
// List<TsmcpUser> tsmcpUser = tsmcpUserMapper.Login(user_name,user_password);
33-
// return tsmcpUser;
34-
// }
35-
36-
// @Override
37-
// public Map<Boolean,String> Login(String user_name, String user_password) {
38-
// Map<> tsmcpUser = tsmcpUserMapper.Login(username,password);
39-
// Map<Boolean,String> map =new HashMap<>();
40-
// if(tsmcpUser == null){
41-
// Boolean result = false;
42-
// map.put(result,"密码错误");
43-
// }else {
44-
// Boolean result = true;
45-
// map.put(result,"");
46-
// }
47-
// List<Object> objects = new ArrayList<>();
48-
// return map;
49-
// }
5030

31+
/**
32+
*
33+
*
34+
*
35+
* [{
36+
* result:true/false,
37+
* mes:"",
38+
* num:Integer
39+
* },{},{}]
40+
*
41+
* @param username
42+
* @param password
43+
* @return
44+
*/
5145

5246
@Override
53-
public Map<Boolean, String> Login(String user_name, String user_password) {
54-
List<TsmcpUser> tsmcpUser = tsmcpUserMapper.Login(user_name,user_password);
55-
Map<Boolean,String> map =new HashMap<>();
56-
if(tsmcpUser == null){
57-
Boolean result = false;
58-
map.put(result,"密码错误");
47+
public JSONArray Login(String username, String password) {
48+
List<TsmcpUser> tsmcpUsers = tsmcpUserMapper.Login(username,password);
49+
JSONArray jSONArray = new JSONArray();
50+
JSONObject jb = new JSONObject();
51+
if(tsmcpUsers == null || tsmcpUsers.isEmpty()){
52+
//登录不成功
53+
jb.put("result",false);
54+
jb.put("message","密码错误");
5955
}else {
60-
Boolean result = true;
61-
map.put(result,"");
56+
//登录成功
57+
jb.put("result",true);
58+
jb.put("message","");
6259
}
63-
// List<Object> objects = new ArrayList<>();
64-
return map;
60+
jSONArray.add(jb);
61+
return jSONArray;
6562
}
6663

6764
@Override
6865
public List<TsmcpUser> selectAll() {
69-
7066
return tsmcpUserMapper.selectAll();
7167
}
7268

@@ -97,4 +93,27 @@ public Boolean insertIntoTsmcpUser(TsmcpUser tsmcpUser) {
9793
return false;
9894
}
9995
}
96+
97+
98+
// public static void main(String[] args) {
99+
// JSONArray jSONArray = new JSONArray();
100+
// JSONObject jb = new JSONObject();
101+
// jb.put("id", 1);
102+
// jb.put("name", "s");
103+
// jSONArray.add(jb);
104+
// JSONObject j1 = new JSONObject();
105+
// j1.put("id", 2);
106+
// j1.put("name", "s");
107+
// jSONArray.add(j1);
108+
// StringBuffer sBuffer = new StringBuffer();
109+
// System.out.println(jSONArray.stream());
110+
// jSONArray.stream().forEach(jsonobejct->arrayIdToString((JSONObject) jsonobejct,sBuffer));
111+
// System.out.println(sBuffer.toString());
112+
// }
113+
//
114+
// private static StringBuffer arrayIdToString(JSONObject jsonobejct,
115+
// StringBuffer sBuffer) {
116+
// return sBuffer.append(jsonobejct.getInteger("id")).append(",");
117+
// }
118+
100119
}

src/main/webapp/login.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
package com.tencent;
22

3-
import com.tencent.mapper.TsmcpUserMapper;
4-
import com.tencent.pojo.TsmcpUser;
5-
import org.apache.ibatis.session.SqlSession;
63
import org.apache.ibatis.session.SqlSessionFactory;
74
import org.junit.jupiter.api.Test;
85
import org.springframework.beans.factory.annotation.Autowired;
96
import org.springframework.boot.test.context.SpringBootTest;
107

11-
import java.util.List;
12-
138
@SpringBootTest
149
class TsmcpApplicationTests {
1510

@@ -22,14 +17,14 @@ void contextLoads() {
2217
//SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("sqlMapConfig.xml"));
2318

2419
//2. 获取SqlSession接口
25-
SqlSession session = factory.openSession();
20+
// SqlSession session = factory.openSession();
2621

2722
//2.获取TsmcpUserMapper
28-
TsmcpUserMapper tsmcpUserMapper = session.getMapper(TsmcpUserMapper.class);
23+
// TsmcpUserMapper tsmcpUserMapper = session.getMapper(TsmcpUserMapper.class);
2924

3025
//3.调用查询
31-
List<TsmcpUser> tsmcpUser = tsmcpUserMapper.Login("SCOTT","123456");
32-
System.out.println(tsmcpUser.toString());
26+
// List<TsmcpUser> tsmcpUser = tsmcpUserMapper.Login("SCOTT","123456");
27+
// System.out.println(tsmcpUser.toString());
3328
}
3429

3530
}
-6 Bytes
Binary file not shown.
Binary file not shown.
-3 Bytes
Binary file not shown.
-6 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)