11.配置自动代理
***************************************************详细步骤**************************************************************
首先需要搭建一个动态web项目 大致步骤如下
项目结构如下
****************************************************项目代码************************************************************
register.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
注册页面
package cn.liujd.bean;
import java.io.Serializable;
/**
* 普通的学生bean类
* @author liujd
*
*/
public class Student implements Serializable{
private static final long serialVersionUID = 6724577147867445725L;
private Integer id;
private String name;
private Integer age;
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 == null ? null : name.trim();
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
@Override
public String toString() {
return "Student [id=" + id + ", name=" + name + ", age=" + age + "]";
}
}
package cn.liujd.dao;
import cn.liujd.bean.Student;
/**
* dao层接口 与数据库交互
* @author liujd
*
*/
public interface StudentMapper {
//保存学生信息的方法
int saveStudent(Student student);
}
id, name, age
insert into student
name,
age,
#{name,jdbcType=VARCHAR},
#{age,jdbcType=INTEGER},
package cn.liujd.service;
import cn.liujd.bean.Student;
/**
* service层接口
* @author liujd
*
*/
public interface IStudentService {
//保存学生对象的方法
int savaStudent(Student student);
}
package cn.liujd.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.liujd.bean.Student;
import cn.liujd.dao.StudentMapper;
/**
* service层实现类
* @author liujd
*
*/
@Service
public class StudentServiceImpl implements IStudentService{
@Autowired
private StudentMapper mapper;
@Override
public int savaStudent(Student student) {
return mapper.saveStudent(student);
}
}
StudentController.java
package cn.liujd.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import cn.liujd.bean.Student;
import cn.liujd.service.IStudentService;
/**
* web层
* @author liujd
*
*/
@Controller
public class StudentController {
@Autowired
private IStudentService service;
//存到数据库
@RequestMapping("regist.do")
public String regist(Student student) {
if(student != null) {
service.savaStudent(student);
}
return "register";
}
//用来跳转到注册页面
@RequestMapping("/register")
public String init(){
return "register";
}
}
db.properties
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/test
use=xxx
password=xxx
ssmCombine
index.html
ssm
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring.xml
1
ssm
/
CharacterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
forceEncoding
true
CharacterEncodingFilter
/*
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath:spring.xml
spring.xml
${driver}
${url}
${use}
${password}
80
20
3000
mybatis-config.xml
运行结果:
该项目的源代码以打包,下载地址为http://download.csdn.net/detail/liujiding/9901555