当前位置:   article > 正文

#极简的SSM小项目:超容易上手(附源码) @FDDLC_基于mvc的项目源码

基于mvc的项目源码

【写完博客后的补充:这里一次性给出全部依赖】

pom.xml的内容:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <groupId>org.example</groupId>
  6. <artifactId>SSM</artifactId>
  7. <version>1.0-SNAPSHOT</version>
  8. <packaging>war</packaging>
  9. <name>SSM Maven Webapp</name>
  10. <!-- FIXME change it to the project's website -->
  11. <url>http://www.example.com</url>
  12. <properties>
  13. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  14. <maven.compiler.source>1.7</maven.compiler.source>
  15. <maven.compiler.target>1.7</maven.compiler.target>
  16. </properties>
  17. <dependencies>
  18. <dependency>
  19. <groupId>org.springframework</groupId>
  20. <artifactId>spring-webmvc</artifactId>
  21. <version>5.1.8.RELEASE</version>
  22. </dependency>
  23. <dependency>
  24. <groupId>junit</groupId>
  25. <artifactId>junit</artifactId>
  26. <version>4.12</version>
  27. <scope>test</scope>
  28. </dependency>
  29. <dependency>
  30. <groupId>org.springframework</groupId>
  31. <artifactId>spring-test</artifactId>
  32. <version>5.1.8.RELEASE</version>
  33. </dependency>
  34. <dependency>
  35. <groupId>mysql</groupId>
  36. <artifactId>mysql-connector-java</artifactId>
  37. <version>8.0.16</version>
  38. </dependency>
  39. <dependency>
  40. <groupId>org.mybatis</groupId>
  41. <artifactId>mybatis</artifactId>
  42. <version>3.4.5</version>
  43. </dependency>
  44. <dependency>
  45. <groupId>org.mybatis</groupId>
  46. <artifactId>mybatis-spring</artifactId>
  47. <version>1.3.1</version>
  48. </dependency>
  49. <dependency>
  50. <groupId>com.mchange</groupId>
  51. <artifactId>c3p0</artifactId>
  52. <version>0.9.5.2</version>
  53. </dependency>
  54. <dependency>
  55. <groupId>org.springframework</groupId>
  56. <artifactId>spring-tx</artifactId>
  57. <version>5.1.8.RELEASE</version>
  58. </dependency>
  59. <dependency>
  60. <groupId>org.springframework</groupId>
  61. <artifactId>spring-jdbc</artifactId>
  62. <version>5.1.8.RELEASE</version>
  63. </dependency>
  64. <dependency>
  65. <groupId>jstl</groupId>
  66. <artifactId>jstl</artifactId>
  67. <version>1.2</version>
  68. </dependency>
  69. <dependency>
  70. <groupId>taglibs</groupId>
  71. <artifactId>standard</artifactId>
  72. <version>1.1.2</version>
  73. </dependency>
  74. </dependencies>
  75. <build>
  76. <finalName>SSM</finalName>
  77. <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
  78. <plugins>
  79. <plugin>
  80. <artifactId>maven-clean-plugin</artifactId>
  81. <version>3.1.0</version>
  82. </plugin>
  83. <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
  84. <plugin>
  85. <artifactId>maven-resources-plugin</artifactId>
  86. <version>3.0.2</version>
  87. </plugin>
  88. <plugin>
  89. <artifactId>maven-compiler-plugin</artifactId>
  90. <version>3.8.0</version>
  91. </plugin>
  92. <plugin>
  93. <artifactId>maven-surefire-plugin</artifactId>
  94. <version>2.22.1</version>
  95. </plugin>
  96. <plugin>
  97. <artifactId>maven-war-plugin</artifactId>
  98. <version>3.2.2</version>
  99. </plugin>
  100. <plugin>
  101. <artifactId>maven-install-plugin</artifactId>
  102. <version>2.5.2</version>
  103. </plugin>
  104. <plugin>
  105. <artifactId>maven-deploy-plugin</artifactId>
  106. <version>2.8.2</version>
  107. </plugin>
  108. </plugins>
  109. </pluginManagement>
  110. </build>
  111. </project>

 

一、创建项目

1、使用Web模板,新建Maven项目:

 

2、导包,即添加Maven依赖:spring-webmvc、junit

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework</groupId>
  4. <artifactId>spring-webmvc</artifactId>
  5. <version>5.1.8.RELEASE</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>junit</groupId>
  9. <artifactId>junit</artifactId>
  10. <version>4.12</version>
  11. <scope>test</scope>
  12. </dependency>
  13. </dependencies>

导包结果:

从上面这张依赖图可以看出,咱们明面上只导了两个包,实际上却有这么多包进来了,其中包括Spring、SpringMVC

 

3、建好项目的结构:在main文件夹下新建java文件夹(要标记为Sources Root)和resources文件夹(要标记为Resources Root),然后在java文件夹下新建csdn.domain、csdn.dao、csdn.service、csdn.controller这几个包,建好后长这样:

 

 

二、搭建Spring的环境

1、在csdn.domain下新建Account类:

  1. package csdn.domain;
  2. public class Account {
  3. private Integer id;
  4. private String name;
  5. private Double money;
  6. public Integer getId() {
  7. return id;
  8. }
  9. public void setId(Integer id) {
  10. this.id = id;
  11. }
  12. public String getName() {
  13. return name;
  14. }
  15. public void setName(String name) {
  16. this.name = name;
  17. }
  18. public Double getMoney() {
  19. return money;
  20. }
  21. public void setMoney(Double money) {
  22. this.money = money;
  23. }
  24. @Override
  25. public String toString() {
  26. return "Account{" +
  27. "id=" + id +
  28. ", name='" + name + '\'' +
  29. ", money=" + money +
  30. '}';
  31. }
  32. }

 

2、在csdn.dao下新建AccountDao接口:

  1. package csdn.dao;
  2. import csdn.domain.Account;
  3. import java.util.List;
  4. public interface AccountDao {
  5. List<Account> findAll();
  6. void save(Account account);
  7. }

 

3、在csdn.dao下新建impl子包,再在impl子包下新建AccountDaoImpl类(两步可合并为一步,即直接在csdn.dao下新建impl.AccountDaoImpl类;后面也有类似的操作,不再赘述!):

  1. package csdn.dao.impl;
  2. import csdn.dao.AccountDao;
  3. import csdn.domain.Account;
  4. import org.springframework.stereotype.Repository;
  5. import java.util.List;
  6. @Repository("accountDao")
  7. public class AccountDaoImpl implements AccountDao {
  8. @Override
  9. public List<Account> findAll() {
  10. System.out.println("AccountDao实现类中的findAll方法到此一游~");
  11. return null;
  12. }
  13. @Override
  14. public void save(Account account) {
  15. System.out.println("AccountDao实现类中的save方法到此一游~");
  16. }
  17. }

 

4、在csdn.service下新建AccountService接口:

  1. package csdn.service;
  2. import csdn.domain.Account;
  3. import java.util.List;
  4. public interface AccountService {
  5. List<Account> findAll();
  6. void save(Account account);
  7. }

 

5、在csdn.service下新建impl子包,再在impl子包下新建AccountServiceImpl类:

  1. package csdn.service.impl;
  2. import csdn.dao.AccountDao;
  3. import csdn.domain.Account;
  4. import csdn.service.AccountService;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Service;
  7. import java.util.List;
  8. @Service("accountService")
  9. public class AccountServiceImpl implements AccountService {
  10. @Autowired
  11. private AccountDao accountDao;
  12. @Override
  13. public List<Account> findAll() {
  14. accountDao.findAll();
  15. System.out.println("我是AccountService实现类,我刚刚调用了dao~");
  16. return null;
  17. }
  18. @Override
  19. public void save(Account account) {
  20. accountDao.save(account);
  21. System.out.println("我是AccountService实现类,我刚刚调用了dao~");
  22. }
  23. }

 

6、在resources下新建spring.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
  6. <context:component-scan base-package="csdn">
  7. <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  8. </context:component-scan>
  9. </beans>

 

7.1、在main文件夹下新建test文件夹,并标记为Test Sources Root:

7.2、在pom.xml中新增spring-test依赖(开头有完整版pom.xml)

 

7.3、在test文件夹下新建SpringTest类:

  1. import csdn.domain.Account;
  2. import csdn.service.AccountService;
  3. import org.junit.Test;
  4. import org.junit.runner.RunWith;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.test.context.ContextConfiguration;
  7. import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  8. @ContextConfiguration(locations = "classpath:spring.xml")
  9. @RunWith(SpringJUnit4ClassRunner.class)
  10. public class SpringTest {
  11. @Autowired
  12. private AccountService accountService;
  13. @Test
  14. public void test() {
  15. accountService.findAll();
  16. //accountService.save(new Account());
  17. }
  18. }

经测试,Spring没毛病!

 

三、搭建SpringMVC的环境

1、在webapp下新建css、js、image文件夹,在WEB-INF下新建pages文件夹:

2、在resources下新建springmvc.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
  6. <context:component-scan base-package="csdn">
  7. <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  8. </context:component-scan>
  9. <mvc:annotation-driven />
  10. <mvc:resources mapping="/css/**" location="/css/" />
  11. <mvc:resources mapping="/js/**" location="/js/" />
  12. <mvc:resources mapping="/image/**" location="/image/" />
  13. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver">
  14. <property name="prefix" value="/WEB-INF/pages/" />
  15. <property name="suffix" value=".jsp" />
  16. </bean>
  17. </beans>

3、修改web.xml:

  1. <!DOCTYPE web-app PUBLIC
  2. "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  3. "http://java.sun.com/dtd/web-app_2_3.dtd" >
  4. <web-app>
  5. <display-name>Archetype Created Web Application</display-name>
  6. <filter>
  7. <filter-name>characterEncodingFilter</filter-name>
  8. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  9. </filter>
  10. <filter-mapping>
  11. <filter-name>characterEncodingFilter</filter-name>
  12. <url-pattern>/*</url-pattern>
  13. </filter-mapping>
  14. <servlet>
  15. <servlet-name>dispatcherServlet</servlet-name>
  16. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  17. <init-param>
  18. <param-name>contextConfigLocation</param-name>
  19. <param-value>classpath:springmvc.xml</param-value>
  20. </init-param>
  21. <load-on-startup>1</load-on-startup>
  22. </servlet>
  23. <servlet-mapping>
  24. <servlet-name>dispatcherServlet</servlet-name>
  25. <url-pattern>/</url-pattern>
  26. </servlet-mapping>
  27. </web-app>

 

4、删除index.jsp,再新建index.jsp:

  1. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  2. <html>
  3. <head>
  4. <title>Title</title>
  5. </head>
  6. <body>
  7. <h3><a href="hello">toHello</a></h3>
  8. </body>
  9. </html>

5、在pages下新建hello.jsp:

  1. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  2. <html>
  3. <head>
  4. <title>Title</title>
  5. </head>
  6. <body>
  7. <h3>hello</h3>
  8. </body>
  9. </html>

6、在controller包下新建HelloController类:

  1. package csdn.controller;
  2. import org.springframework.stereotype.Controller;
  3. import org.springframework.web.bind.annotation.RequestMapping;
  4. @Controller
  5. public class HelloController {
  6. @RequestMapping("/hello")
  7. public String hello() {
  8. return "hello";
  9. }
  10. }

7、添加Tomcat,并关联项目:

 

8、启动Web项目,经测试,SpringMVC没毛病!

 

四、Spring与SpringMVC的整合

1、修改web.xml:

  1. <!DOCTYPE web-app PUBLIC
  2. "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  3. "http://java.sun.com/dtd/web-app_2_3.dtd" >
  4. <web-app>
  5. <display-name>Archetype Created Web Application</display-name>
  6. <context-param>
  7. <param-name>contextConfigLocation</param-name>
  8. <param-value>classpath:spring.xml</param-value>
  9. </context-param>
  10. <filter>
  11. <filter-name>characterEncodingFilter</filter-name>
  12. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  13. </filter>
  14. <filter-mapping>
  15. <filter-name>characterEncodingFilter</filter-name>
  16. <url-pattern>/*</url-pattern>
  17. </filter-mapping>
  18. <listener>
  19. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  20. </listener>
  21. <servlet>
  22. <servlet-name>dispatcherServlet</servlet-name>
  23. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  24. <init-param>
  25. <param-name>contextConfigLocation</param-name>
  26. <param-value>classpath:springmvc.xml</param-value>
  27. </init-param>
  28. <load-on-startup>1</load-on-startup>
  29. </servlet>
  30. <servlet-mapping>
  31. <servlet-name>dispatcherServlet</servlet-name>
  32. <url-pattern>/</url-pattern>
  33. </servlet-mapping>
  34. </web-app>

2、修改HelloController:

  1. package csdn.controller;
  2. import csdn.service.AccountService;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.stereotype.Controller;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. @Controller
  7. public class HelloController {
  8. @Autowired
  9. private AccountService accountService;
  10. @RequestMapping("/hello")
  11. public String hello() {
  12. accountService.findAll();
  13. System.out.println("我是HelloController,我刚刚调用了accountService~");
  14. return "hello";
  15. }
  16. }

3、重启Tomcat,点击超链接,页面成功跳转,控制台输出:

Spring和SpringMVC整合成功!

 

五、搭建MyBatis的环境

1、增加Maven依赖:mysql-connector-java、mybatis(开头有完整版pom.xml)

2、准备好数据库,新建account表(id,name,money),填充若干条记录。

database:test        port:3306        table:account

 

3、编写account表对应的实体类Account(前面已有)。

4、编写AccountDao接口(前面已有)。

5、在resources下新建csdn文件夹,再在csdn文件下新建dao文件夹,编写AccountDao.xml:

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="csdn.dao.AccountDao">
  6. <select id="findAll" resultType="csdn.domain.Account">
  7. select * from account
  8. </select>
  9. <insert id="save" parameterType="csdn.domain.Account">
  10. insert into account (name, money) values (#{name}, #{money})
  11. </insert>
  12. </mapper>

6、在resources下新建mybatis.xml:

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE configuration
  3. PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-config.dtd">
  5. <configuration>
  6. <environments default="mysql">
  7. <environment id="mysql">
  8. <transactionManager type="JDBC"></transactionManager>
  9. <dataSource type="POOLED">
  10. <property name="driver" value="com.mysql.cj.jdbc.Driver"/>
  11. <property name="url" value="jdbc:mysql://localhost:3306/Test?characterEncoding=UTF8&amp;serverTimezone=Asia/Shanghai"/>
  12. <property name="username" value="root"/>
  13. <property name="password" value="root"/>
  14. </dataSource>
  15. </environment>
  16. </environments>
  17. <mappers>
  18. <mapper resource="csdn/dao/AccountDao.xml" />
  19. </mappers>
  20. </configuration>

7、在test文件夹下新建MyBatisTest类:

  1. import csdn.dao.AccountDao;
  2. import csdn.domain.Account;
  3. import org.apache.ibatis.io.Resources;
  4. import org.apache.ibatis.session.SqlSession;
  5. import org.apache.ibatis.session.SqlSessionFactory;
  6. import org.apache.ibatis.session.SqlSessionFactoryBuilder;
  7. import org.junit.Test;
  8. import java.io.InputStream;
  9. import java.util.List;
  10. public class MyBatisTest {
  11. @Test
  12. public void test() throws Exception {
  13. InputStream in = Resources.getResourceAsStream("mybatis.xml");
  14. SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
  15. SqlSessionFactory factory = builder.build(in);
  16. SqlSession session = factory.openSession(true);
  17. AccountDao accountDao = session.getMapper(AccountDao.class);
  18. List<Account> accounts = accountDao.findAll();
  19. for(Account account: accounts) {
  20. System.out.println(account);
  21. }
  22. session.close();
  23. in.close();
  24. }
  25. }

经测试,MyBatis没毛病!

 

六、整合Spring和MyBatis

1、增加Maven依赖:mybatis-spring、c3p0、spring-tx、spring-jdbc(开头有完整版pom.xml)

2、修改spring.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
  6. <context:component-scan base-package="csdn">
  7. <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
  8. </context:component-scan>
  9. <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  10. <property name="driverClass" value="com.mysql.cj.jdbc.Driver"></property>
  11. <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test?characterEncoding=UTF8&amp;serverTimezone=Asia/Shanghai"></property>
  12. <property name="user" value="root"></property>
  13. <property name="password" value="root"></property>
  14. </bean>
  15. <bean class="org.mybatis.spring.SqlSessionFactoryBean" id="sqlSessionFactory">
  16. <property name="dataSource" ref="dataSource" />
  17. </bean>
  18. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" id="mapperScannerConfigurer">
  19. <property name="basePackage" value="csdn.dao" />
  20. </bean>
  21. </beans>

 

3、修改AccountDao接口:

  1. package csdn.dao;
  2. import csdn.domain.Account;
  3. import org.springframework.stereotype.Repository;
  4. import java.util.List;
  5. @Repository("accountDaoProxy")
  6. public interface AccountDao {
  7. List<Account> findAll();
  8. void save(Account account);
  9. }

 

4、在test文件夹下新建SpringAndMyBatisTest类:

  1. import csdn.dao.AccountDao;
  2. import csdn.domain.Account;
  3. import org.junit.Test;
  4. import org.springframework.context.ApplicationContext;
  5. import org.springframework.context.support.ClassPathXmlApplicationContext;
  6. import java.util.List;
  7. public class SpringAndMyBatisTest {
  8. @Test
  9. public void test() {
  10. ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
  11. AccountDao accountDao = context.getBean("accountDaoProxy", AccountDao.class);
  12. List<Account> accounts = accountDao.findAll();
  13. for (Account account : accounts) {
  14. System.out.println(account);
  15. }
  16. }
  17. }

经测试,没毛病!

 

七、Spring、SpringMVC、MyBatis三体合一

1、导入依赖:jstl、standard(开头有完整版pom.xml)

2、修改AccountServiceImpl类:

  1. package csdn.service.impl;
  2. import csdn.dao.AccountDao;
  3. import csdn.domain.Account;
  4. import csdn.service.AccountService;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.beans.factory.annotation.Qualifier;
  7. import org.springframework.stereotype.Service;
  8. import java.util.List;
  9. @Service("accountService")
  10. public class AccountServiceImpl implements AccountService {
  11. @Autowired
  12. @Qualifier("accountDaoProxy")
  13. private AccountDao accountDao;
  14. @Override
  15. public List<Account> findAll() {
  16. return accountDao.findAll();
  17. }
  18. @Override
  19. public void save(Account account) {
  20. accountDao.save(account);
  21. }
  22. }

3、修改index.jsp:

  1. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  2. <html>
  3. <head>
  4. <title>Title</title>
  5. </head>
  6. <body>
  7. <h3><a href="hello">toHello</a></h3>
  8. <form method="post" action="save">
  9. name: <input type="text" name="name" /><br />
  10. money: <input type="text" name="money" /><br />
  11. <input type="submit" value="提交" />
  12. </form>
  13. </body>
  14. </html>

4、修改HelloController类:

  1. package csdn.controller;
  2. import csdn.domain.Account;
  3. import csdn.service.AccountService;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Controller;
  6. import org.springframework.ui.Model;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.servlet.ModelAndView;
  9. import java.util.List;
  10. @Controller
  11. public class HelloController {
  12. @Autowired
  13. private AccountService accountService;
  14. @RequestMapping("/hello")
  15. public String hello(Model model) {
  16. List<Account> accounts = accountService.findAll();
  17. model.addAttribute("accounts", accounts);
  18. return "hello";
  19. }
  20. @RequestMapping("/save")
  21. public String save(Account account) {
  22. accountService.save(account);
  23. return "forward:/hello"; //会请求上一个方法,hello方法
  24. }
  25. }

5、修改hello.jsp:

  1. <%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
  2. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  3. <html>
  4. <head>
  5. <title>Title</title>
  6. </head>
  7. <body>
  8. <c:forEach items="${accounts}" var="account">
  9. <c:out value="${account.id}" />
  10. <c:out value="${account.name}" />
  11. <c:out value="${account.money}" />
  12. <br /><br />
  13. </c:forEach>
  14. </body>
  15. </html>

测试结果:

至此,SSM整合成功!

 

 

 


测试环境:IDEA 2020.2、MySQL 8.0.16

 

项目结构:

 

 

源码链接: https://pan.baidu.com/s/1jFvIhmCiy-tXhNDG3b_dlg    提取码: z8nb

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/153622
推荐阅读
相关标签
  

闽ICP备14008679号