SSM整合

目录

1.导入依赖

2.配置web.xml

3.配置自定义的springmvc.xml

4.spring配置文件

5. mybatis-config

6. 测试

6.1controller

6.2Service

6.3Dao

6.4跳转的页面

6.5结果 


  • 相关标签的注解含义写在了代码中

1.导入依赖


    
    
        5.3.1
    

    
        
            org.springframework
            spring-context
            ${spring.version}
        
        
            org.springframework
            spring-beans
            ${spring.version}
        

        
        
            org.springframework
            spring-web
            ${spring.version}
        
        
            org.springframework
            spring-webmvc
            ${spring.version}
        

        
        
            org.springframework
            spring-jdbc
            ${spring.version}
        

        
            org.springframework
            spring-aspects
            ${spring.version}
        
        
            org.springframework
            spring-test
            ${spring.version}
        

        
        
            org.mybatis
            mybatis
            3.5.7
        
        
        
            org.mybatis
            mybatis-spring
            2.0.6
        

        
        
            com.alibaba
            druid
            1.0.9
        
        
        
            junit
            junit
            4.12
            test
        
        
        
            mysql
            mysql-connector-java
            8.0.33
        

        
        
            log4j
            log4j
            1.2.17
        

        
        
            com.github.pagehelper
            pagehelper
            5.2.0
        

        
        
            ch.qos.logback
            logback-classic
            1.2.3
        

        
        
            javax.servlet
            javax.servlet-api
            3.0.1
            provided
        

        
        
            com.fasterxml.jackson.core
            jackson-databind
            2.12.1
        
        
        
            commons-fileupload
            commons-fileupload
            1.3.1
        

        
        
            org.thymeleaf
            thymeleaf-spring5
            3.0.12.RELEASE
        
    

2.配置web.xml

  
    
        CharacterEncodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
            encoding
            UTF-8
        
        
            forceResponseEncoding
            true
        
    
    
        CharacterEncodingFilter
        /*
    

    
    
        HiddenHttpMethodFilter
        org.springframework.web.filter.HiddenHttpMethodFilter
    
    
        HiddenHttpMethodFilter
        /*
    

    
    
        SpringMVC
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            classpath:springmvc.xml
        
        1
    
    
        SpringMVC
        /
    

    
    
        org.springframework.web.context.ContextLoaderListener
    


    
    
        contextConfigLocation
        classpath:spring.xml
    

3.配置自定义的springmvc.xml

  • 拦截器和异常处理器可以根据需求配置
 
    

    
    
        
        
        
            
                
                    
                        
                        
                        
                        
                        
                        
                    
                
            
        
    


    
    

    
    


    
    


    
    

    

    

4.spring配置文件

spring整合mybatis

 
    
        
    

    
    

    
    
        
        
        
        
    

    
    
        
    

    
    


    
    
        
        
        
        
        
        

        
        
    

    
    
        
    

5. mybatis-config

未用spring整合的插件

    
    
        
    

    
    
        
    

6. 测试

只测试分页功能

 

SSM整合_第1张图片

6.1controller

@Controller
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @RequestMapping(value = "/employee/page/{pageNum}",method = RequestMethod.GET)
    public String getEmployeePage(@PathVariable("pageNum") Integer pageNum,Model model) {
        //获取员工的分页信息
        PageInfo page=employeeService.getEmployeePage(pageNum);

        //将分页数据共享到请求域中
        model.addAttribute("page",page);

        return "employee";
    }
}

6.2Service

@Service
@Transactional
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;


    @Override
    public PageInfo getEmployeePage(Integer pageNum) {
        //开启分页功能
        PageHelper.startPage(pageNum, 2);
        //查询所有员工信息
        List list= employeeMapper.getAllEmployee();

        //获取分页相关数据
        PageInfo page=new PageInfo<>(list,3);
        return page;
    }
}

6.3Dao

public interface EmployeeMapper {

    List getAllEmployee();
}

6.4跳转的页面

员工信息
流水号 员工姓名 年龄 性别 邮箱 操作
删除 修改

6.5结果 

SSM整合_第2张图片

你可能感兴趣的:(java,eclipse,idea,tomcat,后端,mybatis,http)