薄情先生|java开发:S S M 整合开发详解( 三 )


薄情先生|java开发:S S M 整合开发详解

  1. 注册 ContextLoaderListener
  2. 注册 DisatcherServlet
  3. 注册字符集过滤器
  4. 同时创建 Spring 的配置文件和 SpringMVC 的配置文件(上面已经创建好了)
springmvcorg.springframework.web.servlet.DispatcherServletcontextConfigLocationclasspath:conf/dispatcherServlet.xml1springmvc*.do【薄情先生|java开发:S S M 整合开发详解】contextConfigLocationclasspath:conf/applicationContext.xmlorg.springframework.web.context.ContextLoaderListenercharacterEncodingFilterorg.springframework.web.filter.CharacterEncodingFilterencodingutf-8forceRequestEncodingtrueforceResponseEncodingtruecharacterEncodingFilter/*7. 实体类package com.md.domain;/** * @author MD * @create 2020-08-13 20:21 */public class Student {private Integer id;private String name;private Integer age;public Student() {}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}@Overridepublic String toString() {return "Student{" +"id=" + id +", name='" + name + '\'' +", age=" + age +'}';}}8. Dao接口和映射文件都在是dao包下 , 且文件名相同
package com.md.dao;import com.md.domain.Student;import java.util.List;/** * @author MD * @create 2020-08-13 20:22 */public interface StudentDao {int insertStudent(Student student);List selectStudents();}StudentDao.xml
insert into student(name,age) values(#{name} , #{age})select id, name , age from student9. Service接口和实现类package com.md.service;import com.md.domain.Student;import java.util.List;/** * @author MD * @create 2020-08-13 20:31 */public interface StudentService {int addStudent(Student student);List findStudents();}


推荐阅读