写在前面的扑街(gai)日记:我连初心都快忘了,竟然还能想起她,这该死的。。。该死的bug!!!
环境:windows 7
开发工具:IDEA 2020
数据库:mysql 8.0
项目实现预览:
mysql8.0表单预览:
简单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
项目结构预览):
2,建立springMvc.xml 配置文件
springMvc.xml:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
">
3,配置web.xml:
/p>
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
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:
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
mybatis-config.xml:
/p>
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
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:
/p>
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"
>
id , name , age
select * from student
en,差不多就这样了,扑街(gai)一天,结束。。。