今天搭建新的項目環境,從網上找了些ssm的搭建步驟,終於找到了一位csdn的大佬,能夠說寫的特別詳細,按照上面步驟搭建便可,爲了方便往後參考,轉載到本人博客,原文連接:https://blog.csdn.net/khxu666/article/details/79851070;javascript
這篇文章主要以idea作參考,沒有的本身破解,其他的工具能夠根據下面步驟下載安裝和使用css
最終完成後的工程結構:
html
下面開始詳細的講解項目的開發過程。java
IDEA+Maven搭建項目骨架
1. 新建Maven項目:
點擊File -> New -> Project -> Maven -> 勾選 Create from archetype -> 選擇 maven-archetype-webapp (注意:此處不要錯選成上面的cocoom-22-archetype-webapp)
mysql
在彈出的new project 選項卡中填寫GroupId和Artifactid,其中GroupID是項目組織惟一的標識符,實際對應JAVA的包的結構,是main目錄裏java的目錄結構,ArtifactID是項目的惟一的標識符,實際對應項目的名稱,就是項目根目錄的名稱。對於入門練習,這兩項能夠隨意填寫。web
以後點擊next 選擇Maven版本(其中IDEA 專業版自帶Maven,也能夠選擇本身下載的maven)。以後填寫項目名稱和項目地址,完成後點擊Finish,完成項目骨架的建立。 spring
2. 在新建的項目中添加所須要的文件/文件夾sql
建立以後的項目如圖所示,咱們須要在這之上新建一些目錄。數據庫
在項目的根目錄下新建target文件夾,系統自動將其設置爲「Excluded」apache
在src/main目錄下新建Directory:「java」,並將其設置爲「Source Root」(即:此項目默認的代碼文件源目錄)
在剛纔新建的java文件下新建「com」包,再在com包下新建四個包,分別命名爲:pojo,service,dao,controller。(若是出現下圖中所示的包名重疊的狀況,能夠點擊圖中所示的圖標,將「Hide empty middle package取消掉」)
上面新建的四個包:pojo,service,dao,controller,其所存放的分別是:
pojo: 存放自定義的java類。如:paper類,user類,book類等,每一個類的屬性設爲private,並提供public屬性的getter/setter方法讓外界訪問
service:定義接口,包含系統所提供的功能。(以後還會在service包下再新建impl包)。
dao:定義接口,包含與數據庫進行交互的功能。
controller:控制器,負責接收頁面請求,轉發和處理。
在resource包下新建Directory:「mapper」(用於存放xxxMapper.xml文件)和「spring」(用於存放spring-xxx.xml配置文件),新建文件:「jdbc.properties」(mysql數據庫配置文件),」log4j.properties」(日誌輸出配置文件),」mybatis-config.xml」(mybatis框架配置文件)。
在web-inf目錄下新建「jsp」包,存放xxx.jsp顯示界面。
補充以後的項目目錄以下圖所示,至此項目骨架搭建完畢,開始寫代碼實現增刪改查功能。
3. 自定義Paper類
在這以前要對項目的pom.xml文件進行配置,在此文件中配置項目所須要的jar包。
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com</groupId> <artifactId>first</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>first Maven Webapp</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <spring.version>5.0.3.RELEASE</spring.version> <mybatis.version>3.4.4</mybatis.version> </properties> <dependencies> <!-- 單元測試 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <!-- 第一部分:Spring 配置--> <!-- Spring core --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${spring.version}</version> </dependency> <!-- Spring DAO --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <!-- Spring mvc --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> </dependency> <!-- 第二部分:Servlet web --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.2</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.9.4</version> </dependency> <!-- 第三部分:數據庫和mybatis --> <!-- 數據庫 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.38</version> </dependency> <!-- 數據庫鏈接池 --> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.5.2</version> </dependency> <!-- MyBatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <!-- mybatis-spring整合包 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.3.1</version> </dependency> <!-- 第四部分:日誌 --> <!-- 實現slf4j接口並整合 --> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.1.1</version> </dependency> </dependencies> <build> <finalName>first</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> </project>
本項目所用的數據庫爲MySQL 5.7 建表語句以下:
SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for `paper` -- ---------------------------- DROP TABLE IF EXISTS `paper`; CREATE TABLE `paper` ( `paper_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'paperID', `name` varchar(100) NOT NULL COMMENT 'paper名稱', `number` int(11) NOT NULL COMMENT 'paper數量', `detail` varchar(200) NOT NULL COMMENT 'paper描述', PRIMARY KEY (`paper_id`) ) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 COMMENT='paper表'; -- ---------------------------- -- Records of paper -- ---------------------------- INSERT INTO `paper` VALUES ('1', '機器學習', '2', 'mlmlmlml'); INSERT INTO `paper` VALUES ('2', '深度學習', '3', 'dldldl'); INSERT INTO `paper` VALUES ('3', '大數據', '4', 'bdbdbd');
下面開始寫java代碼:
package com.pojo; public class Paper { private long paperId; private String paperName; private int paperNum; private String paperDetail; public long getPaperId() { return paperId; } public void setPaperId(long paperId) { this.paperId = paperId; } public String getPaperName() { return paperName; } public void setPaperName(String paperName) { this.paperName = paperName; } public int getPaperNum() { return paperNum; } public void setPaperNum(int paperNum) { this.paperNum = paperNum; } public String getPaperDetail() { return paperDetail; } public void setPaperDetail(String paperDetail) { this.paperDetail = paperDetail; } }
其中getter/setter方法能夠在定義完私有屬性以後使用IDEA提供的快捷鍵:ALT+Insert 來實現快速添加
package com.service; import com.pojo.Paper; import java.util.List; public interface PaperService { int addPaper(Paper paper); int deletePaperById(long id); int updatePaper(Paper paper); Paper queryById(long id); List<Paper> queryAllPaper(); }
package com.service.impl; import com.pojo.Paper; import com.dao.PaperDao; import com.service.PaperService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class PaperServiceImpl implements PaperService { @Autowired private PaperDao paperDao; @Override public int addPaper(Paper paper) { return paperDao.addPaper(paper); } @Override public int deletePaperById(long id) { return paperDao.deletePaperById(id); } @Override public int updatePaper(Paper paper) { return paperDao.updatePaper(paper); } @Override public Paper queryById(long id) { return paperDao.queryById(id); } @Override public List<Paper> queryAllPaper() { return paperDao.queryAllPaper(); } }
package com.dao; import com.pojo.Paper; import java.util.List; public interface PaperDao { int addPaper(Paper paper); int deletePaperById(long id); int updatePaper(Paper paper); Paper queryById(long id); List<Paper> queryAllPaper(); }
package com.controller; import com.pojo.Paper; import com.service.PaperService; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("/paper") public class PaperController { @Autowired private PaperService paperService; @RequestMapping("/allPaper") public String list(Model model) { List<Paper> list = paperService.queryAllPaper(); model.addAttribute("list", list); return "allPaper"; } @RequestMapping("toAddPaper") public String toAddPaper() { return "addPaper"; } @RequestMapping("/addPaper") public String addPaper(Paper paper) { paperService.addPaper(paper); return "redirect:/paper/allPaper"; } @RequestMapping("/del/{paperId}") public String deletePaper(@PathVariable("paperId") Long id) { paperService.deletePaperById(id); return "redirect:/paper/allPaper"; } @RequestMapping("toUpdatePaper") public String toUpdatePaper(Model model, Long id) { model.addAttribute("paper", paperService.queryById(id)); return "updatePaper"; } @RequestMapping("/updatePaper") public String updatePaper(Model model, Paper paper) { paperService.updatePaper(paper); paper = paperService.queryById(paper.getPaperId()); model.addAttribute("paper", paper); return "redirect:/paper/allPaper"; } }
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.dao.PaperDao"> <resultMap type="Paper" id="paperResultMap" > <id property="paperId" column="paper_id"/> <result property="paperName" column="name"/> <result property="paperNum" column="number"/> <result property="paperDetail" column="detail"/> </resultMap> <insert id="addPaper" parameterType="Paper"> INSERT INTO paper(paper_id,name,number,detail) VALUE (#{paperId},#{paperName}, #{paperNum}, #{paperDetail}) </insert> <delete id="deletePaperById" parameterType="long"> DELETE FROM paper WHERE paper_id=#{paperID} </delete> <update id="updatePaper" parameterType="Paper"> UPDATE paper SET NAME = #{paperName},NUMBER = #{paperNum},detail = #{paperDetail} WHERE paper_id = #{paperId} </update> <select id="queryById" resultType="Paper" parameterType="long"> SELECT paper_id,name,number,detail FROM paper WHERE paper_id=#{paperId} </select> <select id="queryAllPaper" resultMap="paperResultMap"> SELECT paper_id,name,number,detail FROM paper </select> </mapper>
spring-dao.xml:(spring-mybatis整合配置文件)
<?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 配置整合mybatis過程 --> <!-- 1.配置數據庫相關參數properties的屬性:${url} --> <context:property-placeholder location="classpath:jdbc.properties"/> <!-- 2.數據庫鏈接池 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <!-- 配置鏈接池屬性 --> <property name="driverClass" value="${jdbc.driver}"/> <property name="jdbcUrl" value="${jdbc.url}"/> <property name="user" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <!-- c3p0鏈接池的私有屬性 --> <property name="maxPoolSize" value="30"/> <property name="minPoolSize" value="10"/> <!-- 關閉鏈接後不自動commit --> <property name="autoCommitOnClose" value="false"/> <!-- 獲取鏈接超時時間 --> <property name="checkoutTimeout" value="10000"/> <!-- 當獲取鏈接失敗重試次數 --> <property name="acquireRetryAttempts" value="2"/> </bean> <!-- 3.配置SqlSessionFactory對象 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 注入數據庫鏈接池 --> <property name="dataSource" ref="dataSource"/> <!-- 配置MyBaties全局配置文件:mybatis-config.xml --> <property name="configLocation" value="classpath:mybatis-config.xml"/> <!-- 掃描pojo包 使用別名 --> <property name="typeAliasesPackage" value="com.pojo"/> <!-- 掃描sql配置文件:mapper須要的xml文件 --> <property name="mapperLocations" value="classpath:mapper/*.xml"/> </bean> <!-- 4.配置掃描Dao接口包,動態實現Dao接口,注入到spring容器中 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!-- 注入sqlSessionFactory --> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> <!-- 給出須要掃描Dao接口包 --> <property name="basePackage" value="com.dao"/> </bean> </beans>
spring-mvc.xml:(spring mvc配置文件)
<?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <!-- 配置SpringMVC --> <!-- 1.開啓SpringMVC註解模式 --> <!-- 簡化配置: (1)自動註冊DefaultAnootationHandlerMapping,AnotationMethodHandlerAdapter (2)提供一些列:數據綁定,數字和日期的format @NumberFormat, @DateTimeFormat, xml,json默認讀寫支持 --> <mvc:annotation-driven /> <!-- 2.靜態資源默認servlet配置 (1)加入對靜態資源的處理:js,gif,png (2)容許使用"/"作總體映射 --> <mvc:default-servlet-handler/> <!-- 3.配置jsp 顯示ViewResolver --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> <!-- 4.掃描web相關的bean --> <context:component-scan base-package="com.controller" /> </beans>
spring-service.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 掃描service包下全部使用註解的類型 --> <context:component-scan base-package="com.service" /> <!-- 配置事務管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!-- 注入數據庫鏈接池 --> <property name="dataSource" ref="dataSource" /> </bean> <!-- 配置基於註解的聲明式事務 --> <tx:annotation-driven transaction-manager="transactionManager" /> </beans>
jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://127.0.0.1:3306/papersystem?useUnicode=true&characterEncoding=utf8 jdbc.username=root jdbc.password=12345678
log4j.rootLogger=ERROR, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 配置全局屬性 --> <settings> <!-- 使用jdbc的getGeneratedKeys獲取數據庫自增主鍵值 --> <setting name="useGeneratedKeys" value="true" /> <!-- 使用列別名替換列名 默認:true --> <setting name="useColumnLabel" value="true" /> <!-- 開啓駝峯命名轉換:Table{create_time} -> Entity{createTime} --> <setting name="mapUnderscoreToCamelCase" value="true" /> </settings> </configuration>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1" metadata-complete="true"> <display-name>Archetype Created Web Application</display-name> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 配置springMVC須要加載的配置文件 spring-dao.xml,spring-service.xml,spring-mvc.xml Mybatis - > spring -> springmvc --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/spring-*.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <!-- 默認匹配全部的請求 --> <url-pattern>/</url-pattern> </servlet-mapping> <filter> <filter-name>encodingFilter</filter-name> <filter-class> org.springframework.web.filter.CharacterEncodingFilter </filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <% pageContext.setAttribute("path", request.getContextPath()); %> <!DOCTYPE HTML> <html> <head> <title>首頁</title> <style type="text/css"> a { text-decoration: none; color: black; font-size: 18px; } h3 { width: 180px; height: 38px; margin: 100px auto; text-align: center; line-height: 38px; background: deepskyblue; border-radius: 4px; } </style> </head> <body> <div class="container"> <div class="row clearfix"> <div class="col-md-12 column"> <div class="page-header"> <h1> 基於SSM框架的管理系統:簡單實現增、刪、改、查。 </h1> </div> </div> </div> </div> <br><br> <h3> <a href="${path }/paper/allPaper">點擊進入管理頁面</a> </h3> </body> </html>
allPaper.jsp:全部論文顯示界面
<%-- Created by IntelliJ IDEA. User: lenovo Date: 2018/4/6 Time: 16:57 To change this template use File | Settings | File Templates. --%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <% String appPath = request.getContextPath(); %> <html> <head> <title>Paper列表</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- 引入 Bootstrap --> <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div class="container"> <div class="row clearfix"> <div class="col-md-12 column"> <div class="page-header"> <h1> 基於SSM框架的管理系統:簡單實現增、刪、改、查。 </h1> </div> </div> </div> <div class="row clearfix"> <div class="col-md-12 column"> <div class="page-header"> <h1> <small>論文列表 —— 顯示全部論文</small> </h1> </div> </div> </div> <div class="row"> <div class="col-md-4 column"> <a class="btn btn-primary" href="${path}/paper/toAddPaper">新增</a> </div> </div> <div class="row clearfix"> <div class="col-md-12 column"> <table class="table table-hover table-striped"> <thead> <tr> <th>論文編號</th> <th>論文名字</th> <th>論文數量</th> <th>論文詳情</th> <th>操做</th> </tr> </thead> <tbody> <c:forEach var="paper" items="${requestScope.get('list')}" varStatus="status"> <tr> <td>${paper.paperId}</td> <td>${paper.paperName}</td> <td>${paper.paperNum}</td> <td>${paper.paperDetail}</td> <td> <a href="${path}/paper/toUpdatePaper?id=${paper.paperId}">更改</a> | <a href="<%=appPath%>/paper/del/${paper.paperId}">刪除</a> </td> </tr> </c:forEach> </tbody> </table> </div> </div> </div>
addPaper,jsp:論文添加頁面
<%-- Created by IntelliJ IDEA. User: lenovo Date: 2018/4/7 Time: 16:45 To change this template use File | Settings | File Templates. --%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <html> <head> <title>新增論文</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- 引入 Bootstrap --> <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div class="container"> <div class="row clearfix"> <div class="col-md-12 column"> <div class="page-header"> <h1> 基於SSM框架的管理系統:簡單實現增、刪、改、查。 </h1> </div> </div> </div> <div class="row clearfix"> <div class="col-md-12 column"> <div class="page-header"> <h1> <small>新增論文</small> </h1> </div> </div> </div> <form action="" name="userForm"> 論文名稱:<input type="text" name="paperName"><br><br><br> 論文數量:<input type="text" name="paperNum"><br><br><br> 論文詳情:<input type="text" name="paperDetail"><br><br><br> <input type="button" value="添加" onclick="addPaper()"> </form> <script type="text/javascript"> function addPaper() { var form = document.forms[0]; form.action = "<%=basePath %>paper/addPaper"; form.method = "post"; form.submit(); } </script> </div>
updatePaper.jsp:論文更改界面
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <html> <head> <title>修改論文</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- 引入 Bootstrap --> <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div class="container"> <div class="row clearfix"> <div class="col-md-12 column"> <div class="page-header"> <h1> 基於SSM框架的管理系統:簡單實現增、刪、改、查。 </h1> </div> </div> </div> <div class="row clearfix"> <div class="col-md-12 column"> <div class="page-header"> <h1> <small>修改論文</small> </h1> </div> </div> </div> <form action="" name="userForm"> <input type="hidden" name="paperId" value="${paper.paperId}"/> 論文名稱:<input type="text" name="paperName" value="${paper.paperName}"/> 論文數量:<input type="text" name="paperNum" value="${paper.paperNum}"/> 論文詳情:<input type="text" name="paperDetail" value="${paper.paperDetail }"/> <input type="button" value="提交" onclick="updatePaper()"/> </form> <script type="text/javascript"> function updatePaper() { var form = document.forms[0]; form.action = "<%=basePath %>paper/updatePaper"; form.method = "post"; form.submit(); } </script> </div>
4. 利用tomcat進行項目部署
選擇default -> tomcat -> local 選擇下載安裝到本地的tomcat服務器的地址
切換到Deployment選項頁 點擊 + 號選擇 Arctifact ,
添加 項目名:war exploded 打包
最後在Application context 中選擇 空白 那一項,點擊 Apply 應用。
5. 運行界面
論文列表界面:
新增論文界面:
論文修改界面:
至此,利用IDEA+Maven+SSM框架實現的簡單的增、刪、改、查功能已經構建完畢!
---------------------
做者:二營長的意大利麪
來源:CSDN
原文:https://blog.csdn.net/khxu666/article/details/79851070
<?xml version="1.0" encoding="UTF-8" ?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <!-- 配置SpringMVC --> <!-- 1.開啓SpringMVC註解模式 --> <!-- 簡化配置: (1)自動註冊DefaultAnootationHandlerMapping,AnotationMethodHandlerAdapter (2)提供一些列:數據綁定,數字和日期的format @NumberFormat, @DateTimeFormat, xml,json默認讀寫支持 --> <mvc:annotation-driven /> <!-- 2.靜態資源默認servlet配置 (1)加入對靜態資源的處理:js,gif,png (2)容許使用"/"作總體映射 --> <mvc:default-servlet-handler/> <!-- 3.配置jsp 顯示ViewResolver --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> <!-- 4.掃描web相關的bean --> <context:component-scan base-package="com.controller" /></beans>--------------------- 做者:二營長的意大利麪 來源:CSDN 原文:https://blog.csdn.net/khxu666/article/details/79851070 版權聲明:本文爲博主原創文章,轉載請附上博文連接!