xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-4.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd" >
或数据库采用外部文件,配置文件中配置数据源改为下面内容:
jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver jdbc.url=jdbc:sqlserver://127.0.0.1:1433;databaseName=数据库名 jdbc.username=sa jdbc.password=密码
3、controller文件内容
@Controller
public class HelloController {
@Autowired
private HelloService piaoService;
@RequestMapping("/findAll")
public String findAll(Model model) {
List lists = piaoService.selectAll();
model.addAttribute("Piaos", lists);
return "success";
}
4、server代码内容
@Service
@Transactional
public class HelloService {
@Autowired
private PiaoDao piaoDao;
public List selectAll(){
return piaoDao.findAll();
}
5、MyAnnotation文件内容
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
}
6、dao层代码内容
import java.util.List;
import com.cc.annotation.MyAnnotation;
import com.cc.entity.Piao;
@MyAnnotation
public interface PiaoDao {
List findAll();
}
7、mapper映射文件
8、jsp文件内容
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>Insert title here
| ${piao.name } | ${piao.leibie } |
最后web.xml配置内容为
ssm_01
dispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:applicationContext.xml
1
dispatcherServlet
/
encodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
encodingFilter
/*
lib的包
最后,以上ssm的整合只是自己写的一个记录,如有bug请多多包涵!!



