java点击登录实现跳转_页面跳转的简单实现(单点登录)

需求说明

说明:当用户点击登录/注册按钮时,需要跳转到指定的页面中。

4d37680eb72a29493a9dc8089efeb027.png

编辑UserController@Controller

@RequestMapping("/user")

public class UserController {

/**

* 实现用户模块跳转

* url1:http://www.jt.com/user/login.html 页面:login.jsp

* url2:http://www.jt.com/user/register.html 页面:register.jsp

* @return 页面

* 使用restful的风格

* 动态获取url中的参数,之后实现通用的跳转

*/

@RequestMapping("/{moduleName}")

public String module(@PathVariable String moduleName){

return moduleName;

}

}

页面效果展现

3f4bace99b501d0ad56effb5175951dc.png

实现单点登录

创建JT-SSO项目

236276a295d93a953ed61c2143519818.png

添加继承/依赖/插件<?xml version="1.0" encoding="UTF-8"?>

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

jt-sso

jar

jt

com.jt

1.0-SNAPSHOT

com.jt

jt-common

1.0-SNAPSHOT

org.springframework.boot

spring-boot-maven-plugin

编辑User的POJO对象@TableName("tb_user")

@Data

@Accessors(chain = true)

public class User extends BasePojo{

@TableId(type = IdType.AUTO)//设定主键自增

private Long id; //用户ID号

private String username; //用户名

private String password; //密码 需要md5加密

private String phone; //电话号码

private String email; //使用电话代替邮箱

}

测试JT-SSO项目

用户通过sso.jt.com/findUserAll获取user表中的信息,json返回代码。

8fa0d42934c07b068a128dfecd99e584.png

编辑UserControllerpackage com.jt.controller;

import com.jt.pojo.User;

import com.jt.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController

public class UserController {

@Autowired

private UserService userService;

/**

* 完成测试按钮

* 1.url地址 :findUserAll

* 2.参数信息: null

* 3.返回值结果: List

*

*/

@RequestMapping("/findUserAll")

public List findUserAll(){

return userService.findUserAll();

}

}

编辑UserServicepackage com.jt.service;

import com.jt.mapper.UserMapper;

import com.jt.pojo.User;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class UserServiceImpl implements UserService{

@Autowired

private UserMapper userMapper;

@Override

public List findUserAll() {

return userMapper.selectList(null);

}

}

修改nginx配置

f598fbe340e4cf00e9d9429cee0e4334.png

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值