<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>您好Springboot</title> <!-- 1.導入函數類庫 --> <script src="../js/jquery-3.4.1.min.js"></script> <script type="text/javascript"> //讓JS頁面加載完成,以後執行JS $(function(){ /* 需求: 利用ajax方式動態獲取user數據信息 請求網址: /findAjax 知識點: 返回值類型: 能夠根據數據自動匹配類型,因此能夠不寫. 1. $.get(url地址,傳遞的參數,回調函數,返回值類型) 2. $.post(.....) 3. $.getJSON(.....) */ $.get("/findAjax2",function(result){ //1.能夠使用js中的for循環 /* for(let i=0; i<result.length;i++){ } */ /* for(let index in result){ console.log(index); } */ for(let user of result){ let id = user.id; let name = user.name; let age = user.age; let sex = user.sex; let tr = "<tr align='center'><td>"+id+"</td><td>"+name+"</td><td>"+age+"</td><td>"+sex+"</td></tr>" $("#tab1").append(tr); } }) /* 原生ajax寫法 $.ajax變形 jQuery的編程特色: 函數式編程 需求:傳遞Id=100,name=喵 參數寫法1:data : {"id":100,"name":"喵"} 參數寫法2:data: "id=100&name=喵", */ $.ajax({ url : "/findAjax", type : "get", //method: "post" //data : {"id":100,"name":"喵"} data: "id=100&name=喵", success: function(result){ for(let user of result){ let id = user.id; let name = user.name; let age = user.age; let sex = user.sex; let tr = "<tr align='center'><td>"+id+"</td><td>"+name+"</td><td>"+age+"</td><td>"+sex+"</td></tr>" $("#tab1").append(tr); } }, error: function(result){ alert("請求失敗,請聯繫管理員!!!") }, cache: false, //默認值 true async: false //默認值 true 異步操做 false同步操做 }); }) </script> </head> <body> <table id="tab1" border="1px" width="65%" align="center"> <tr> <td colspan="6" align="center"><h3>學生信息</h3></td> </tr> <tr> <th>編號</th> <th>姓名</th> <th>年齡</th> <th>性別</th> </tr> </table> </body> </html>
一、建立父級工程jt(pom.xml)javascript
<?xml version="1.0" encoding="UTF-8"?> <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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.jt</groupId> <artifactId>jt2007</artifactId> <version>1.0-SNAPSHOT</version> <!--1.設定打包方式 爲聚合工程--> <packaging>pom</packaging> <!--2.統一管理jar包--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <java.version>1.8</java.version> <skipTests>true</skipTests> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> <!--spring整合mybatis-plus --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.2.0</version> </dependency> <!--springBoot整合JSP添加依賴 --> <!--servlet依賴 --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> </dependency> <!--jstl依賴 --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <!--使jsp頁面生效 --> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency> <!--添加httpClient jar包 --> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> </dependency> <!--引入dubbo配置 --> <!--<dependency> <groupId>com.alibaba.boot</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>0.2.0</version> </dependency>--> <!--添加Quartz的支持 --> <!--<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-quartz</artifactId> </dependency>--> <!-- 引入aop支持 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <!--spring整合redis --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> </dependency> </dependencies> <!-- 注意事項: 聚合工程自己不須要發佈,因此不要添加 build標籤 --> </project>
2.建立工具API jt-common(是jt的子項目--pom.xml--導入課前資料)html
<?xml version="1.0" encoding="UTF-8"?> <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/xsd/maven-4.0.0.xsd"> <parent> <artifactId>jt2007</artifactId> <groupId>com.jt</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>jt-common</artifactId> </project>
3.建立jt-manage項目(是jt的子項目--pom.xml--導入課前資料)【打包方式: war包】java
<?xml version="1.0" encoding="UTF-8"?> <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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>jt-manage</artifactId> <!--1.web項目打成war包--> <packaging>war</packaging> <!--2.繼承父級項目--> <parent> <artifactId>jt2007</artifactId> <groupId>com.jt</groupId> <version>1.0-SNAPSHOT</version> </parent> <!--3.依賴工具API--> <dependencies> <dependency> <groupId>com.jt</groupId> <artifactId>jt-common</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> <!--4.添加maven插件--> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
ymlmysql
server: port: 8091 servlet: context-path: / spring: datasource: #引入druid數據源 # type: com.alibaba.druid.pool.DruidDataSource # driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/jtdb?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true username: root password: 123456 mvc: view: prefix: /WEB-INF/views/ suffix: .jsp #mybatis-plush配置 mybatis-plus: type-aliases-package: com.jt.pojo mapper-locations: classpath:/mybatis/mappers/*.xml configuration: map-underscore-to-camel-case: true logging: level: com.jt.mapper: debug
1)### 修改啓動項
說明: SpringBoot項目中若是用戶採用缺省值訪問時,則SpringBoot會採用模板工具API進行頁面跳轉. 若是使用模板工具API則會動態的拼接視圖解析器的前綴和後綴
eg:
前綴: /WEB-INF/views/
後綴 .jsp
默認系統歡迎頁面的全路徑: /WEB-INF/views/index.jspjquery
1.京淘後端頁面佈局說明(樹形結構)
程序員
2.通用頁面跳轉實現web
package com.jt.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller public class IndexController { /*@RequestMapping("/index") public String index(){ return "index"; }*/ /** * 需求:實現通用頁面跳轉 * url: /page/item-add 頁面:item-add.jsp * url: /page/item-list 頁面:item-list.jsp * 結論: url中的地址就是跳轉的頁面信息. * * restFul風格實現1: * 做用: 能夠動態的接收url中的參數 * 語法: * 1.url中的地址若是是參數,則須要使用/分割 * 2.controller方法接收參數時,須要使用{}號方式獲取 * 3.若是須要獲取參數信息,則使用特定的註解標識 * * restFul風格實現2: 須要指定訪問的請求類型,而且根據特定的類型執行業務 * 請求類型: * 1.get 執行查詢操做 * 2.post 執行入庫操做 * 3.put 執行更新操做 * 4.delete 執行刪除操做 */ //@RequestMapping(value = "/page/{moduleName}",method = RequestMethod.GET) @GetMapping("/page/{moduleName}") public String module(@PathVariable String moduleName){ return moduleName; } }
3.UI框架-表格數據展示說明(核心: JS中須要什麼數據,則後端程序員就封裝什麼數據!!)
1)### 常見縮寫介紹ajax
1. POJO 與數據庫映射的實體類對象 2. VO : 數據展示層的對象 主要與頁面JS進行數據交互的媒介
2)### EasyUI表格定義redis
<div> 定義表格,而且經過url訪問json數據, fitColumns:true表示自動適應,singleSelect:true 表示選中單個 <table class="easyui-datagrid" style="width:500px;height:300px" data-options="url:'datagrid_data.json',method:'get', fitColumns:true,singleSelect:false,pagination:true"> <thead> <tr> <th data-options="field:'code',width:100">Code</th> <th data-options="field:'name',width:100">Name</th> <th data-options="field:'price',width:100,align:'right'">Price</th> </tr> </thead> </table> </div>
3)### 表格數據返回格式說明spring
{ "total":2000, "rows":[ {"code":"A","name":"果汁","price":"20"}, {"code":"B","name":"漢堡","price":"30"}, {"code":"C","name":"雞柳","price":"40"}, {"code":"D","name":"可樂","price":"50"}, {"code":"E","name":"薯條","price":"10"}, {"code":"F","name":"麥旋風","price":"20"}, {"code":"G","name":"套餐","price":"100"} ] }
4)### 根據返回值 定義VO對象
5)JSON結構說明
JSON概述: JSON(JavaScript Object Notation) 是一種輕量級的數據交換格式。 JSON格式之對象格式 eg: {「id」:「100」,「name」:「tomcat貓」} JSON格式之數組格式 eg: [「1」,「玩」,「學習」] JSON格式之嵌套格式 ["敲代碼","打遊戲",[1,2,3,4,5],{"id":100,"name":"tomcat貓","hobby":["吃東西","打豆豆","玩聯盟"]}]