Controller层的写法

更新时间:2023-06-15 00:54:18 阅读: 评论:0

Controller层的写法
项⽬中的两个Controller层实现类,⼀个是跳转到jsp页⾯,⼀个是以Json形式返回Map键值对。
跳转到jsp页⾯:
ller;
2
3import java.io.IOException;
existent4
5import javax.rvlet.http.HttpServletRequest;
6
7import s.httpclient.HttpClient;
8import s.httpclient.HttpException;
9import hods.PostMethod;
10import org.springframework.stereotype.Controller;
11import org.springframework.web.bind.annotation.RequestMapping;
12import org.springframework.web.rvlet.ModelAndView;
13
14import util.AuthConfig;
15
我是一只鸡16 @Controller
17public class Operate {
18    @RequestMapping(value="login.html")
19public ModelAndView requestPost(HttpServletRequest request){
20        AuthConfig config = Instance();
21        String rver = ConfigParameter("rver");
22        String client_id = ConfigParameter("client_id");
23        String client_cret = ConfigParameter("client_cret");
24        String redirect_uri = ConfigParameter("redirect_uri");
25        String scope = ConfigParameter("scope");
26        String url = rver+"AuthServer/oauth2/authorize?client_id="+client_id+"&client_cret="+client_cret+"&redirect_uri="+redirect_uri+"&respon_type=code&scope="+scope;
27        System.out.println(url);
28        ModelAndView mav = new ModelAndView("login");
29        mav.addObject("url", url);
30return mav;
31    }
32 }
⼀个是以Json形式返回Map键值对:
1package com.ller;
2
3import java.util.HashMap;
4import java.util.Map;
5module1
6import com.ken.AuthKeyGenerator;
7import com.ken.DefaultAuthKeyGenerator;
8import com.bupt.oauth2.utils.*;
9
10import org.springframework.beans.factory.annotation.Autowired;
11
12import com.OAuth2AccessToken;
13
14import org.springframework.web.bind.annotation.RequestBody;
15import org.springframework.web.bind.annotation.RequestMapping;
16import org.springframework.web.bind.annotation.RequestMethod;
17import org.springframework.web.bind.annotation.ResponBody;
18import org.springframework.web.bind.annotation.RestController;
19
20import com.bupt.auth.bussiness.RegisterAppBean;
amor什么意思21import com.bupt.auth.bussiness.RegisterBean;
22import com.ity.Ur;
23import com.ption.MyException;
文都考研怎么样24import com.bupt.auth.rvice.UrManager;
25import com.bupt.oauth2.peve.TokenHandler;
baudi
26import com.util.OAuth2Utils;
27import com.util.VePeUtils;
28
29 @RestController
30public class RegisteController
31 {
32    @Autowired
33private TokenHandler tokenHandler;
34    @Autowired
35private UrManager urManager;
36
37private AuthKeyGenerator authKeyGenerator = new DefaultAuthKeyGenerator();
38
39    @RequestMapping(value="/registerur.html",method=RequestMethod.POST)
40    @ResponBody
41public Map<String, Object> register(@RequestBody RegisterBean registerbean)
42    {
43        Map<String, Object> map = new HashMap<String, Object>();
44        Ur ur = new Ur();
45try{
46if(urManager.Ur_name()) != null){
47                map.put("result", "fail");
48                map.put("info", "Urname has already exist!!");
49                map.put("failcode", "602");
50return map;
51            }
52        }catch(MyException e){
53            map.put("result", "fail");
54            map.put("info", e.getMessage());
55            map.put("failcode", e.getFailCode());
56return map;island
57        }
58
59        ur.Ur_name());
60        ur.Ur_password());
61        ur.Info());
62        urManager.addUr(ur);
63
64        createUrAccessToken(ur);
奥林匹斯山十二主神
65        System.out.Ur_name());
66
67        map.put("result", "success");
68return map;
69    }
70
71private void createUrAccessToken(Ur ur)
72    {
cnn英语中英翻译网73        String urName = ur.getUrname();
74        String urId = String.Id());
75        Map<String, String> requestParameters =  VePeUtils.buildRequestParameters(urId, null);
76        tokenHandler.accessToken(requestParameters);
77//ur 中存放authentication_id
78//与JdbcTokenStore中storeAccessToken⽅法中⽣成authentication_id相对应
79        ur.String()));
80        urManager.updateUr(ur);
81    }
82 }

本文发布于:2023-06-15 00:54:18,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/78/956473.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:键值   考研   返回   文都   形式
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图