Commit eb0e25ff57b76e43a9101ef6669c40f7cc006e01
1 parent
6ba08fc6d4
Exists in
master
controller获取json
Showing 2 changed files with 43 additions and 0 deletions
parent/hospital.web/pom.xml
View file @
eb0e25f
| ... | ... | @@ -22,6 +22,11 @@ |
| 22 | 22 | <version>core.sdk-1.0</version> |
| 23 | 23 | </dependency> |
| 24 | 24 | <dependency> |
| 25 | + <groupId>com.lyms.base.common</groupId> | |
| 26 | + <artifactId>base.common</artifactId> | |
| 27 | + <version>base.common-1.0</version> | |
| 28 | + </dependency> | |
| 29 | + <dependency> | |
| 25 | 30 | <groupId>com.lyms</groupId> |
| 26 | 31 | <artifactId>hospital.mac</artifactId> |
| 27 | 32 | <version>${project.parent.version}</version> |
parent/hospital.web/src/main/java/com/lyms/hospital/controller/LoginController.java
View file @
eb0e25f
| 1 | 1 | package com.lyms.hospital.controller; |
| 2 | 2 | |
| 3 | +import org.springframework.web.bind.annotation.RequestBody; | |
| 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; |
| 4 | 5 | import org.springframework.web.bind.annotation.RequestMethod; |
| 6 | +import org.springframework.web.bind.annotation.ResponseBody; | |
| 5 | 7 | import org.springframework.web.bind.annotation.RestController; |
| 6 | 8 | |
| 9 | +import com.alibaba.fastjson.JSON; | |
| 10 | +import com.alibaba.fastjson.JSONObject; | |
| 11 | +import com.lyms.base.common.entity.user.Users; | |
| 7 | 12 | import com.lyms.web.controller.BaseController; |
| 8 | 13 | |
| 9 | 14 | import io.swagger.annotations.Api; |
| ... | ... | @@ -24,5 +29,38 @@ |
| 24 | 29 | // request.getSession().setAttribute("abc", "123"); |
| 25 | 30 | return "abc"; |
| 26 | 31 | } |
| 32 | + | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * <li>@Description:测试@RequestBody | |
| 36 | + * <li>@param reqJson | |
| 37 | + * <li>@param users | |
| 38 | + * <li>@return | |
| 39 | + * <li>创建人:方承 | |
| 40 | + * <li>创建时间:2017年3月28日 | |
| 41 | + * <li>修改人: | |
| 42 | + * <li>修改时间: | |
| 43 | + */ | |
| 44 | + @RequestMapping(value = "/testPostJson", method = RequestMethod.POST) | |
| 45 | + @ResponseBody | |
| 46 | + public String testPostJson(@RequestBody JSONObject reqJson){ | |
| 47 | + Users u = getRequestUsersEntity(reqJson); | |
| 48 | + System.out.println(JSON.toJSONString(u)); | |
| 49 | + return "1"; | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * <li>@Description:设置业务实体 | |
| 54 | + * <li>@param reqJson | |
| 55 | + * <li>@param users | |
| 56 | + * <li>创建人:方承 | |
| 57 | + * <li>创建时间:2017年3月28日 | |
| 58 | + * <li>修改人: | |
| 59 | + * <li>修改时间: | |
| 60 | + */ | |
| 61 | + private Users getRequestUsersEntity(JSONObject reqJson){ | |
| 62 | + //users.setId(reqJson.getString("id")); | |
| 63 | + return JSON.parseObject(reqJson.toJSONString(), Users.class); | |
| 64 | + } | |
| 27 | 65 | } |