需求说明
说明:当用户点击登录/注册按钮时,需要跳转到指定的页面中。
编辑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;
}
}
页面效果展现
实现单点登录
创建JT-SSO项目
添加继承/依赖/插件<?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返回代码。
编辑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配置