springboot怎么設置多個路徑全部跳轉首頁_SpringBoot(四)—Web開發(二)

這篇文章準備來記錄一下一個restful風格小項目的流程,上篇文章為它做了一個基礎,如果有什么錯誤希望大家能夠指出。

目錄

  • 首頁
  • 國際化
  • 登錄
  • 攔截器
  • CRUD

一、首頁

  1. 在訪問localhost:8080/的時候,默認訪問首頁
  • 在自己配置的SpringMVC的配置類中
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {@Bean//將這個組件注冊到容器中public WebMvcConfigurer webMvcConfigurer(){WebMvcConfigurer webMvcConfigurer = new WebMvcConfigurer() {@Overridepublic void addViewControllers(ViewControllerRegistry registry) {registry.addViewController("/").setViewName("login");registry.addViewController("/login.html").setViewName("login");}};return webMvcConfigurer;}
}

二、國際化

  1. 步驟
  • 編寫國際化配置文件,抽取頁面需要顯示的國際化消息

目錄結構

login.properties代表默認的;下面的兩個分別代表英文和中文的

c1b66aec596c40a057486616a277c385.png

在編寫頁面需要的國際化消息時,可以點擊任意的一個properties文件,然后切換到Resource Bundle視圖,然后使用+進行每個消息的編寫

49c140bb133d89ec4ce6a0795aa72401.png
  • 使用ResourceBundleMessageSource管理國際化資源文件

如果是在SpringMVC中使用的時候,需要我們自己去編寫;但是在SpringBoot中是給自動配置好了的

我們在編寫的時候是在resourses目錄下的i18n文件夾下寫了配置文件,但是在觀察源碼發現他表示配置文件是放在類路徑下的message.properties中,所以我們需要在application.propertis中去修改一下

95a20aa2c11caeeb5cb7d4b7c284e133.png

fd502cefb74e7f539e0a4c0fff2fd650.png
  • 去頁面獲取國際化的值

35f3d3858cfdd89d899b19d54b32799f.png

效果:根據瀏覽器語言設置的信息切換了國際化;

2. 用按鈕去實現切換國際化

  • 原理

國際化Locale(區域信息對象);LocaleResolver(獲取區域信息對象);

1d54c7f8521f16d5c05c70d5cc53fa59.png
  • 步驟

在頁面上添加超鏈接

60b8b4325efc7017d1b38f2a18205460.png

編寫自定義的LocaleResolver

public class MyLocalResolver implements LocaleResolver {@Overridepublic Locale resolveLocale(HttpServletRequest httpServletRequest) {String l = httpServletRequest.getParameter("l");//使用默認的Locale locale = Locale.getDefault();if(!StringUtils.isEmpty(l)){String[] s = l.split("_");locale = new Locale("s[0]","s[1]");}return locale;}@Overridepublic void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {}
}

在MyMvcConfig中將我們自己編寫的LocaleResolver添加到容器中;

@Bean
public LocaleResolver localeResolver(){return new MyLocalResolver();
}

三、登錄

1.不連接數據庫,只要用戶名不為空和密碼等于123456就可以成功登錄并且跳轉到首頁

@Controller
public class LoginController {//可以使用Restful風格的注解// @RequestMapping(value = "/user/login",method = RequestMethod.POST)@PostMapping(value="/user/login")public String login(@RequestParam("username") String username,@RequestParam("password") String password, Map<String,Object> map){if(!StringUtils.isEmpty(username) && "123456".equals(password)){//登錄成功,為了防止表單重復提交,將重定向到dashboardreturn "redirect:/main.html";}else{//登錄失敗map.put("msg","用戶名密碼錯誤");}return "login";}
}

2. 開發期間模板引擎頁面修改以后,為了保證他能實時生效,需要執行以下步驟:

  • 禁用模板引擎的緩存
#禁用模板引擎的緩存
spring.thymeleaf.cache=false
  • idea中用Ctrl+f9:重新編譯

3. 登錄錯誤信息的顯示

<p th:text="${msg}" th:if="${not #strings.isEmpty(msg)}"></p>

4. 為了防止表單重復提交,將重定向進首頁,所以在自己的MvcConfig配置類中再添加一個視圖渲染;但是我們在設置了這個之后,會發現直接在地址欄中輸入跳到首頁的網址是可以直接進去的,那么我們的登錄功能就不是擺設了嗎?所以需要使用攔截器

registry.addViewController("/main.html").setViewName("dashboard");return "redirect:/main.html";

四、攔截器

1.自定義攔截器

/*** 這個攔截器的作用就是:進行登錄的檢查,如果不通過的話是不能進行主頁的訪問和一些增刪改查功能的*/
public class LoginHandlerInterceptor implements HandlerInterceptor {//目標方法執行之前@Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {Object loginUser = request.getSession().getAttribute("loginUser");if (loginUser==null){//在頁面顯示錯誤信息request.setAttribute("msg","沒有權限");//未登錄,返回登錄頁面request.getRequestDispatcher("/login.html").forward(request,response);return false;}else{//已登錄return true;}}@Overridepublic void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {}@Overridepublic void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {}
}

2. 將攔截器注入到容器中

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {@Bean//將這個組件注冊到容器中public WebMvcConfigurer webMvcConfigurer(){WebMvcConfigurer webMvcConfigurer = new WebMvcConfigurer() {//注冊攔截器@Overridepublic void addInterceptors(InterceptorRegistry registry) {//由于SpringBoot已經做好了靜態資源的映射,攔截器不會攔截靜態資源//addPathPatterns()表示會對那種類型的映射進行攔截,"/**"表示/全部攔截//excludePathPatterns()表示排除一些不攔截的registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**").excludePathPatterns("/login.html","/","/user/login");}@Overridepublic void addViewControllers(ViewControllerRegistry registry) {registry.addViewController("/").setViewName("login");registry.addViewController("/login.html").setViewName("login");registry.addViewController("/main.html").setViewName("dashboard");}};return webMvcConfigurer;}

3. 在Controller中是利用了session來進行用戶名的存儲,然后在攔截器中判斷用戶名是否為空

@Controller
public class LoginController {//可以使用Restful風格的注解// @RequestMapping(value = "/user/login",method = RequestMethod.POST)@PostMapping(value="/user/login")public String login(@RequestParam("username") String username,@RequestParam("password") String password,Map<String,Object> map,HttpSession session){if(!StringUtils.isEmpty(username) && "123456".equals(password)){session.setAttribute("loginUser",username);//登錄成功,為了防止表單重復提交,將重定向到dashboardreturn "redirect:/main.html";}else{//登錄失敗map.put("msg","用戶名密碼錯誤");}return "login";}
}

五、CRUD

1.員工列表

  • 實驗要求

CRUD滿足rest風格;

URI:/資源名稱、資源標識;

HTTP請求方式區分對資源CRUD操作;

  • Controller代碼實現
@Controller
public class EmployeeController {@AutowiredEmployeeDao employeeDao;//獲取所有員工@GetMapping("/emps")public String list(Model model){//獲取所有員工Collection<Employee> all = employeeDao.getAll();//將獲取到的員工存進session域中model.addAttribute("emps",all); //thymeleaf默認就會進行拼串;前綴是classpath:/templates/xxxx.htmlreturn "emp/list";}
}
  • Thymeleaf公共頁面元素抽取

93b17f65ce6688f4d35c2b03f00aa206.png

三種引入功能片段的th屬性:

th:insert----將公共片段整個插入聲明引入元素中;

th:replace---將聲明引入的元素替換為公共片段;

th:include----將被引入的片段的內容包含進這個標簽中;

7aa4f9aabb20d232a895e29a56823e43.png

56d863bd067c2d341a7a793304041dec.png
  • 鏈接高亮

thymeleaf實現只有在點擊側邊欄某個按鈕時,只有點擊的按鈕高亮;將之前的側邊欄和頂部欄代碼抽取出來放在一個新的HTML文件里

側邊欄---dashboard
<a class="nav-link active" href="http://getbootstrap.com/docs/4.0/examples/dashboard/#"th:class="${activeUri=='main.html'}?'nav-link active':'nav-link '">
側邊欄----員工管理<a class="nav-link active" href="#"th:href="@{/emps}" th:class="${activeUri=='emps'?'nav-link active':'nav-link '}">
dashboard.html(將activeUri的值傳遞到引用的側邊欄里,進行判斷)
<div th:replace="commens/bar::#sidebar(activeUri='main.html')"></div>
list.html
<div th:replace="commens/bar::#sidebar(activeUri='emps')"></div>
  • 員工列表顯示
<thead><tr><th>#</th><th>lastName</th><th>gender</th><th>department</th><th>birth</th><th>操作</th></tr>
</thead>
<tbody><tr th:each="emp:${emps}"><td th:text="${emp.lastName}"></td><td th:text="${emp.lastName}"></td><td th:text="${emp.gender}==0?'男':'女'"></td><td th:text="${emp.department.departmentName}"></td><td th:text="${#dates.format(emp.birth,'yyyy--MM-dd:HH:mm')}"></td><td><button class="btn btn-sm btn-primary">修改</button><button class="btn btn-sm btn-danger">刪除</button></td></tr>

2.添加員工

  • Controller
@GetMapping("/addEmp")
public String toAddPage(Model model){Collection<Department> departments = departmentDao.getDepartments();model.addAttribute("depts",departments);//返回到添加頁面return "emp/add";
}
@PostMapping("/addEmp")public String addEmp(Employee employee){System.out.println("保存的員工是:"+employee);employeeDao.save(employee);//來到員工列表頁面//redirect:重定向到一個地址//forward:轉發到一個地址return "redirect:/emps";}
  • 前臺頁面
跳轉請求
<a href="addEmp" class="btn btn-sm btn-success">添加</a>
add.html
<form th:action="addEmp" method="post"><div class="form‐group"><label>LastName</label><input name="lastName" type="text" class="form‐control" placeholder="zhangsan"></div><div class="form‐group"><label>Email</label><input name="email" type="email" class="form‐control" placeholder="zhangsan@atguigu.com"></div><div class="form‐group"><label>Gender</label><br/><div class="form‐check form‐check‐inline"><input class="form‐check‐input" type="radio" name="gender" value="1"><label class="form‐check‐label">男</label></div><div class="form‐check form‐check‐inline"><input class="form‐check‐input" type="radio" name="gender" value="0"><label class="form‐check‐label">女</label></div></div><div class="form‐group"><label>department</label><select class="form‐control"name="department.id"><option th:value="${dept.id}" th:each="dept:${depts}" th:text="${dept.departmentName}">1</option></select></div><div class="form‐group"><label>Birth</label><input name="birth" type="text" class="form‐control" placeholder="zhangsan"></div><button type="submit" class="btn btn‐primary">添加</button>
</form>
  • 使用添加功能主要會出現的錯誤是400錯誤,前臺輸入的格式不匹配導致

我們這個功能這邊主要是日期的格式會導致錯誤

填寫的日期格式主要有:2017/01/01 2017-01-01 2017.01.01

日期的格式話:SpringMVC需要將頁面提取的值轉化為指定的類型;

默認的日期格式是按照/的格式

可以在application.properties配置文件中修改

spring.mvc.date-format=yyyy-MM-dd

3.修改員工

  • 在做員工修改的時候發現修改頁面和新增頁面是差不多的,只需要通過判斷去判定執行的是添加功能還是修改功能
add.html
<!--對功能的判定就是通過emp是否為空,不為空則是修改-->
<form th:action="@{/addEmp}" method="post"><input type="hidden" name="_method" value="put" th:if="${emp!=null}"/><!--在傳遞到Controller的時候也要把id傳過去(修改功能的時候)--><input type="hidden" th:if="${emp!=null}" th:value="${emp.id}"/><div class="form‐group"><label>LastName</label><input th:value="${emp!=null}?${emp.lastName}" name="lastName" type="text" class="form‐control" placeholder="zhangsan"></div><div class="form‐group"><label>Email</label><input th:value="${emp!=null}?${emp.email}" name="email" type="email" class="form‐control" placeholder="zhangsan@atguigu.com"></div><div class="form‐group"><label>Gender</label><br/><div class="form‐check form‐check‐inline"><input class="form‐check‐input" type="radio" name="gender" value="1"th:checked="${emp!=null}?${emp.gender==1}"><label class="form‐check‐label">男</label></div><div class="form‐check form‐check‐inline"><input class="form‐check‐input" type="radio" name="gender" value="0"th:checked="${emp!=null}?${emp.gender==0}"><label class="form‐check‐label">女</label></div></div><div class="form‐group"><label>department</label><select class="form‐control"name="department.id"><option th:selected="${emp!=null}?${dept.id==emp.department.id}" th:value="${dept.id}" th:each="dept:${depts}" th:text="${dept.departmentName}"></option></select></div><div class="form‐group"><label>Birth</label><input th:value="${emp!=null}?${emp.birth}" name="birth" type="text" class="form‐control" placeholder="zhangsan"></div><button type="submit" class="btn btn‐primary"th:text="${emp!=null}?'修改':'添加'"></button>
</form>
  • Controller
//來到修改頁面,查出當前員工,并進行回顯
@GetMapping("/editEmp/{id}")
public String toEditPage( @PathVariable("id") Integer id, Model model){Employee employee = employeeDao.get(id);model.addAttribute("emp",employee);//頁面顯示所有的部門信息Collection<Department> departments = departmentDao.getDepartments();model.addAttribute("departments",departments);return "emp/add";
}
//進行員工修改,需要傳遞該員工的id
@PutMapping("/addEmp")
public String updateEmp(Employee employee){System.out.println("收到的員工信息:"+employee);System.out.println(employeeDao);employeeDao.save(employee);return "redirect:/emps";
}
  • 這里重點提一下在寫這段代碼會出現的一個錯誤:如果使用的是較高版本的SpringBoot,在修改的時候使用的是put請求,SpringBoot是為我們配置好了hiddenFilter,但是他默認是不開啟的,需要在application.properties中進行開啟
#開啟過濾器
spring.mvc.hiddenmethod.filter.enabled=true@Bean
@ConditionalOnMissingBean({FormContentFilter.class})
@ConditionalOnProperty(prefix = "spring.mvc.formcontent.filter",name = {"enabled"},matchIfMissing = true
)
public OrderedFormContentFilter formContentFilter() {return new OrderedFormContentFilter();
}

4.刪除員工

  • Controller
//員工刪除方法
@DeleteMapping("/deleteEmp/{id}")
public String deleteEmp(@PathVariable("id") Integer id){employeeDao.delete(id);return "redirect:/emps";
}
  • 前臺頁面最簡單的編寫就是將刪除按鈕用form表單包起來,然后發送delete請求,再傳遞id;但是這樣的頁面就不太美觀,所以可以使用js點擊事件來進行編寫
 <form th:action="@{/deleteEmp/}+${emp.id}" method="post"><input type="hidden" name="_method" value="delete"><button type="submit" class="btn btn-sm btn-danger">刪除</button>
</form>
點擊事件:
<button th:attr="del_uri=@{/emp/}+${emp.id}" class="btn btn‐sm btn‐danger deleteBtn">刪除</button></td> </tr><script>$(".deleteBtn").click(function(){//刪除當前員工的$("#deleteEmpForm").attr("action",$(this).attr("del_uri")).submit();return false; }); 
</script>

這個小實驗到這里就寫的差不多了,和Spring的框架差不多,只是在寫的過程中可以知道一些技巧和thymeleaf的標簽的使用,這里只貼了一部分代碼,完整代碼可以進入我的GitHub:https://github.com/rainbow-dan/SpringBoot-rest-crud;如果你喜歡我的文章,就關注我吧!

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/534063.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/534063.shtml
英文地址,請注明出處:http://en.pswp.cn/news/534063.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

計算機英語六級,英語六級作文范文:計算機

英語六級考試時間越來越近了&#xff0c;所以在備考的時候就更要掌握技巧&#xff0c;勤加練習。在備考英語六級寫作時&#xff0c;學習一篇好的范文&#xff0c;會給復習帶來事半功倍的效果。Using a computer every day can have more negative than positive effects on you…

python軟件_Python自制照片美顏軟件~

下午被一個騙子惡心到了&#xff0c;本來聽公開課聽得好好的&#xff0c;搞得心情極差&#xff0c;于是就中斷了網課&#xff0c;聽聽音樂&#xff0c;寫一下文章吧&#xff01;前期準備①Python編譯環境以及Python代碼編輯器Pycharm的安裝&#xff1a;請在【微信公眾后臺】找到…

數據集怎么導出_PCA算法 | 數據集特征數量太多怎么辦?用這個算法對它降維打擊...

今天是機器學習專題的第27文章&#xff0c;我們一起來聊聊數據處理領域的降維(dimensionality reduction)算法。我們都知道&#xff0c;圖片格式當中有一種叫做svg&#xff0c;這種格式的圖片無論我們將它放大多少倍&#xff0c;也不會失真更不會出現邊緣模糊的情況。原因也很簡…

html form callback,Promise異步編程模式總結初始化Promise對象統一錯誤處理PromisifyfromCallbackMongoose Promisify...

Promise是JavaScript中的一種異步編程范式&#xff0c; 一個Promise對象表示一個即將完成但還未完成的操作。 鑒于JavaScript中異步和回調的編程風格&#xff0c; Promise模式可以有效地避免『Callback Hell』。Promise 最初有q和bluebird等實現&#xff0c;在ES2015(ES6)提出后…

常用命令_GIT常用命令大全

Git 是一個很強大的分布式版本控制系統。它不但適用于管理大型開源軟件的源代碼&#xff0c;管理私人的文檔和源代碼也有很多優勢。克隆遠程文件&#xff1a;git clone https://gitee.com/abcd/codefile.git projectgit checkout -b dev(本地分支名稱) origin/dev(遠程分支名稱…

nvidia顯示設置不可用_Nvidia顯示設置不可用,您當前未使用連接到NVIDIA GPU的顯示器的解決方法...

相信不少用戶遇到這樣一個問題&#xff0c;就是新購買的臺式機電腦&#xff0c;配置達標的情況下&#xff0c;玩游戲出現卡頓不流暢的現象&#xff0c;準備在NVIDIA控制面板查看是否設置的問題&#xff0c;在打開NVIDIA控制面板的時候&#xff0c;提示了“Nvidia顯示設置不可用…

html的id不能有.嗎,html – 哪些DOM元素不能接受id?

在HTML5中,id屬性是global attribute,可以在任何元素上指定.如果你看看Document Type Declaration for HTML4,你可以找到沒有&#xff05;attrs的元素;在他們的屬性列表中定義,表示它們不支持id屬性.那些包括在“文檔頭”部分的底部附近&#xff1a;HEAD,TITLE,BASE,META,STYLE…

oracle tns 代理配置_Toad for oracle安裝配置與使用

一.toad安裝與配置注意:toad的使用本機電腦必須安裝完整版oracle客戶端,不能是精簡版的.1.1完整版oracle客戶端的安裝.1.解壓文件&#xff0c;安裝oracle客戶端打開安裝包&#xff0c;找到setup.ext&#xff0c;開始安裝。提示下圖彈窗,可根據此網址內容進行更改(https://blog.…

吳楓 python小課賬號_無門檻速學編程——Python小短課,自上而下分而治之

【Python小短課 11】自上而下&#xff0c;分而治之 做任何事都需計劃&#xff0c;編程也是。 譬如寫文章要列大綱、作畫要想布局&#xff0c;編程也需先謀全局&#xff0c;而后思慮細節。 就以上回說到的“找寶藏”這個程序舉例&#xff0c;最頂層的需求自然就是“找寶藏”&…

計算機本地磁盤D無法擴展,計算機上的本地磁盤D突然無法打開,表明它需要格式化...

接受使用數據恢復軟件將重要數據保存到其他磁盤FindDate特定操作: 運行軟件----“打開”后&#xff0c;將顯示要還原的驅動器. C \ D \ E \ F選擇您要還原的一個&#xff0c;它將開始. 掃描后&#xff0c;再次保存掃描的文件. 哈哈&#xff0c;希望對您有所幫助.最后&#xff0…

caffe運行不停止_caffe(gpu)安裝過程及問題解決

2019.12.05 caffe(gpu)安裝參考網址&#xff1a;教程1&#xff1a;weiliu89/caffe?github.com教程2&#xff1a;https://blog.csdn.net/yggaoeecs/article/details/79163789?blog.csdn.net環境&#xff1a;Ubuntu16.04cuda10.0安裝過程&#xff1a;git clone https://github.…

2021年考計算機考研三戰,2021考研的小伙伴有3條忠告一定要記得,這些都是歷年實戰經驗...

2021考研的小伙伴有3條忠告一定要記得&#xff0c;這些都是歷年實戰經驗&#xff0c;考研一定要記得避開三個大坑。1&#xff0c;分數線低的學校就一定容易考。有一些學校分數線看著很低但實際上難度不低&#xff0c;比如首都師范大學 &#xff0c;很多專業就是國家線錄取甚至招…

c++ 返回string_JVM系列之:String.intern和stringTable

簡介StringTable是什么&#xff1f;它和String.intern有什么關系呢&#xff1f;在字符串對象的創建過程中&#xff0c;StringTable有起到了什么作用呢&#xff1f;一切的答案都在本文中&#xff0c;快來看看吧。intern簡介intern是String類中的一個native方法&#xff0c;所以它…

conda install 換源_ubuntu更換pip install,apt-get,conda install 成國內源

# 默認注釋了源碼鏡像以提高 apt update 速度&#xff0c;如有需要可自行取消注釋deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe mu…

python幫助文檔中查看內置函數_PYTHON官方文檔內置函數整理

一、數學運算類 abs(x) 求絕對值 1 、參數可以是整型&#xff0c;也可以是復數 2 、若參數是復數&#xff0c;則返回復數的模 complex([real[, imag]]) 創建一個復數 divmod(a, b) 分別取商和余數 注意&#xff1a;整型、浮點型都可以 float([x]) 將一個字符串或數轉換為浮點數…

計算機二級指針,C語言——二級指針

二級指針的概念首先任何值都有地址&#xff0c;一級指針的值雖然是地址&#xff0c;但這個地址做為一個值亦需要空間來存放&#xff0c;是空間就具有地址&#xff0c;這就是存放地址這一值的空間所具有的地址&#xff0c;二級指針就是為了獲取這個地址&#xff0c;一級指針所關…

華為 虛擬鍵盤_華為mate30 pro虛擬機械鍵盤特有體驗,雖是虛擬,但卻感受逼真...

華為Mate30 pro已于26日在國內正式發布了。此外&#xff0c;根據了解華為Mate30系列現在已經突破了5億的銷售額。看來&#xff0c;華為的這個下半年旗艦手機非常受歡迎啊。華為Mate30系列現在在國內已經發布了&#xff0c;其整體感官看上去與海外的沒有多大的區別。其實&#x…

python 如何快速判斷列表是否相同_Python-檢查列表中的所有元素是否相同

小編典典 通用方法&#xff1a; def checkEqual1(iterator): iterator iter(iterator) try: first next(iterator) except StopIteration: return True return all(first rest for rest in iterator) 單線&#xff1a; def checkEqual2(iterator): return len(set(iterator)…

計算機有什么著名基金經理排名,百萬年薪的基金經理,都是什么專業出身?!...

有人會說了“小嗶君你四不四撒&#xff01;基金經理肯定是金融專業出身的咯&#xff1f;不然嘞&#xff1f;”但事實的真相是許多基金經理都并非科班出身這要從基金經理的晉升機制說起了&#xff01;如下圖基金經理都是從研究員做起的&#xff01;那么問題來了&#xff0c;如何…

遍歷children_589. N叉樹的前序遍歷

589. N叉樹的前序遍歷給定一個 N 叉樹&#xff0c;返回其節點值的前序遍歷。例如&#xff0c;給定一個 3叉樹 :返回其前序遍歷: [1,3,5,6,2,4]。說明: 遞歸法很簡單&#xff0c;你可以使用迭代法完成此題嗎?題解&#xff1a;既然是樹的遍歷&#xff0c;那么一共就是兩種思路&a…