mirror of
				https://gitee.com/coder-xiaomo/flashsale
				synced 2025-11-04 06:03:13 +08:00 
			
		
		
		
	改正telephone拼写错误;添加viewobject;修正age类型错误
This commit is contained in:
		
							
								
								
									
										36
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								README.md
									
									
									
									
									
								
							@@ -16,22 +16,28 @@
 | 
			
		||||
 | 
			
		||||
> http://localhost:8090/user/get?id=1
 | 
			
		||||
 | 
			
		||||
预期效果:
 | 
			
		||||
 | 
			
		||||
```json
 | 
			
		||||
{"id":1,"name":"admin","gender":2,"age":18,"telephone":"110"}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### 层次结构(以User为例,自上向下)
 | 
			
		||||
 | 
			
		||||
|                               | 目录                    | Java对象类型      | 说明                    | 举例                            |
 | 
			
		||||
| ----------------------------- |-----------------------| ----------------- | ----------------------- | ----------------------------- |
 | 
			
		||||
| **<nobr>Controller层</nobr>** |                       |                   |                         |                               |
 | 
			
		||||
| Controller                    | controller            | 类 class          |                         | controller.UserController     |
 | 
			
		||||
| Controller                    | controller/viewobject | 类 class          |                         | controller.UserController     |
 | 
			
		||||
|                               |                       |                   |                         |                               |
 | 
			
		||||
| **<nobr>Service层</nobr>**    | 转换成业务模型               |                   |                         |                               |
 | 
			
		||||
| Service                       | service               | 接口 interface    |                         | service.UserService           |
 | 
			
		||||
| ServiceImpl                   | service/impl          | Service接口实现类 | 将DataObject组装成Model | service.impl.UserServiceImpl  |
 | 
			
		||||
| Model                         | service/model         | 类 class          | 用户模型Model           | service.model.UserModel       |
 | 
			
		||||
|                               |                       |                   |                         |                               |
 | 
			
		||||
| **<nobr>Dao层</nobr>**        | 对数据库的映射               |                   |                         |                               |
 | 
			
		||||
| Mapper                        | dao                   | 接口 interface    |                         | dao.UserDOMapper         |
 | 
			
		||||
| Mapping                       | resources/mapping     | Mapper接口实现类  | xml格式;SQL语句        | mapping/UserDOMapper.xml |
 | 
			
		||||
| Data Object                   | dataobject            | 类 class          |                         | dataobject.UserDO     |
 | 
			
		||||
|                               | 目录                  | Java对象类型      | 说明                                     | 举例                         |
 | 
			
		||||
| ----------------------------- | --------------------- | ----------------- | ---------------------------------------- | ---------------------------- |
 | 
			
		||||
| **<nobr>Controller层</nobr>** |                       |                   |                                          |                              |
 | 
			
		||||
| Controller                    | controller            | 类 class          |                                          | controller.UserController    |
 | 
			
		||||
| View Object                   | controller/viewobject | 类 class          | 将用户Model转化为可供UI使用的View Object | controller.UserController    |
 | 
			
		||||
|                               |                       |                   |                                          |                              |
 | 
			
		||||
| **<nobr>Service层</nobr>**    | 转换成业务模型        |                   |                                          |                              |
 | 
			
		||||
| Service                       | service               | 接口 interface    |                                          | service.UserService          |
 | 
			
		||||
| ServiceImpl                   | service/impl          | Service接口实现类 | 将DataObject组装成Model                  | service.impl.UserServiceImpl |
 | 
			
		||||
| Model                         | service/model         | 类 class          | 用户模型Model                            | service.model.UserModel      |
 | 
			
		||||
|                               |                       |                   |                                          |                              |
 | 
			
		||||
| **<nobr>Dao层</nobr>**        | 对数据库的映射        |                   |                                          |                              |
 | 
			
		||||
| Mapper                        | dao                   | 接口 interface    |                                          | dao.UserDOMapper             |
 | 
			
		||||
| Mapping                       | resources/mapping     | Mapper接口实现类  | xml格式;SQL语句                         | mapping/UserDOMapper.xml     |
 | 
			
		||||
| Data Object                   | dataobject            | 类 class          |                                          | dataobject.UserDO            |
 | 
			
		||||
 | 
			
		||||
**Tips:** Model与Data Object并非完全一一对应,例如UserModel是由ServiceImpl将UserDO和UserPasswordDO组装而成的。
 | 
			
		||||
@@ -1,8 +1,10 @@
 | 
			
		||||
package com.cxyxiaomo.flashsale.controller;
 | 
			
		||||
 | 
			
		||||
import com.cxyxiaomo.flashsale.controller.viewobject.UserVO;
 | 
			
		||||
import com.cxyxiaomo.flashsale.service.UserService;
 | 
			
		||||
import com.cxyxiaomo.flashsale.service.model.UserModel;
 | 
			
		||||
import org.apache.catalina.User;
 | 
			
		||||
import org.springframework.beans.BeanUtils;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.stereotype.Controller;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestMapping;
 | 
			
		||||
@@ -18,9 +20,20 @@ public class UserController {
 | 
			
		||||
 | 
			
		||||
    @RequestMapping("/get")
 | 
			
		||||
    @ResponseBody
 | 
			
		||||
    public UserModel getUser(@RequestParam(name = "id") Integer id) {
 | 
			
		||||
    public UserVO getUser(@RequestParam(name = "id") Integer id) {
 | 
			
		||||
        // 调用Services服务获取对应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 String name;
 | 
			
		||||
    private Byte gender;
 | 
			
		||||
    private String age;
 | 
			
		||||
    private String telphone;
 | 
			
		||||
    private Integer age;
 | 
			
		||||
    private String telephone;
 | 
			
		||||
    private String registerMode;
 | 
			
		||||
    private String thirdPartyId;
 | 
			
		||||
 | 
			
		||||
@@ -35,20 +35,20 @@ public class UserModel {
 | 
			
		||||
        this.gender = gender;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getAge() {
 | 
			
		||||
    public Integer getAge() {
 | 
			
		||||
        return age;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setAge(String age) {
 | 
			
		||||
    public void setAge(Integer age) {
 | 
			
		||||
        this.age = age;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getTelphone() {
 | 
			
		||||
        return telphone;
 | 
			
		||||
    public String getTelephone() {
 | 
			
		||||
        return telephone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setTelphone(String telphone) {
 | 
			
		||||
        this.telphone = telphone;
 | 
			
		||||
    public void setTelephone(String telephone) {
 | 
			
		||||
        this.telephone = telephone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getRegisterMode() {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user