????????????????????????
????????????? ???????[ 2017/4/14 14:16:06 ] ??????????????? ???????
????д??????????????????????????????Щ???????????????
???????????restclient??????????????????????????????????????????token?????token??????????????????????nickname??PS????????????????????????????????????????
????app??eclipse????????????????navicat????mySQL???????restclient????????????????
????Step1:д??????????
?????????Bumofang/.../MemberController.java
package com.fh.controller.bmf.app;
import ...?? ???
@Controller("AppMemberController")
@RequestMapping(value = "/app/user")
public class MemberController extends AppBaseController {
@RequestMapping(value = { "/update" }?? method = {RequestMethod.POST }?? produces = {JSON_UTF8})
@ResponseBody
/*login*/
public Object login(@RequestBody Map<String?? String> map) throws Exception {
String mobile = map.get("mobile");
if(StringUtils.isBlank(mobile)){
return ResponseMessageEnum.ARGUMENT_EXCEPTION.toString();
}
PageData pd = new PageData();
pd.put("MOBILE"?? mobile);
pd = memberService.findByMobile(pd);
if(pd == null || pd.isEmpty()){
return ResponseMessageEnum.ERROR_LOGIN.toString();
}
String userId = pd.getString("ID");
String token = AccessTokenManager.getInstance().putToken(userId);
Map<String??Object> tokenMap = new HashMap<String??Object>();
tokenMap.put("token"?? token);
return ResponseMessageEnum.SUCCESS.appendMapToString(tokenMap);
}
/*update ?????????*/
public Object update(@RequestBody Map<String?? String> map) throws Exception{ //Map<>map??????????????????
Object result = getUser();
if(result instanceof ResponseMessageEnum){
return result.toString();
} //???token???mySQL???????????getUser()?????????1
PageData pd = (PageData)result; //?????????????pd
String nickname = map.get("nickname"); //???restclient?????update?????????{"nickname":"afterTest"}
pd.put("NICKNAME"?? nickname); //??{"nickname":"afterTest"}???????pd
try {
memberService.edit(pd); //??pd?????????mySQL?????
}
catch (Exception e) {
return ResponseMessageEnum.SERVER_SQL_ERROR.toString();
}
return ResponseMessageEnum.SUCCESS.appendMapToString(new HashMap<String?? Object>());
//??restclient???????{“data":{}??"code":200??"msg":"success"}??appendMapToString()?????????4
}
}
????Step2?????????restclient????????body????{"mobile":"15068880000"}??????token??e59dfcbf7f40662aee9a27f4f0ee8303?????1??????????mySQL???????2
????Step3?????????restclient??????update??url??http://localhost:8080/bumofang/app/user/update?token=e59dfcbf7f40662aee9a27f4f0ee8303??body????{"nickname":"afterTest"}?????3??????????????mySQL???????4
???????1
?????????Bumofang/.../ AppBaseController.java
package com.fh.controller.base;
import ...
public class AppBaseController extends BaseController{
@Autowired
protected HttpServletRequest request;
@Resource(name = "memberService")
protected MemberService memberService;
protected Object getUser(){
String token = request.getParameter("token");
if(StringUtils.isBlank(token)){
return ResponseMessageEnum.ARGUMENT_TOKEN_EMPTY;
}
AccessToken accessToken = AccessTokenManager.getInstance().getToken(token);
if(accessToken == null){
return ResponseMessageEnum.ARGUMENT_TOKEN_INVALID;
}
String userId = accessToken.getUserId();
PageData pd = new PageData();
pd.put("ID"?? userId);
try {
PageData rs = memberService.findById(pd);
if(rs == null || rs.isEmpty()){
return ResponseMessageEnum.ERROR_USER_NOT_EXIT;
}
return rs;
} catch (Exception e) {
return ResponseMessageEnum.SERVER_SQL_ERROR;
}
}
}
???????2??
?????????Bumofang/.../MemberService.java
package com.fh.service.bmf.member;
@Service("memberService")
public class MemberService {
public void edit(PageData pd)throws Exception{
dao.update("MemberMapper.edit"?? pd); // MemberMapper.edit?????3
}
}
???????3:??
?????????Bumofang/.../MemberMapper.xml
<mapper namespace="MemberMapper">
<!-- ??? -->
<update id="edit" parameterType="pd">
update MEMBER
set
NUMBER = #{NUMBER}??
USERNAME = #{USERNAME}??
PASSWORD = #{PASSWORD}??
NICKNAME = #{NICKNAME}??
AVATAR = #{AVATAR}??
MOBILE = #{MOBILE}??
PROFESSION = #{PROFESSION}??
DEFAULT_AREA = #{DEFAULT_AREA}??
DEFAULT_ADDRESS = #{DEFAULT_ADDRESS}??
REALNAME = #{REALNAME}??
ID_CARD = #{ID_CARD}??
BANK_CARD = #{BANK_CARD}??
STATUS = #{STATUS}??
WECHAT_ID = #{WECHAT_ID}??
QQ_ID = #{QQ_ID}??
WEIBO_ID = #{WEIBO_ID}??
ID = ID
where
ID = #{ID}
</update>
</mapper>
???????4??
?????????Bumofang/.../ResponseMessageEnum.java
package com.fh.common.model;
import ...
public enum ResponseMessageEnum {
public String appendMapToString(Map<String?? Object> appendMap) {
Map rsMap = new HashMap();
rsMap.put("data"?? appendMap);
rsMap.put("code"?? code);
rsMap.put("msg"?? this.message);
JSONObject jsonNode = JSONObject.fromObject(rsMap); //??rsMap????????JSON???????????jsonNode
return jsonNode.toString();
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11