Java基礎-SSM之Spring和Mybatis以及Spring MVC整合案例html
做者:尹正傑前端
版權聲明:原創做品,謝絕轉載!不然將追究法律責任。java
能看到這篇文章的小夥伴,詳細你已經有必定的Java功能,而且對SSM組件已經有必定的瞭解啦。上次我分享過一篇關於「SSM之Spring和Mybatis整合案例」,此次咱們須要在上次的基礎之上添加前端的支持。本篇博客只是介紹他們的聯合用法,並不涉及具體的業務邏輯。可是咱們能夠經過這個小案例,來嵌套咱們實際生產環境中所須要的處理的業務邏輯喲!mysql
一.開發環境介紹golang
整合SSM使用的是idea開發工具。在進行開發以前,咱們須要準備數據庫測試數據以及在Windows操做系統下安裝WEB服務器(Tomcat)。web
1>.添加數據庫數據spring
1 create database yinzhengjie; 2 3 use yinzhengjie; 4 5 create table if not exists users(id int primary key auto_increment,name varchar(20) , age int) ;
2>.安裝Tomcatsql
安裝Tomcat的過程極爲艱難,直接在網上下載一個安裝便可,固然我這裏的測試版本你們也能夠下載,直接解壓便可完成安裝操做。我已經下載好了Tomcat綠色版(連接:https://pan.baidu.com/s/1_fTB5tX0JMUtErI-s0_Ofg 密碼:bow5)數據庫
二.編寫MVC框架代碼並啓動Tomcat服務器apache
1>.建立模塊,添加web project支持
2>.引入Maven依賴
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <modelVersion>4.0.0</modelVersion> 6 7 <groupId>cn.org.yinzhengjie</groupId> 8 <artifactId>MySSM</artifactId> 9 <version>1.0-SNAPSHOT</version> 10 11 12 <dependencies> 13 <dependency> 14 <groupId>junit</groupId> 15 <artifactId>junit</artifactId> 16 <version>4.11</version> 17 </dependency> 18 <dependency> 19 <groupId>org.springframework</groupId> 20 <artifactId>spring-context-support</artifactId> 21 <version>4.3.5.RELEASE</version> 22 </dependency> 23 <dependency> 24 <groupId>org.springframework</groupId> 25 <artifactId>spring-jdbc</artifactId> 26 <version>4.3.5.RELEASE</version> 27 </dependency> 28 <dependency> 29 <groupId>org.mybatis</groupId> 30 <artifactId>mybatis</artifactId> 31 <version>3.2.1</version> 32 </dependency> 33 <dependency> 34 <groupId>org.mybatis</groupId> 35 <artifactId>mybatis-spring</artifactId> 36 <version>1.3.0</version> 37 </dependency> 38 <dependency> 39 <groupId>c3p0</groupId> 40 <artifactId>c3p0</artifactId> 41 <version>0.9.1.2</version> 42 </dependency> 43 <dependency> 44 <groupId>mysql</groupId> 45 <artifactId>mysql-connector-java</artifactId> 46 <version>5.1.17</version> 47 </dependency> 48 <dependency> 49 <groupId>org.aspectj</groupId> 50 <artifactId>aspectjrt</artifactId> 51 <version>1.6.1</version> 52 </dependency> 53 <dependency> 54 <groupId>org.aspectj</groupId> 55 <artifactId>aspectjweaver</artifactId> 56 <version>1.8.10</version> 57 </dependency> 58 <dependency> 59 <groupId>org.springframework</groupId> 60 <artifactId>spring-webmvc</artifactId> 61 <version>4.3.5.RELEASE</version> 62 </dependency> 63 <dependency> 64 <groupId>javax.servlet</groupId> 65 <artifactId>servlet-api</artifactId> 66 <version>2.5</version> 67 </dependency> 68 <dependency> 69 <groupId>jstl</groupId> 70 <artifactId>jstl</artifactId> 71 <version>1.2</version> 72 </dependency> 73 </dependencies> 74 </project>
3>.編寫代碼
建立包結構以下:
具體代碼以下:
1 /* 2 @author :yinzhengjie 3 Blog:http://www.cnblogs.com/yinzhengjie/tag/Java%E5%9F%BA%E7%A1%80/ 4 EMAIL:y1053419035@qq.com 5 */ 6 package cn.org.yinzhengjie.ssm.dao; 7 8 import java.util.List; 9 10 /** 11 * Basedao,基本dao 12 */ 13 public interface BaseDao<T> { 14 public abstract void insert(T t) ; 15 public abstract void update(T t) ; 16 public abstract void delete(Integer id) ; 17 public abstract T selectOne(Integer id) ; 18 public abstract List<T> selectAll() ; 19 public abstract List<T> selectPage(int offset, int length) ; 20 public abstract int count() ; 21 }
1 /* 2 @author :yinzhengjie 3 Blog:http://www.cnblogs.com/yinzhengjie/tag/Java%E5%9F%BA%E7%A1%80/ 4 EMAIL:y1053419035@qq.com 5 */ 6 package cn.org.yinzhengjie.ssm.dao.impl; 7 8 import cn.org.yinzhengjie.ssm.dao.BaseDao; 9 import cn.org.yinzhengjie.ssm.domain.User; 10 import org.apache.ibatis.session.RowBounds; 11 import org.apache.ibatis.session.SqlSessionFactory; 12 import org.mybatis.spring.support.SqlSessionDaoSupport; 13 import org.springframework.stereotype.Repository; 14 15 import javax.annotation.Resource; 16 import java.util.List; 17 18 @Repository("userDao") 19 public class UserDaoImpl extends SqlSessionDaoSupport implements BaseDao<User> { 20 21 public void insert(User user) { 22 getSqlSession().insert("users.insert" , user) ; 23 } 24 25 public void update(User user) { 26 getSqlSession().update("users.update", user); 27 } 28 29 public void delete(Integer id) { 30 getSqlSession().delete("users.deleteOne", id); 31 } 32 33 public User selectOne(Integer id) { 34 return getSqlSession().selectOne("users.selectOne", id); 35 } 36 public int count() { 37 return getSqlSession().selectOne("users.selectCount"); 38 } 39 40 public List<User> selectAll() { 41 return getSqlSession().selectList("users.selectAll"); 42 } 43 public List<User> selectPage(int offset ,int length) { 44 return getSqlSession().selectList("users.selectPage" , new RowBounds(offset,length)); 45 } 46 47 @Resource(name="sqlSessionFactory") 48 public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) { 49 super.setSqlSessionFactory(sqlSessionFactory); 50 } 51 }
1 /* 2 @author :yinzhengjie 3 Blog:http://www.cnblogs.com/yinzhengjie/tag/Java%E5%9F%BA%E7%A1%80/ 4 EMAIL:y1053419035@qq.com 5 */ 6 package cn.org.yinzhengjie.ssm.domain; 7 8 public class User { 9 private Integer id; 10 private String name; 11 private int age; 12 13 public Integer getId() { 14 return id; 15 } 16 17 public void setId(Integer id) { 18 this.id = id; 19 } 20 21 public String getName() { 22 return name; 23 } 24 25 public void setName(String name) { 26 this.name = name; 27 } 28 29 public int getAge() { 30 return age; 31 } 32 33 public void setAge(int age) { 34 this.age = age; 35 } 36 }
1 /* 2 @author :yinzhengjie 3 Blog:http://www.cnblogs.com/yinzhengjie/tag/Java%E5%9F%BA%E7%A1%80/ 4 EMAIL:y1053419035@qq.com 5 */ 6 package cn.org.yinzhengjie.ssm.service; 7 8 import java.util.List; 9 10 public interface UserService<T> { 11 public abstract void insert(T t); 12 13 public abstract void update(T t); 14 15 public abstract void delete(Integer id); 16 17 public abstract T selectOne(Integer id); 18 public abstract int selectCount(); 19 20 public abstract List<T> selectAll(); 21 public abstract List<T> selectPage(int offset, int length); 22 }
1 /* 2 @author :yinzhengjie 3 Blog:http://www.cnblogs.com/yinzhengjie/tag/Java%E5%9F%BA%E7%A1%80/ 4 EMAIL:y1053419035@qq.com 5 */ 6 package cn.org.yinzhengjie.ssm.service.impl; 7 8 import cn.org.yinzhengjie.ssm.dao.BaseDao; 9 import cn.org.yinzhengjie.ssm.domain.User; 10 import cn.org.yinzhengjie.ssm.service.UserService; 11 import org.springframework.stereotype.Service; 12 13 import javax.annotation.Resource; 14 import java.util.List; 15 16 /** 17 * 用戶服務實現類 18 */ 19 @Service("userService") 20 public class UserServiceImpl implements UserService<User> { 21 22 @Resource(name="userDao") 23 private BaseDao<User> userDao ; 24 25 public void insert(User user) { 26 userDao.insert(user); 27 } 28 29 public void update(User user) { 30 userDao.update(user); 31 } 32 33 public void delete(Integer id) { 34 userDao.delete(id); 35 } 36 37 public User selectOne(Integer id) { 38 return userDao.selectOne(id); 39 } 40 41 public List<User> selectAll() { 42 return userDao.selectAll(); 43 } 44 45 public List<User> selectPage(int offset , int length) { 46 return userDao.selectPage(offset , length); 47 } 48 49 public int selectCount() { 50 return userDao.count(); 51 } 52 }
1 /* 2 @author :yinzhengjie 3 Blog:http://www.cnblogs.com/yinzhengjie/tag/Java%E5%9F%BA%E7%A1%80/ 4 EMAIL:y1053419035@qq.com 5 */ 6 package cn.org.yinzhengjie.ssm.web.controller; 7 8 import cn.org.yinzhengjie.ssm.domain.User; 9 import cn.org.yinzhengjie.ssm.service.UserService; 10 import org.springframework.stereotype.Controller; 11 import org.springframework.web.bind.annotation.RequestMapping; 12 13 import javax.annotation.Resource; 14 15 @Controller 16 @RequestMapping("/home") 17 public class HomeController { 18 19 //注入用戶Service 20 @Resource(name="userService") 21 private UserService us ; 22 23 @RequestMapping("/m1") 24 public String m1(){ 25 System.out.println("m1"); 26 User u = new User(); 27 u.setName("yinzhengjie"); 28 u.setAge(18); 29 us.insert(u); 30 return "index" ; 31 } 32 }
1 /* 2 @author :yinzhengjie 3 Blog:http://www.cnblogs.com/yinzhengjie/tag/Java%E5%9F%BA%E7%A1%80/ 4 EMAIL:y1053419035@qq.com 5 */ 6 package cn.org.yinzhengjie.ssm.web.controller; 7 8 import cn.org.yinzhengjie.ssm.domain.User; 9 import cn.org.yinzhengjie.ssm.service.UserService; 10 import org.springframework.stereotype.Controller; 11 import org.springframework.ui.Model; 12 import org.springframework.web.bind.annotation.RequestMapping; 13 import org.springframework.web.bind.annotation.RequestMethod; 14 import org.springframework.web.bind.annotation.RequestParam; 15 16 import javax.annotation.Resource; 17 import java.util.List; 18 19 @Controller 20 @RequestMapping("/user") 21 public class UserController { 22 23 @Resource(name="userService") 24 private UserService<User> us ; 25 26 27 public String findAll(Model m){ 28 List<User> list = us.selectAll(); 29 m.addAttribute("list" , list) ; 30 return "user/list" ; 31 } 32 33 @RequestMapping("/list") 34 public String page(Model m , @RequestParam(value = "pno" , defaultValue = "1") int pno){ 35 //每頁顯示5條記錄 36 int records = 5 ; 37 38 //總頁數 39 int pages = 1 ; 40 41 //查詢總記錄數 42 int count = us.selectCount() ; 43 44 if(count % records == 0){ 45 pages = count / records ; 46 } 47 else{ 48 pages = count / records + 1; 49 } 50 51 List<User> list = us.selectPage( (pno-1) * records, records) ; 52 53 m.addAttribute("list" ,list) ; 54 m.addAttribute("pages" , pages) ; 55 return "user/list" ; 56 } 57 58 @RequestMapping("/delete") 59 public String delete(Integer uid) { 60 us.delete(uid); 61 return "redirect:/user/list"; 62 } 63 64 @RequestMapping("/toadd") 65 public String toadd(){ 66 return "user/reg" ; 67 } 68 69 @RequestMapping(value = "/doadd" ,method = RequestMethod.POST) 70 public String doAdd(User user){ 71 us.insert(user); 72 return "redirect:/user/list" ; 73 } 74 75 @RequestMapping(value = "/modify" ,method = RequestMethod.GET) 76 public String modify(Model m ,Integer uid){ 77 User u = us.selectOne(uid) ; 78 m.addAttribute("user" , u) ; 79 return "user/edit" ; 80 } 81 82 @RequestMapping(value = "/update" ,method = RequestMethod.POST) 83 public String update(User u){ 84 us.update(u); 85 return "redirect:/user/list" ; 86 } 87 }
4>.編輯Spring和Mybatis配置文件
文件存放路徑以下:
具體代碼以下:
1 <?xml version="1.0"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:aop="http://www.springframework.org/schema/aop" 5 xmlns:context="http://www.springframework.org/schema/context" 6 xmlns:tx="http://www.springframework.org/schema/tx" 7 xsi:schemaLocation="http://www.springframework.org/schema/beans 8 http://www.springframework.org/schema/beans/spring-beans-4.3.xsd 9 http://www.springframework.org/schema/aop 10 http://www.springframework.org/schema/aop/spring-aop-4.3.xsd 11 http://www.springframework.org/schema/context 12 http://www.springframework.org/schema/context/spring-context-4.3.xsd 13 http://www.springframework.org/schema/tx 14 http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"> 15 <context:component-scan base-package="cn.org.yinzhengjie.ssm.service,cn.org.yinzhengjie.ssm.dao" /> 16 <!-- 數據源 --> 17 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> 18 <property name="driverClass" value="com.mysql.jdbc.Driver"/> 19 <property name="jdbcUrl" value="jdbc:mysql://localhost:5200/yinzhengjie"/> 20 <property name="user" value="root"/> 21 <property name="password" value="yinzhengjie"/> 22 <property name="maxPoolSize" value="10"/> 23 <property name="minPoolSize" value="2"/> 24 <property name="initialPoolSize" value="3"/> 25 <property name="acquireIncrement" value="2"/> 26 </bean> 27 28 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 29 <property name="dataSource" ref="dataSource"/> 30 <property name="configLocation" value="classpath:mybatis-config.xml"/> 31 </bean> 32 33 <!-- 事務管理器,在servie層面上實現事務管理的。 --> 34 <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 35 <property name="dataSource" ref="dataSource" /> 36 </bean> 37 38 <!-- 事務通知 --> 39 <tx:advice id="txAdvicd" transaction-manager="txManager"> 40 <tx:attributes> 41 <tx:method name="insert*" propagation="REQUIRED" isolation="DEFAULT" /> 42 <tx:method name="update*" propagation="REQUIRED" isolation="DEFAULT" /> 43 <tx:method name="delete*" propagation="REQUIRED" isolation="DEFAULT" /> 44 <tx:method name="select*" propagation="REQUIRED" isolation="DEFAULT" read-only="true" /> 45 <tx:method name="*" propagation="REQUIRED" isolation="DEFAULT" /> 46 </tx:attributes> 47 </tx:advice> 48 49 <aop:config> 50 <aop:advisor pointcut="execution(* *..*Service.*(..))" advice-ref="txAdvicd" /> 51 </aop:config> 52 </beans>
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 <typeAliases> 7 <typeAlias type="cn.org.yinzhengjie.ssm.domain.User" alias="_User" /> 8 </typeAliases> 9 <mappers> 10 <mapper resource="UserMapper.xml"/> 11 </mappers> 12 </configuration>
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 3 "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 4 <!-- 定義名字空間 --> 5 <mapper namespace="users"> 6 <insert id="insert"> 7 insert into users(name, age) values(#{name}, #{age}) ; 8 </insert> 9 10 <update id="update"> 11 update users set name = #{name} , age = #{age} where id = #{id} 12 </update> 13 14 <delete id="deleteOne"> 15 delete from users where id = #{id} 16 </delete> 17 18 <select id="selectOne" resultType="_User"> 19 select * from users where id = #{id} 20 </select> 21 22 <select id="selectAll" resultType="_User"> 23 select * from users 24 </select> 25 <select id="selectPage" resultType="_User"> 26 select * from users limit #{offset} , #{limit} 27 </select> 28 <select id="selectCount" resultType="int"> 29 select count(*) from users 30 </select> 31 32 </mapper>
5>.配置web文件
配置目錄以下:
具體文件內容以下:
【web/user目錄】
1 <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 <html> 4 <head> 5 <title>UserList</title> 6 </head> 7 <body> 8 </body> 9 <form action='<c:url value="/user/update"/>' method="post"> 10 <input type="hidden" name="id" value='<c:out value="${user.id}"/>'> 11 username : <input type="text" name="name" value='<c:out value="${user.name}"/>'><br> 12 age : <input type="text" name="age" value='<c:out value="${user.age}"/>'><br> 13 <input type="submit" value="提交"> 14 </form> 15 </html>
1 <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 <html> 4 <head> 5 <title>UserList</title> 6 </head> 7 <body> 8 <a href='<c:url value="/user/toadd" />'>添加新用戶</a><br> 9 <table border="1px" cellpadding="0px" cellspacing="0px" 10 style="border-collapse: collapse"> 11 <tr> 12 <td>id</td> 13 <td>name</td> 14 <td>age</td> 15 <td>修改</td> 16 <td>刪除</td> 17 </tr> 18 <c:forEach items="${list}" var="u"> 19 <tr> 20 <td><c:out value="${u.id}" /></td> 21 <td><c:out value="${u.name}" /></td> 22 <td><c:out value="${u.age}" /></td> 23 <td><a href='<c:url value="/user/modify?uid=${u.id}" />'>修改</a></td> 24 <td><a href='<c:url value="/user/delete?uid=${u.id}" />'>刪除</a></td> 25 </tr> 26 </c:forEach> 27 <tr> 28 <td colspan="5" style="text-align: right"> 29 <c:forEach begin="1" end="${pages}" var="i"> 30 <c:if test="${i == param.pno}"> 31 [<c:out value="${i}"/>] 32 </c:if> 33 <c:if test="${i != param.pno}"> 34 <a href='<c:url value="/user/list?pno=${i}" />'><c:out value="${i}"/></a> 35 </c:if> 36 </c:forEach> 37 </td> 38 </tr> 39 40 </table> 41 </body> 42 </html>
1 <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 <html> 4 <head> 5 <title>UserList</title> 6 </head> 7 <body> 8 </body> 9 <form action='<c:url value="/user/doadd"/>' method="post"> 10 username : <input type="text" name="name"><br> 11 age : <input type="text" name="age"><br> 12 <input type="submit" value="提交"> 13 </form> 14 </html>
【web/WEB-INF目錄】
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:mvc="http://www.springframework.org/schema/mvc" 5 xmlns:context="http://www.springframework.org/schema/context" 6 xsi:schemaLocation="http://www.springframework.org/schema/beans 7 http://www.springframework.org/schema/beans/spring-beans.xsd 8 http://www.springframework.org/schema/mvc 9 http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd 10 http://www.springframework.org/schema/context 11 http://www.springframework.org/schema/context/spring-context-4.3.xsd"> 12 <!-- 配置掃描路徑 --> 13 <context:component-scan base-package="cn.org.yinzhengjie.ssm.web.controller"/> 14 <!-- 使用註解驅動 --> 15 <mvc:annotation-driven/> 16 <!-- 內部資源視圖解析器 --> 17 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 18 <property name="prefix" value="/"/> 19 <property name="suffix" value=".jsp"/> 20 </bean> 21 </beans>
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 5 version="3.1"> 6 7 <!-- 經過上下文參數指定配置文件的位置 --> 8 <context-param> 9 <param-name>contextConfigLocation</param-name> 10 <param-value>classpath:beans.xml</param-value> 11 </context-param> 12 13 <!-- 上下文載入器監聽器,確保web服務器啓動時,加載spring的配置到容器中 --> 14 <listener> 15 <listener-class>org.springframework.web.context.ContextLoaderListener 16 </listener-class> 17 </listener> 18 19 <filter> 20 <filter-name>characterEncodingFilter</filter-name> 21 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 22 <init-param> 23 <param-name>encoding</param-name> 24 <param-value>UTF-8</param-value> 25 </init-param> 26 <init-param> 27 <param-name>forceEncoding</param-name> 28 <param-value>true</param-value> 29 </init-param> 30 </filter> 31 <filter-mapping> 32 <filter-name>characterEncodingFilter</filter-name> 33 <url-pattern>/*</url-pattern> 34 </filter-mapping> 35 36 <servlet> 37 <servlet-name>dispatcher</servlet-name> 38 <servlet-class>org.springframework.web.servlet.DispatcherServlet 39 </servlet-class> 40 </servlet> 41 <servlet-mapping> 42 <servlet-name>dispatcher</servlet-name> 43 <url-pattern>/</url-pattern> 44 </servlet-mapping> 45 </web-app>
【web根目錄】
1 <%@ page contentType="text/html;charset=UTF-8" language="java" %> 2 <!DOCTYPE html> <!--Doctype告訴瀏覽器使用什麼樣的html或xhtml規範來解析html文檔。html這種模式兼容瀏覽器是最好的--> 3 <html lang="en"> 4 <head name="尹正傑" age="25"> <!--標籤的開頭,其裏面的內容(name="尹正傑")是標籤的屬性,其屬性能夠定義多個。--> 5 <meta charset="UTF-8"/> <!--指定頁面編碼,咱們稱這種標籤類型爲自閉和標籤,由於咱們須要在標籤的結尾寫上「/」,爲了方便咱們識別標籤類型。--> 6 <meta http-equiv="refresh" content="5; Url=http://www.cnblogs.com/yinzhengjie/"> <!--這是作了一個界面的跳轉,表示30s不運行的話就跳轉到指定的URL--> 7 <title>尹正傑的我的主頁</title> <!--定義頭部(標籤)的標題--> 8 <meta name="keywords" content="開發者,博客園,開發者,程序猿,程序媛,極客,編程,代碼,開源,IT網站,Developer,Programmer,Coder,Geek,技術社區" /> <!--「content」定義關鍵字,其做用就是讓瀏覽器經過搜索關鍵字時,會匹配該網站,這就是說若是你沒有單獨給百度錢的話,這些關鍵字就尤其重要啦!--> 9 <meta name="description" content="博客園是一個面向開發者的知識分享社區。自建立以來,博客園一直致力並專一於爲開發者打造一個純淨的技術交流社區,推進並幫助開發者經過互聯網分享知識,從而讓更多開發者從中受益。博客園的使命是幫助開發者用代碼改變世界。" /> <!--定義描述字符,其做用就告訴客戶你的這個網站是幹嗎使用的。--> 10 <link rel="shortcut icon" href="https://baike.baidu.com/pic/%E9%82%93%E7%B4%AB%E6%A3%8B/6798196/0/d1a20cf431adcbef011db9bba6af2edda3cc9f66?fr=lemma&ct=single#aid=0&pic=d1a20cf431adcbef011db9bba6af2edda3cc9f66" type="image/x-icon" /> <!--定義頭部圖標--> 11 <meta http-equiv="X-UA-Compatible" content="IE=Edge"> <!--這個是IE的瀏覽器生效的規則,若是你用的是谷歌,360等瀏覽器的話,這行規則不生效,若是你用的是IE瀏覽器的話,表示用IE最新的引擎去渲染HTML--> 12 </head> <!--標籤的結尾,結合該標籤的開頭,這種標籤類型咱們稱之爲主動閉合標籤。--> 13 <body> 14 <h1>尹正傑</h1><!--定義文件的內容,其中「h1」標籤中--> 15 <h2>尹正傑</h2> 16 <h3>尹正傑</h3> 17 <h4>尹正傑</h4> 18 <h5>尹正傑</h5> 19 <h6>尹正傑</h6> 20 <h1>You are a good boy!</h1> 21 <div style="width: 4000px"> <!--是其縮進代碼的父級標籤,給其定義寬度屬性是200像素大小--> 22 <h1>尹正傑</h1><!--塊級標籤:也叫父級標籤,即本身單獨佔了一行空間,或者說是佔它父級標籤的100%。做用:定義文件的內容--> 23 <h1>You are a good boy!</h1> 24 </div> <!--div的標籤的結尾--> 25 <p>素胚勾勒出青花筆鋒濃轉淡<br/>瓶身描繪的牡丹一如你初妝<br/>冉冉檀香透過窗心事我瞭然<br/>宣紙上走筆至此擱一半<br/>釉色渲染仕女圖韻味被私藏<br/>而你嫣然的一笑如含苞待放</p> <!--其中<br/>表示換行符的意思,<p></p>表示一個段落的意思。--> 26 <a>yinzhengjie</a> <!--內聯標籤,以a開頭的標籤都是內聯標籤,這些標籤的內容時鏈接在一塊兒的。:--> 27 <a>2017</a> 28 <a href="http://www.cnblogs.com/yinzhengjie/" target="_blank">尹正傑博客</a> <!--a標籤特有的性能,重定向,經過href屬性定義須要跳轉的網站,經過target="_blank"表示新打開一個標籤頁並打開新的URL地址--> 29 30 <a href="#Y1">Golang第一章</a> <!--a標籤特有的性能,作錨,找ID爲"Y1"的標籤並跳轉過去--> 31 <a href="#Y2">Golang第二章</a> <!--找ID爲"Y2"的標籤--> 32 <a href="#Y3">Golang第三章</a> <!--找ID爲"Y3"的標籤--> 33 34 35 36 <div id="Y1" style="height:700px;background-color:antiquewhite"> <!--用id來定義標籤爲"Y1"(通常要具備惟一性,即儘可能不要讓標籤的id的值相同),用style來定義高度爲700像素,顏色用background-color來定義。--> 37 Golang進階之路Day1<br/> 38 Go語言官方自稱,之因此開發Go 語言,是由於「近10年來開發程序之難讓咱們有點沮喪」。 這必定位暗示了Go語言但願取代C和Java的地位,成爲最流行的通用開發語言。博客地址:http://www.cnblogs.com/yinzhengjie/p/6482675.html 39 </div> 40 41 <div id="Y2" style="height:700px;background-color:rebeccapurple;"> 42 <br/>Golang進階之路Day2<br/> 43 前者你們應該都很熟悉,由於我在上一篇(http://www.cnblogs.com/yinzhengjie/p/6482675.html)關於GO的博客中用"go build"命令編譯不一樣的版本,可是在這裏咱們仍是要演示一下go build的花式用法。博客地址:http://www.cnblogs.com/yinzhengjie/p/7000272.html 44 </div> 45 46 <div id="Y3" style="height:700px;background-color:brown;"> 47 Golang進階之路Day3<br/> 48 固然我這裏只是介紹了Golang的冰山一角,對Golang感興趣的小夥伴,能夠看一下Golang官網的文檔說明。畢竟官方纔是最權威的,給出國內地址:https://golang.org/pkg/!博客地址:http://www.cnblogs.com/yinzhengjie/p/7043430.html 49 </div> 50 51 <!--功能最少的標籤,最純潔的易於加工的標籤,即他們沒有「h1」和"a"標籤那麼多的屬性。--> 52 <div>我是塊標籤</div> 53 <span>我是內聯標籤</span> 54 55 <!--列表--> 56 <ul> <!--打印字符穿前面帶個小黑點--> 57 <li>菜單一</li> 58 <li>菜單二</li> 59 <li>菜單三</li> 60 </ul> 61 62 <ol> <!--打印字符串前面有數字標識--> 63 <li>第一章</li> 64 <li>第二章</li> 65 <li>第三章</li> 66 </ol> 67 68 <ol> 69 <dd>北京</dd> <!--自帶縮進,能夠用於寫新聞的標題--> 70 <dt>朝陽區</dt> 71 <dt>亦莊經濟開發區</dt> 72 <dt>豐臺區</dt> 73 <dt>海淀區</dt> 74 <dd>河北</dd> 75 <dt>石家莊</dt> 76 <dt>保定</dt> 77 <dd>陝西</dd> 78 <dt>西安</dt> 79 <dt>安康</dt> 80 </ol> 81 82 83 <!--表格--> 84 <table border="1"> <!--定義一個表格,其屬性是border="1",表示加邊框的意思。--> 85 <thead> <!--定義表頭信息--> 86 <tr> <!--'tr'表示定義一行的數據,裏面的內容由子標籤<th></th>實現--> 87 <th>姓名</th> <!--'th'定義同一行每一列的內容,也就是說只要帶有這個標籤的且在其父標籤"tr"標籤中就是寫的同一行內容。--> 88 <th>年齡</th> 89 <td>性別</td> 90 </tr> 91 </thead> 92 <tbody> <!--定義表格的內容--> 93 <tr> <!--'tr'表示每一行的數據,其定義的是行的操做。--> 94 <td>尹正傑</td> <!--td用來定義當前行的每一列的內容,與thead中的'th'用法相同。只不過'th’有加粗效果!--> 95 <td>25</td> 96 <td>boy</td> 97 </tr> 98 <tr> <!--'tr'表示每一行的數據--> 99 <td>尹正傑</td> <!--‘<td></td>’標籤訂義的是列的操做--> 100 <td colspan="2">26</td> <!--注意,'td'標籤的colspan屬性表示向右佔鋸的空間,咱們給的值是「2」,就表示會從當前列日後在佔一個列,共計當前行的兩列空間!--> 101 </tr> 102 <tr> <!--'tr'表示每一行的數據--> 103 <td>yinzhengjie</td> <!--‘<td></td>’標籤訂義的是列的操做--> 104 <td rowspan="2">26</td> <!--注意,'td'標籤的rowspan屬性表示向下佔據的空間,咱們這裏給的是仍是「2」,即從當前行的當前列,向下擴充空一列內容。--> 105 </tr> 106 <tr> <!--'tr'表示每一行的數據--> 107 <td>yinzhengjie</td> <!--‘<td></td>’標籤訂義的是列的操做--> 108 <td >26</td> <!--表示這個'td'標籤佔兩列的空間--> 109 </tr> 110 </tbody> 111 </table> 112 </body> 113 </html>
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>myhtml.html</title> 6 </head> 7 <body> 8 <table border="1px" cellpadding="0px" cellspacing="0px" style="border-collapse: collapse"> 9 <tr> 10 <td>id</td> 11 <td>name</td> 12 <td>age</td> 13 </tr> 14 <tr> 15 <td>1</td> 16 <td>tom</td> 17 <td>12</td> 18 </tr> 19 <tr> 20 <td>2</td> 21 <td>tomas</td> 22 <td>13</td> 23 </tr> 24 </table> 25 <h1>h1標題</h1> 26 <h2>h2標題</h2> 27 <h3>h3標題</h3> 28 <a href="http://www.baidu.com">百度</a><br> 29 <img src="Koala.gif" width="200px" height="100px"> 30 <input action=""> 31 username : <input type="text" name="user_name"><br> 32 password : <input type="password" name="user_pass"><br> 33 confirm : <input type="password" name="user_confirm"><br> 34 nickname : <input type="text" name="user_nickname"><br> 35 sex : <input type="radio" name="user_sex" value="1">男</input> 36 <input type="radio" name="user_sex" value="0">女</input><br> 37 hobby : <input type="checkbox" name="user_hobby" value="0">足球</input> 38 <input type="checkbox" name="user_hobby" value="1">藍球</input> 39 <input type="checkbox" name="user_hobby" value="2">排球</input><br> 40 民族 : <select multiple="multiple"> 41 <option value="0">漢族</option> 42 <option value="1">滿族</option> 43 <option value="2">回族</option> 44 </select> 45 <br> 46 <textarea></textarea> 47 </form> 48 </body> 49 </html>
koala.gif是一張考拉的圖片,這個你們能夠隨意放一張照片上去,以下:
6>.添加Tomcat服務端插件
7>.修改Tomcat的服務器名稱
8>.添加開發環境(選中項目名稱)
9>.配置Tomcat的相關參數(配置完畢以後須要點擊ok確認喲)
10>.給項目添加依賴庫
點擊OK確認配置成功,以下圖:
11>.啓動Tomcat服務器
啓動成功以後,會自動打開咱們設置的瀏覽器,以下圖:
三.經過Web界面實現增刪改查
因爲個人首頁會在5秒以後進行自動跳轉,所以我們的手速得快,咱們須要切換到指定的路徑中去「/user/list」。
1>.查看數據庫信息
2>.經過web界面網數據庫裏插入數據
添加新用戶
添加測試用戶:
添加數據成功:
3>.刪除數據(咱們用上面的方法多添加一些數據信息)
4>.修改數據
將修改的數據進行提交:
查看數據是否修改爲功: