mirror of
				https://gitee.com/coder-xiaomo/flashsale
				synced 2025-11-04 14:13:14 +08:00 
			
		
		
		
	改正telephone拼写错误;添加viewobject;修正age类型错误
This commit is contained in:
		
							
								
								
									
										10
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								README.md
									
									
									
									
									
								
							@@ -16,13 +16,19 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
> http://localhost:8090/user/get?id=1
 | 
					> http://localhost:8090/user/get?id=1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					预期效果:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{"id":1,"name":"admin","gender":2,"age":18,"telephone":"110"}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 层次结构(以User为例,自上向下)
 | 
					### 层次结构(以User为例,自上向下)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
|                               | 目录                  | Java对象类型      | 说明                                     | 举例                         |
 | 
					|                               | 目录                  | Java对象类型      | 说明                                     | 举例                         |
 | 
				
			||||||
| ----------------------------- |-----------------------| ----------------- | ----------------------- | ----------------------------- |
 | 
					| ----------------------------- | --------------------- | ----------------- | ---------------------------------------- | ---------------------------- |
 | 
				
			||||||
| **<nobr>Controller层</nobr>** |                       |                   |                                          |                              |
 | 
					| **<nobr>Controller层</nobr>** |                       |                   |                                          |                              |
 | 
				
			||||||
| Controller                    | controller            | 类 class          |                                          | controller.UserController    |
 | 
					| Controller                    | controller            | 类 class          |                                          | controller.UserController    |
 | 
				
			||||||
| Controller                    | controller/viewobject | 类 class          |                         | controller.UserController     |
 | 
					| View Object                   | controller/viewobject | 类 class          | 将用户Model转化为可供UI使用的View Object | controller.UserController    |
 | 
				
			||||||
|                               |                       |                   |                                          |                              |
 | 
					|                               |                       |                   |                                          |                              |
 | 
				
			||||||
| **<nobr>Service层</nobr>**    | 转换成业务模型        |                   |                                          |                              |
 | 
					| **<nobr>Service层</nobr>**    | 转换成业务模型        |                   |                                          |                              |
 | 
				
			||||||
| Service                       | service               | 接口 interface    |                                          | service.UserService          |
 | 
					| Service                       | service               | 接口 interface    |                                          | service.UserService          |
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,10 @@
 | 
				
			|||||||
package com.cxyxiaomo.flashsale.controller;
 | 
					package com.cxyxiaomo.flashsale.controller;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.cxyxiaomo.flashsale.controller.viewobject.UserVO;
 | 
				
			||||||
import com.cxyxiaomo.flashsale.service.UserService;
 | 
					import com.cxyxiaomo.flashsale.service.UserService;
 | 
				
			||||||
import com.cxyxiaomo.flashsale.service.model.UserModel;
 | 
					import com.cxyxiaomo.flashsale.service.model.UserModel;
 | 
				
			||||||
import org.apache.catalina.User;
 | 
					import org.apache.catalina.User;
 | 
				
			||||||
 | 
					import org.springframework.beans.BeanUtils;
 | 
				
			||||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
					import org.springframework.beans.factory.annotation.Autowired;
 | 
				
			||||||
import org.springframework.stereotype.Controller;
 | 
					import org.springframework.stereotype.Controller;
 | 
				
			||||||
import org.springframework.web.bind.annotation.RequestMapping;
 | 
					import org.springframework.web.bind.annotation.RequestMapping;
 | 
				
			||||||
@@ -18,9 +20,20 @@ public class UserController {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @RequestMapping("/get")
 | 
					    @RequestMapping("/get")
 | 
				
			||||||
    @ResponseBody
 | 
					    @ResponseBody
 | 
				
			||||||
    public UserModel getUser(@RequestParam(name = "id") Integer id) {
 | 
					    public UserVO getUser(@RequestParam(name = "id") Integer id) {
 | 
				
			||||||
        // 调用Services服务获取对应id的用户对象并返回给前端
 | 
					        // 调用Services服务获取对应id的用户对象并返回给前端
 | 
				
			||||||
        UserModel userModel = userService.getUserById(id);
 | 
					        UserModel userModel = userService.getUserById(id);
 | 
				
			||||||
        return userModel;
 | 
					        // 将核心领域模型用户对象转化为可供UI使用的viewobject
 | 
				
			||||||
 | 
					        return convertFromModel(userModel);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private UserVO convertFromModel(UserModel userModel) {
 | 
				
			||||||
 | 
					        if (userModel == null) {
 | 
				
			||||||
 | 
					            return null;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        UserVO userVO = new UserVO();
 | 
				
			||||||
 | 
					        BeanUtils.copyProperties(userModel, userVO);
 | 
				
			||||||
 | 
					        return userVO;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,50 @@
 | 
				
			|||||||
 | 
					package com.cxyxiaomo.flashsale.controller.viewobject;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class UserVO {
 | 
				
			||||||
 | 
					    private Integer id;
 | 
				
			||||||
 | 
					    private String name;
 | 
				
			||||||
 | 
					    private Byte gender;
 | 
				
			||||||
 | 
					    private Integer age;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Integer getId() {
 | 
				
			||||||
 | 
					        return id;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setId(Integer id) {
 | 
				
			||||||
 | 
					        this.id = id;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public String getName() {
 | 
				
			||||||
 | 
					        return name;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setName(String name) {
 | 
				
			||||||
 | 
					        this.name = name;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Byte getGender() {
 | 
				
			||||||
 | 
					        return gender;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setGender(Byte gender) {
 | 
				
			||||||
 | 
					        this.gender = gender;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Integer getAge() {
 | 
				
			||||||
 | 
					        return age;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setAge(Integer age) {
 | 
				
			||||||
 | 
					        this.age = age;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public String getTelephone() {
 | 
				
			||||||
 | 
					        return telephone;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setTelephone(String telephone) {
 | 
				
			||||||
 | 
					        this.telephone = telephone;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private String telephone;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -4,8 +4,8 @@ public class UserModel {
 | 
				
			|||||||
    private Integer id;
 | 
					    private Integer id;
 | 
				
			||||||
    private String name;
 | 
					    private String name;
 | 
				
			||||||
    private Byte gender;
 | 
					    private Byte gender;
 | 
				
			||||||
    private String age;
 | 
					    private Integer age;
 | 
				
			||||||
    private String telphone;
 | 
					    private String telephone;
 | 
				
			||||||
    private String registerMode;
 | 
					    private String registerMode;
 | 
				
			||||||
    private String thirdPartyId;
 | 
					    private String thirdPartyId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -35,20 +35,20 @@ public class UserModel {
 | 
				
			|||||||
        this.gender = gender;
 | 
					        this.gender = gender;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public String getAge() {
 | 
					    public Integer getAge() {
 | 
				
			||||||
        return age;
 | 
					        return age;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void setAge(String age) {
 | 
					    public void setAge(Integer age) {
 | 
				
			||||||
        this.age = age;
 | 
					        this.age = age;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public String getTelphone() {
 | 
					    public String getTelephone() {
 | 
				
			||||||
        return telphone;
 | 
					        return telephone;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void setTelphone(String telphone) {
 | 
					    public void setTelephone(String telephone) {
 | 
				
			||||||
        this.telphone = telphone;
 | 
					        this.telephone = telephone;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public String getRegisterMode() {
 | 
					    public String getRegisterMode() {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user