码迷,mamicode.com
首页 > 编程语言 > 详细

springboot 登录+增删改查+获取登录人的ip地址

时间:2019-11-16 17:21:48      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:login   build   clu   path   time   nec   nta   登录页面   sys   

项目刚开始用的是springboot CRUD 后来加了一个功能能获取当前登录人的ip地址和当前人姓名 下面附上gitHub地址

项目结构图
技术图片

 

 


application.yml 配置文件
技术图片

 

 


mysql 数据库
技术图片

 

 

entity 实体
技术图片

 

 


userMapper
技术图片

 

 


userService
技术图片

 

 


Controller 层

@Controller
public class controller {

@Autowired
UserService userService;
/**
* 满
* 2019年11月9日15:35:44
* @return
*/
@RequestMapping("/index")
public String index() {
return "登录成功";
}

/*查询用户列表*/
@RequestMapping("/listAll")
public String userList(Model model) {
model.addAttribute("users", userService.userList());
System.out.println("查询成功.............");
return "list";
}

/*删除用户*/
@RequestMapping("/del/{id}")
public String deleteUser(@PathVariable("id") Integer id) {
userService.delete(id);
System.out.println("删除成功.............");
return "redirect:/list";
}

/*添加用户页面*/
@RequestMapping("/add")
public String addUser(ModelMap map) {
map.addAttribute("user", new User());
System.out.println("添加成功.............");
return "add";
}

/*更新用户页面*/
@RequestMapping("/update/{id}")
public String updateUser(@PathVariable("id") Integer id, Model model) {
//获取id 然后根据id 查询当前用户的数据
User user = userService.getById(id);
//把根据id 查到的数据 传到前端
model.addAttribute("user", user);
System.out.println("进入修改..........." + user);
return "update";
}

/*添加完用户后重定向到list页面*/
@RequestMapping("/saveI")
public String saveI(@ModelAttribute User user) {
userService.insert(user);
return "redirect:/listAll";
}

/*更新完用户后重定向到list页面*/
@RequestMapping("/saveU")
public String saveU(@ModelAttribute User user) {
userService.update(user);
return "redirect:/listAll";
}

/**
* 跳转到用户登录页面
*
* @return 登录页面
*/
@RequestMapping("/userLogin")
public String userLogin() {
return "login";
}

/* 用户登录检测 */
@RequestMapping("/long")
public String longUser(@Param("username") String username,
@Param("password") String password) {
if (StringUtils.isEmpty(username)) {
return "用户名不能为空";
}
if (StringUtils.isEmpty(password)) {
return "密码不能为空";
}
User user = userService.longUser(username, password);
if (user != null)
{
return "redirect:/listAll";
}
//登录成功重定向到 全查页面
return "redirect:/userLogin";
}
}


登录 login.html
技术图片

 

 技术图片

 

 


删除直接调用方法不需要页面
用户列表页面 list.html
技术图片

 

 技术图片

 

 


添加用户在那个蓝色条里面 鼠标放上去会出现 这个没有细写

添加用户 add.html
技术图片

 

 技术图片

 

 



修改用户 update.html

技术图片

 

 技术图片

 

 


pom文件
<properties>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.2.0</version>
</dependency>

<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>1.1.5</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

#1 测一测 没几个功能 都可以使用 中途遇到不少问题 特别是前后端交互的时候遇到很多问题

#1遇到什么问题可以私聊我
另附上项目git地址(https://github.com/M666666/SpringBoot-ip.git)

 

springboot 登录+增删改查+获取登录人的ip地址

标签:login   build   clu   path   time   nec   nta   登录页面   sys   

原文地址:https://www.cnblogs.com/m-jj/p/11872177.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!