SpringBoot Learning 2: Integrating Web Technology_addurlmappings_kenewstar’s Blog

class=”markdown_views prism-atom-one-light”> (1) SpringBoot integrates Servlet technology Many beginners who are new to JavaEE will learn Jsp/Servlet in Web technology, and the same SpringBoot also provides integrated Servlet technology; Create a Java project (IDEA+Maven) The project is created; There are two ways for SpringBoot to integrate Servlet: 1 Complete the registration of Servlet components by annotation ① Create a FirstServlet class to inherit HttpServlet Create the code as follows: package com.kenewstar.servlet; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** * @Author:kenewstar * @Description: For springboot integration servlet, * Method 1: Complete the registration of Servlet components through annotation scanning * @Date:Created in 2020/4/20 */ @WebServlet(“/first”) //url access path public class FirstServlet extends HttpServlet { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //Console print data System.out.println(“springboot integrated servlet: use annotation method”); } } The above code does not explain too much, it is just a very common Servlet;Next we need to create a SpringBoot startup class; ② Create SpringBoot startup class package com.kenewstar; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.ServletComponentScan; /** * @Author:kenewstar * @Description: spingboot startup class, test FirstServlet * @Date:Created in 2020/4/20 */ @SpringBootApplication @ServletComponentScan //used to scan @WebServlet annotation public…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索