ssm项目搭建的详细步骤 | 您所在的位置:网站首页 › ssm项目搭建过程 › ssm项目搭建的详细步骤 |
1.Springmvc的项目搭建
我们要创建ssm框架 首先要搭建一个springmvc的框架 1.创建一个maven项目 < !–在当前pom 或者父类pom 中声明属性 --> 5.0.16.RELEASE 在< dependencies>标签中加入 javax.servlet javax.servlet-api 3.0.1 provided javax.servlet.jsp jsp-api 2.1 provided org.springframework spring-context ${spirng.version} org.springframework spring-aop ${spirng.version} org.aspectj aspectjrt 1.6.12 org.aspectj aspectjweaver 1.6.12 org.springframework spring-webmvc ${spirng.version} com.fasterxml.jackson.core jackson-databind 2.9.9 com.fasterxml.jackson.core jackson-core 2.9.9 com.fasterxml.jackson.core jackson-annotations 2.9.93.在src/main下创建resources和java文件夹 并设置为源文件 4.在resources目录下创建springmvc-servlet.xml文件 5.在web.xml文件中加入声明 springmvc org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:springmvc-servlet.xml springmvc /6.在springmvc-servlet中加入 2.Spring和Mybatis的整合 1导入jar 在springmvc 工程基础上导入 mytatis 相关依赖 com.alibaba druid 1.1.16 org.mybatis mybatis-spring 1.3.0 org.mybatis mybatis 3.4.5 mysql mysql-connector-java 5.1.9 log4j log4j 1.2.12 org.springframework spring-tx ${spirng.version} org.springframework spring-jdbc 5.0.16.RELEASE 2.将mybatis.properties,log4j.properties(可以不拷贝),mybatis-config.xml拷贝到resource文件下(1)mybatis.properties jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/test jdbc.username=root jdbc.password=123456(2)mybatis-config.xml ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m\n 3.创建并配置applicationContext.xml 4.创建对应的dao 和mapper根据自己的需要去创建entity层,dao层,service层 对应的目录结构如下,一定记dao层和对应的xml文件在路径名相同的文件夹下 测试 public class Test1 { public static void main(String[] args) { ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml"); //从容器获取 AccountService accountService = applicationContext.getBean(AccountService.class); accountService.transMoney(1,2,3000); } }结果正确说明spring和mybatis搭建没有出错 controller findStudentById方法 @RestController public class StudentController { @Autowired private StudentService studentService; @GetMapping("/findStudentById/{id}") public Student findStudentById(@PathVariable("id") int id){ Student student = studentService.findStudentById(id); return student; }student.html /** * 根据id查找学生 */ function findStudentById() { $.ajax({ url:"/findStudentById/"+$("#id").val(), type:'get', // 使用get方式请求 //dataType:'json',// 将接收的数据转为json success:function (data) { alert(JSON.stringify(data)) }, error:function () { alert("服务器错误") } }) } 查询学生 5配置tomcat并启动在输入框输入http://localhost:8080/student.html |
CopyRight 2018-2019 实验室设备网 版权所有 |