idea2019搭建ssm(spring+springMVC+mybatis)项目

1.新建项目
idea2019搭建ssm(spring+springMVC+mybatis)项目_第1张图片
idea2019搭建ssm(spring+springMVC+mybatis)项目_第2张图片
idea2019搭建ssm(spring+springMVC+mybatis)项目_第3张图片
2.在项目根目录新建Directry:target
在这里插入图片描述
3.建好项目目录:
idea2019搭建ssm(spring+springMVC+mybatis)项目_第4张图片

4.引入相关依赖
5.定义实体domain
6.定义对应dao接口
7.配置mapper.xml文件
8.新建三个spring-xx.xml文件
idea2019搭建ssm(spring+springMVC+mybatis)项目_第5张图片
spring-dao.xml:(spring-mybatis整合配置文件)




    
    
    

    
    
        
        
        
        
        

        
        
        
        
        
        
        
        
        
    

    
    
        
        
        
        
        
        
        
        
    

    
    
        
        
        
        
    


spring-mvc.xml:(spring mvc配置文件)




    
    
    
    

    
    

    
    
        
        
        
    

    
    


spring-service.xml




    
    

    
    
        
        
    
    
    

在log4j.properties文件中配置日志设定

log4j.rootLogger=ERROR, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

在mybatis-config.xml文件中配置mybtis框架




    
    
        
        

        
        

        
        
    

配置web.xml文件




  Archetype Created Web Application
  
    dispatcher
    org.springframework.web.servlet.DispatcherServlet
    
    
      contextConfigLocation
      classpath:spring/spring-*.xml
    
  
  
    dispatcher
    
    /
  
  
    encodingFilter
    
      org.springframework.web.filter.CharacterEncodingFilter
    
    
      encoding
      utf-8
    
  

  
    encodingFilter
    /*
  


controller:

package com.controller;

import com.domain.Paper;
import com.service.PaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author Wangxingze
 * @date 2019-06-26 18:34
 */
@Controller
@RequestMapping("/paper")
public class PaperController {
    @Autowired
    private PaperService paperService;

    @RequestMapping("/allPaper")
    public String list(Model model) {
        List list = paperService.queryAllPaper();
        model.addAttribute("list", list);
        return "allPaper";
    }

    @RequestMapping("toAddPaper")
    public String toAddPaper() {
        return "addPaper";
    }

    @RequestMapping("/addPaper")
    public String addPaper(Paper paper) {
        paperService.addPaper(paper);
        return "redirect:/paper/allPaper";
    }

    @RequestMapping("/del/{paperId}")
    public String deletePaper(@PathVariable("paperId") Long id) {
        paperService.deletePaperById(id);
        return "redirect:/paper/allPaper";
    }

    @RequestMapping("toUpdatePaper")
    public String toUpdatePaper(Model model, Long id) {
        model.addAttribute("paper", paperService.queryById(id));
        return "updatePaper";
    }

    @RequestMapping("/updatePaper")
    public String updatePaper(Model model, Paper paper) {
        paperService.updatePaper(paper);
        paper = paperService.queryById(paper.getPaperId());
        model.addAttribute("paper", paper);
        return "redirect:/paper/allPaper";
    }
}

你可能感兴趣的:(springMVC,mybatis,spring)