springboot ——pringmvc +mybatis 增三改查——+thymeleaf

springboot ——pringmvc +mybatis 增三改查——+thymeleaf_第1张图片 springboot —+—springmvc -
mybatis 曾三改查

在这里插入图片描述springboot ——pringmvc +mybatis 增三改查——+thymeleaf_第2张图片
在这里插入图片描述

springboot ——pringmvc +mybatis 增三改查——+thymeleaf_第3张图片
在这里插入图片描述
springboot ——pringmvc +mybatis 增三改查——+thymeleaf_第4张图片

springboot ——pringmvc +mybatis 增三改查——+thymeleaf_第5张图片
项目架构 springboot +mybatis—+springmvc

pom.xml

org.springframework.boot spring-boot-starter-parent 1.5.7.RELEASE sping-boot my-springboot-ltv 0.0.1-SNAPSHOT

controller 层

@Controller
@RequestMapping("/user")
public class UserController {

@Autowired
private UserService userService;

@RequestMapping("/{page}")
public String showPage(@PathVariable String page){
	return page;

}

@RequestMapping("/addUser")
public String addUser(User user){
	userService.addUser(user);
	return "success";

}



@RequestMapping("/login")
public String  findAll(Model model){
	List list =userService.findAll();
	model.addAttribute("list", list);
	return "index";	
}

/* @RequestMapping("/login")
public String findAll(Model model){
List list =userService.findAll();
model.addAttribute(“list”, list);
return “login”;
}
*/

/**
 * 根据id查询用户
 */
  @RequestMapping("/findUserById")
public String findUserById(Model model,Integer id){
   User user=userService.selectUserById(id);
   model.addAttribute("user", user);
   return "updateUser"; 
	
}

/**
 * 
 * 更新用户 
 */
@RequestMapping("/editUser")
public String editUser(User user){
	System.out.println(user.getName());
	System.out.println(user.getAge());
	System.out.println(user.getId());
	userService.updateUser(user);
	return "success";
		
}
  
@RequestMapping("/delUser")
public String delUser(Integer id){
	System.out.println("+ahjnakjn+");
	userService.deleteUserById(id);
	return "redirect:/user/login";
	
	
}
service层

import java.util.List;

import com.jzkj.pojo.User;

public interface UserService {

void addUser(User user);

List findAll();

User selectUserById(Integer id);

void updateUser(User user);

void deleteUserById(Integer id);

}

实现类

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jzkj.mapper.UserMapper;
import com.jzkj.pojo.User;
import com.jzkj.service.UserService;
@Service
@Transactional
public class UserServiceImpl implements UserService{

@Autowired
private UserMapper userMapper;

@Override
public void addUser(User user) {
	// TODO Auto-generated method stub
	userMapper.addUser(user);
	
}

@Override
public List findAll() {
	// TODO Auto-generated method stub
	return userMapper.findAll();
}

public User selectUserById(Integer id){
	
	return userMapper.selectUserById(id);
	
}

@Override
public void updateUser(User user) {
	// TODO Auto-generated method stub
	userMapper.updateUser(user);
}

@Override
public void deleteUserById(Integer id) {
	// TODO Auto-generated method stub
	userMapper.deleteUserById(id);
}

}

mapper层

import java.util.List;

import com.jzkj.pojo.User;

public interface UserMapper {

void addUser(User user);

List findAll();

User selectUserById(Integer id);

void updateUser(User user);

void deleteUserById(Integer id);

}

mapper.xml sql

PUBLIC “-//mybatis.org//DTD Mapper 3.0//EN”
“http://mybatis.org/dtd/mybatis-3-mapper.dtd”>

insert into user (name,age) values(#{name},#{age}) select id,name,age from user select id,name,age from user where id=#{id}

update user set name=#{name},age=#{age} where id=#{id}

delete from user where id=#{id}

添加页面

------------添加用户---------------- 用户姓名:
用户年龄:

登入页面

----------用户数据-----------------
  操作
 
 
 
 
        
           
           
           
           
           更新用户
             删除用户
           
      
      
用户ID 用户姓名 用户年龄

跳转成功页面

Insert title here 添加成功

---------------------------la更新工作--------------

修改回显页面 共用一个借口

Insert title here 用户姓名:
用户年龄:

数据源

spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/ssmh
spring.datasource.username=root
spring.datasource.password=root

spring.datasource.type=com.alibaba.druid.pool.DruidDataSource

mybatis.type-aliases-package=com.jzkj.pojo

spring.thymeleaf.cache=false

#spring.mvc.view.prefix=/WEB-INF/jsp/
#spring.mvc.view.suffix=.jsp

你可能感兴趣的:(springboot, mybatis, springboot,计划,web,java)