一个简单的Java SSM项目,记录

写在前面的扑街(gai)日记:我连初心都快忘了,竟然还能想起她,这该死的。。。该死的bug!!!

环境:windows 7

开发工具:IDEA 2020 

数据库:mysql 8.0

项目实现预览:

一个简单的Java SSM项目,记录_第1张图片

mysql8.0表单预览:

 

一个简单的Java SSM项目,记录_第2张图片

简单ssm项目开始:

ssm项目:spring springmvc mybatis

1,导入依赖 :

pom.xml  :


    
      org.springframework
      spring-jdbc
      4.3.11.RELEASE
    


    

    
      org.springframework
      spring-webmvc
      4.3.11.RELEASE
    




    
      org.mybatis
      mybatis
      3.4.5
    

    
      org.mybatis
      mybatis-spring
      1.3.1
    


    
      mysql
      mysql-connector-java
      8.0.11
    


    
      com.mchange
      c3p0
      0.9.5.1
    



    
      javax.servlet
      javax.servlet-api
      4.0.0
      provided
    

 

(放入build里面)


    
    
      src/main/java
      
        **/*.xml
      
    
    

 

 

项目结构预览):

 

一个简单的Java SSM项目,记录_第3张图片

 

2,建立springMvc.xml 配置文件

springMvc.xml:




    
        
        

    

    


 

3,配置web.xml:




  Archetype Created Web Application
  

  
    contextConfigLocation
    classpath:applicationContext.xml
  

    
    org.springframework.web.context.ContextLoaderListener
  
  
  

  
    SpringMvc
    org.springframework.web.servlet.DispatcherServlet
    
      contextConfigLocation
      classpath:springMvc.xml
    
  
  
    SpringMvc
    *.action
  
  
  

 

4,建立 db.properties 和配置 application.xml 以及 mybatis-config.xml和配置

db.properties:

uname=root
upass=1234
url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT
driver_Class=com.mysql.cj.jdbc.Driver

initPoolSize=5
maxPoolSize=20

 

applicationContext.xml:




    
    
    
    
        
        
        
        
        
        
    
    
    
        
        
        
        
        
        
    




    
        
    



  

 

 

mybatis-config.xml:





    
        
    



 

java文件夹里面:

controllers 里面StudentController:

package controllers;

import com.alibaba.fastjson.JSON;

import dao.StudentDao;
import entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * SSM+UI  CRUD
 */
@Controller
public class StudentController {
    HttpServletResponse response;
    @Autowired
    private StudentDao studentDao;







    //    查询所有
    @ResponseBody
    @RequestMapping("getStudent")
    public List getStudent(){
        System.out.println("查询所有111");
        List list=studentDao.getStudent();

        System.out.println("哈哈");
        String data = JSON.toJSONString(list);
        return list;
    }

    @ResponseBody
    @RequestMapping("test")
    public String test(){
        System.out.println("进来了");
        return "ok";
    }


}

dao 里面StudentDao:

package dao;

import entity.Student;

import java.util.List;

public interface StudentDao {

    public List getStudent();


}

entity 里面Student:

package entity;

public class Student {

    private int id ;
    private String name ;
    private int age ;


    public Student() {

    }
    public Student(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

 

mappingXml 里面 Student.xml:




    
id , name , age

    

    

 

en,差不多就这样了,扑街(gai)一天,结束。。。

 

 

你可能感兴趣的:(一个简单的Java SSM项目,记录)