#SpringMVC
Explore tagged Tumblr posts
Text
Key points to learn the Spring Framework
key points to learn the Spring Framework:
Java Basics: Ensure solid understanding of Java fundamentals.
Spring Basics: Read official Spring documentation for an overview.
Core Concepts: Learn Inversion of Control (IoC) and Dependency Injection (DI).
Spring Boot: Explore Spring Boot for quick setup and configuration.
Dependency Injection: Understand IoC containers, XML, and annotation-based configurations.
Spring MVC: Grasp Model-View-Controller architecture for web applications.
Data Access: Explore data access using JDBC, ORM (like Hibernate), and Spring Data.
Security: Learn Spring Security for authentication and authorization.
RESTful Web Services: Build RESTful APIs using Spring MVC or WebFlux.
Aspect-Oriented Programming (AOP): Understand AOP for handling cross-cutting concerns.
Testing: Write unit and integration tests using tools like JUnit.
Real-World Projects: Apply knowledge through practical projects.
Community Engagement: Join Spring community discussions and forums.
Advanced Topics: Explore Spring Cloud, Spring Batch, and other advanced features.
Continuous Learning: Stay updated with the latest releases and features.
#magistersign#Java#SpringFramework#Programming#Coding#SoftwareDevelopment#JavaDevelopment#WebDevelopment#SpringBoot#DependencyInjection#SpringMVC#DataAccess
0 notes
Text

Want to Learn Full Stack Web Development? Build Web Apps & Kickstart your Development Journey! 𝑷𝒓𝒐𝒈𝒓𝒂𝒎 𝑯𝒊𝒈𝒉𝒍𝒊𝒈𝒉𝒕𝒔:
⭕ Learn required Languages, Frameworks & Tools[HTML, CSS2 CSS3, JavaScript, React JS, Spring Framework(Spring Core | Spring MVC | Spring Boot)]
⭕ Working in Real-World Projects
⭕ Learn from the Experts & Industry Professionals
⭕ Experience the complete Development Lifecycle
⭕ Be a certified Full Stack Developer Don't wait for the right time as this is the right time!
Take one step further & be ahead of the crowd. Enroll Now!!!
https://forms.gle/ZmjqBnwhrch3tDYy8 #springboot
#springframework#springmvc#ReactJS#bootstrap#internship#training#fullstackdevelopment#webdevelopment#kanpur#lucknow
0 notes
Text
What is Dispatcher Servlet in Spring MVC?
Dispatcher Servlet is actually the heart of Spring MVC.Every single web request which is supposed to be processed by Spring MVC goes through DispatcherServlet.In general, its an implementation of Front Controller Pattern which provides a single point of entry in your application. It handles all incoming requests. It is also the bridge between Java and Spring.he DispatcherServlet, as any Servlet, needs to be declared and mapped according to the Servlet specification by using Java configuration or in web.xml. In turn, the DispatcherServlet uses Spring configuration to discover the delegate components it needs for request mapping, view resolution, exception handling.
It is responsible for request handling by delegating requests to additional components of Spring MVC e.g. actual controller classes i.e. those which are annotated using @Controller or @RestController (in case of RESTful Web Services), Views, View Resolvers, handler mappers, etc.
Though the job of actual request mapping is done by @RequestMapping annotation, it's actually the DispatcherServlet which delegates request to the corresponding controller.
In the case of RESTful web services, it is also responsible for finding the correct message converter to convert the response into the format client is expecting like JSON, XML, or TEXT.
For example, if a client is expecting JSON then it will use the MappingJacksonHttpMessageConverter or MappingJackson2HttpMessageConverter (depending upon whether Jackson 1 or Jackson 2 is available in Classpath) to convert the response returned by convert into a JSON string.
==DispatcherServlet Request Processing===
Essentially, a DispatcherServlet handles an incoming HttpRequest, delegates the request, and processes that request according to the configured HandlerAdapter interfaces that have been implemented within the Spring application along with accompanying annotations specifying handlers, controller endpoints, and response objects.
Let's get more in-depth about how a DispatcherServlet processes a component:
**The WebApplicationContext associated to a DispatcherServlet under the key DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE is searched for and made available to all of the elements of the process
**The DispatcherServlet finds all implementations of the HandlerAdapter interface configured for your dispatcher using getHandler() – each found and configured implementation handles the request via handle() through the remainder of the process
**The LocaleResolver is optionally bound to the request to enable elements in the process to resolve the locale
**The ThemeResolver is optionally bound to the request to let elements, such as views, determine which theme to use
**if a MultipartResolver is specified, the request is inspected for MultipartFiles – any found are wrapped in a MultipartHttpServletRequest for further processing
**HandlerExceptionResolver implementations declared in the WebApplicationContext picks up exceptions that are thrown during processing of the request.
Thank You... Pramuda Liyanage -Fullstack Developer-
2 notes
·
View notes
Text
SpringMVC Digging Road 4 - Annotation2 - Other uses of RequestMapping
##Request method qualification
###Request narrowing
Used directly on the Controller
>@RequestMapping(value="/request")
####Methodologically,
>@RequestMapping(value="/request",method=RequestMethod.GET)
####Combination mode
>@RequestMapping(value="/request",{method=RequestMethod.GET,RequestMethod.POST})
##Request parameter mapping
####The specified parameter name exists in the request data
>@RequestMapping(params="submitFlag",method=RequestMethod.GET)
Said the request has a parameter name of "submitFlag" and the request method is "GET", which can be matched.
####Parameter name is not specified in the request data
>@RequestMapping(params="!submitFlag",method=RequestMethod.GET)
####Parameter name = value specified in request data
>@RequestMapping(params="submitFlag=create")
####Parameter name != value specified in request data
>@RequestMapping(params="submitFlag!=create",method=RequestMethod.GET)
####Combined use is the relationship of "and"
>@RequestMapping(params={"test1","test2=value"})
##Request Headers mapping
####The request header data has the specified parameter name
>@RequestMapping(value="/header/test",headers="value")
####Parameter name is not specified in the request header data
>@RequestMapping(value="/header/test",headers="value")
####Parameter name = value specified in request header data
>@RequestMapping(value="/header/test",headers="value=data")
####Parameter name != value specified in request header data
>@RequestMapping(value="/header/test",headers="value!=data")
####Combined use is the relationship of "and"
>@RequestMapping(value="/header/test",headers={"Hello=abc","Accept!=text/vnc.wap.wml"})
####Parameter name = value specified in request header data
>@RequestMapping(value="/header/test1",headers="value=data")
**Note: Generally, headers contain the contents of Agent and Cookie.**
##Request type qualification
####The following code only accepts the request type of application/json, that is, the value of Content-Type
>@RequestMapping(value = "/consumes/test", consumes="application/json")
##Set the return type
####Set the return type
####The following code sets the return type to application/json
>@RequestMapping(value = "/produces/test", produces="application/json")
0 notes
Photo

👩💻 . . . #webdev #webdesign #webhosting #angularJS #SpringMVC #cordova #reactsJS https://www.instagram.com/p/ByihZNYnYVy/?igshid=hbw10cgdipuu
0 notes
Text
Spring mvc integration with prometheus Example
In this article ,we will see how we can monitor spring MVC applications using prometheus tool . You wont get much documentation for this setup on web. Prometheus is mostly configured with spring boot easily. But in order to configure it with spring MVC based application , it requires some additional configurations - Prometheus Prometheus is a time-series monitoring application written in Go. It can run on a server, in a docker container, or as part of a Kubernetes cluster (or something similar). Prometheus collects, stores, and visualizes time-series data so that you can monitor your systems. You can tell Prometheus exactly where to find metrics by configuring a list of "scrape jobs". Applications that are being monitored can provide metrics endpoints to Prometheus using any one of the many client libraries available; additionally, separate exporters can gather metrics from applications to make them available in Prometheus. Metrics get stored locally for 15 days, by default, and any Prometheus server can scrape another one for data. Additionally, remote storage is another option for Prometheus data - provided there is a reliable remote storage endpoint. Benefits: The option of "service discovery" allows Prometheus to keep track of all current endpoints effortlessly. Outages are quickly detected .The PromQL query language is incredibly flexible and Turing-complete. There's also a very low load on the services monitored (metrics get stored in memory as they get generated), allowing fewer resources to get used. Additionally, Prometheus users can control traffic volumes, access metrics in the browser, and allow for easy reconfiguration. Step 1 : Spring MVC application pom.xml configuration Below prometheus dependencies are required in pom.xml for project - 0.6.0 io.prometheus simpleclient ${prometheus.version} io.prometheus simpleclient_hotspot ${prometheus.version} io.prometheus simpleclient_servlet ${prometheus.version} io.prometheus simpleclient_pushgateway ${prometheus.version} io.prometheus simpleclient_spring_web ${prometheus.version} com.fasterxml.jackson.core jackson-core 2.5.2 Step 2 : Spring MVC application web.xml configuration We need configure MetricsServlet to capture the metrics of our spring mvc application as below - PrometheusServlet io.prometheus.client.exporter.MetricsServlet PrometheusServlet /metrics Step 3: Add an interceptor class This will intercept all the requests coming to application and capture the metrics to be exposed to prometheus - package com.myjavablog.config; import io.prometheus.client.Counter; import io.prometheus.client.Gauge; import io.prometheus.client.Histogram; import io.prometheus.client.Summary; import org.apache.log4j.Logger; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * @author anupb */ public class PrometheusMetricsInterceptor extends HandlerInterceptorAdapter { private static Logger logger = Logger.getLogger(PrometheusMetricsInterceptor.class); private static final Histogram requestLatency = Histogram.build() .name("service_requests_latency_seconds") .help("Request latency in seconds.") .labelNames("systemId", "appId", "type", "name", "method").register(); private ThreadLocal timerThreadLocal; @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { return super.preHandle(request, response, handler); } @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { String name = this.getName(request, handler).toLowerCase(); String method = request.getMethod().toUpperCase(); timerThreadLocal = new ThreadLocal(); timerThreadLocal.set(requestLatency.labels(name, method).startTimer()); super.postHandle(request, response, handler, modelAndView); } @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { super.afterCompletion(request, response, handler, ex); if (timerThreadLocal.get() != null) { timerThreadLocal.get().observeDuration(); } } @Override public void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { super.afterConcurrentHandlingStarted(request, response, handler); } private String getName(HttpServletRequest request, Object handler) { String name = ""; try { if (handler != null && handler instanceof HandlerMethod) { HandlerMethod method = (HandlerMethod) handler; String className = ((HandlerMethod) handler).getBeanType().getName(); name = className + "." + method.getMethod().getName(); } else { name = request.getRequestURI(); } } catch (Exception ex) { logger.error("getName", ex); } finally { return name; } } } Step 4: Add prometheus initialization configuration This will expose the metrics to prometheus server - package com.myjavablog.config; public class PrometheusConfig { private static Logger logger = Logger.getLogger(PrometheusConfig.class); @PostConstruct public void initialize() { logger.info("prometheus init..."); DefaultExports.initialize(); logger.info("prometheus has been initialized..."); } } Step 5: Add an interceptor to spring-mvc.xml You need to first add the schema location as below - http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd Then you need to add below tag - Step 6: Add configuration to applicationcontext.xml Once all this configuration is done , you can add the application URL in prometheus. These parameters are useful to monitor your spring MVC application. Read the full article
0 notes
Text
MyBatis and Doma2: Dynamic SQL in Java Spring
Trước giờ làm với mấy chú Nhật hay sử dụng Doma2 trong Spring (hoặc seasar) để thao tác với Database. Thấy cái này cũng hay vì nó có viết được dynamic SQL (mà Doma2 gọi là 2WaySQL). Kiểu như if name != "" thì thêm điều kiện AND name like %name-truyền-vào%.
Nhìn thấy có vẻ đơn giản nhưng nếu không có cái dynamic SQL thì phải sử dụng IF hoặc CASE WHEN trong SQL làm giảm đáng kể performance, bởi index thì không nhận khi sử dụng điều kiện rẽ nhánh.
Nhược điểm của Doma2 là cộng đồng nhỏ quá, 1 phần vì nó là hàng Nhật, 1 phần vì cũng lâu đời rồi nên chẳng thấy ai dùng (ngoài Nhật và công ty outsource cho Nhật).
Mới đây mò ra cái MyBatis cũng làm được trò này mà cộng đồng to hơn Doma2 nhiều. https://mybatis.org/mybatis-dynamic-sql/docs/spring.html
0 notes
Link
一般最常见的请求为GET和POST,get请求的参数在url上可以获取,post请求参数除了url上还有可能在表单中,文件上传时,获取方式又和一般的参数获取不一样 本篇则主要集中在不同请求方式下,获取参数的使用姿势
0 notes
Text
Pizza Order form using Reactjs UI Components with Spring MVC
In my blog post http://blog.star-is.info/?p=12 I show how to use Reactjs (frontend) with Spring MVC (backend) and implement a dynamic Pizza Order Form. I have covered new concepts as Objects inside state and arrays inside those objects
0 notes
Photo

Full Stack Web Development with Angular and Spring MVC ☞ https://morioh.com/p/654de255f692 #Angular #SpringMVC WebDevelopment
3 notes
·
View notes
Photo

Full Stack Web Development with Angular and Spring MVC ☞ https://morioh.com/p/654de255f692 #Angular #SpringMVC WebDevelopment
1 note
·
View note
Photo

14 Tips for Writing Spring MVC Controllers ☞ http://bit.ly/2MWW7dw #SpringMVC #Java #Morioh
1 note
·
View note
Photo

14 Tips for Writing Spring MVC Controllers ☞ http://bit.ly/2MWW7dw #SpringMVC #Java #Morioh
1 note
·
View note
Text
SpringMVC Digging Road 3 - Annotation1 - Usage of value in RequestMapping
``
@Controller : Used to identify the processor class
@RequestMapping : Mapping rules of request to processor function method
@RequestParam : Binding of request parameters to method parameters of processor function processing methods
@ModelAttribute : Request the binding of parameters to command objects
@SessionAttributes : Attributes used to declare session level storage are placed on the processor class. Usually, the names corresponding to model attributes (such as @ModelAttribute) are listed, and these attributes will be stored transparently in the session
@InitBinder : Custom data binding registration support is used to convert request parameters to the corresponding types of command object attributes
@CookieValue : Binding of cookie data to method parameters of processor function processing method
@RequestHeader : Binding of request header data to processing method parameters of processor function
@RequestBody : Binding of the requested body (type conversion via HttpMessageConverter)
@RequestStatus : Define the processing method of processor function/the status code and reason returned by the abnormal processor
@ExceptionHandler : Annotated declaration exception handler
@PathVariable : Request the binding of template variable part in URI to the method parameters of processor function processing method, so as to support RESTful architecture style URL
```
Directory structure reference :
https://blog.csdn.net/qq_33811662/article/details/80699470
First of all, the jsp part of the code:
login.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
请求路径为:${path}
<center>
<form action="do_login" method="post">
姓名:<input type="text" name="name" /> <br />
性别:<input type="text"name="gender" /> <br />
<input value="提交" type="submit" />
</form>
</center>
</body>
</html>
Only @RequestMapping and @RequestParam will be discussed here
@RequestMapping
View source code:
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Mapping
public @interface RequestMapping {
String name() default "";
@AliasFor("path")
String[] value() default {};
@AliasFor("value")
String[] path() default {};
RequestMethod[] method() default {};
String[] params() default {};
String[] headers() default {};
String[] consumes() default {};
String[] produces() default {};
}
RequestMapping is an annotation used to handle request address mapping, which can be used on class and interface methods. When used on class or interface, it means that all corresponding request methods in class take this address as the parent path, and the basic fields are name, path(value)(path and value refer to each other), method, params, headers, consumes, produces
More commonly used are:
####value(path)
Specify the actual address of the request, and the specified address can be URI Template mode
####method
Specifies the requested method type. E.g., GET, POST, PUT, DELETE, etc
####consumes
Specify the Content-Type for processing requests, such as application/json, text/html;
####produces
Specifies the content type to be returned, which will only be returned if the specified type is included in the (Accept) type in the request header
####params
Specifies that some parameter values must be included in the request for the method to process the request.
####header
Specifies that some specified header values must be included in the request for the method to process the request.
###Usage of value:
Declare on the method:
@Controller
public class LoginController {
@RequestMapping("/to_login")
public ModelAndView toLogin(){
System.out.println("进入 to_login");
ModelAndView mv = new ModelAndView();
mv.setViewName("login");
return mv;
}
}
At this time, the request address is ip/project_name/to_login
Declare an @RequestMapping annotation on the class:
@Controller
@RequestMapping("/login")
public class LoginController {
@RequestMapping("/to_login")
public ModelAndView toLogin(){
System.out.println("进入 to_login");
ModelAndView mv = new ModelAndView();
mv.setViewName("login");
return mv;
}
}
At this time, the request address is ip/project_name/login/to_login
* Common URL mapping: @ requestmapping ({"/to _ login", "login"}): multiple URL paths can be mapped to the function processing method of the same processor
* Uri template schema mapping
> 1、@RequestMapping("/login/{userId}"):{xx} the URL of placeholder request can be "/login/123" or "/login/abc". The value of xx variable in {xx} in URI template pattern can be extracted through @PathVariable.
> 2、@RequestMapping("/login/{userId}/topic"):The requested URL can be "/login/uid/topic"
> 3、@RequestMapping("/login/{userId}/topic/{topicId}"):The requested URL can be "/login/uid/topic/tid"
* Ant style URL path mapping
> 1、@RequestMapping("/login/**"):Can match "/login/abc/abc",However, "/login/abc" will be mapped to preferentially by "/login/{userId}" pattern in URI template pattern mapping (longest matching takes precedence)
> 2、@RequestMapping("/login/abc?"):Can match "/login/abcd" and "/login/abc1",can’t match "/login/abc" or "/login/abcde"
> 3、@RequestMapping("/login/abc*"):Can match "/login/abcd" and "/login/abcde",can’t match "/login/abc"
Code example:
@Controller
@RequestMapping("/login")
public class LoginController {
@RequestMapping("/to_login")
public ModelAndView toLogin() {
System.out.println("进入 to_login");
ModelAndView mv = new ModelAndView();
mv.addObject("path", "/to_login");
mv.setViewName("login");
return mv;
}
@RequestMapping({"/to_login2","/login"})
public ModelAndView toLogin2() {
System.out.println("进入 to_login");
ModelAndView mv = new ModelAndView();
mv.addObject("path", "/to_login2,/login");
mv.setViewName("login");
return mv;
}
@RequestMapping({"/to_login/abc?"})
public ModelAndView toLogin3() {
System.out.println("进入 to_login");
ModelAndView mv = new ModelAndView();
mv.addObject("path", "/to_login/abc?");
mv.setViewName("login");
return mv;
}
@RequestMapping({"/to_login/abc*"})
public ModelAndView toLogin4() {
System.out.println("进入 to_login");
ModelAndView mv = new ModelAndView();
mv.addObject("path", "/to_login/abc*");
mv.setViewName("login");
return mv;
}
@RequestMapping("/**")
public ModelAndView toLogin5() {
System.out.println("进入 /**");
ModelAndView mv = new ModelAndView();
mv.addObject("path", "/**");
mv.setViewName("login");
return mv;
}
@RequestMapping("/to_login/**")
public ModelAndView toLogin6() {
System.out.println("进入 /to_login/**");
ModelAndView mv = new ModelAndView();
mv.addObject("path", "/to_login/**");
mv.setViewName("login");
return mv;
}
@RequestMapping("/to_login/abc")
public ModelAndView toLogin7() {
System.out.println("进入 /to_login/abc");
ModelAndView mv = new ModelAndView();
mv.addObject("path", "/to_login/abc");
mv.setViewName("login");
return mv;
}
@RequestMapping("/**/abc")
public ModelAndView toLogin8() {
System.out.println("进入 /**/abc");
ModelAndView mv = new ModelAndView();
mv.addObject("path", "/**/abc");
mv.setViewName("login");
return mv;
}
@RequestMapping("/*/*")
public ModelAndView toLogin9() {
System.out.println("进入 /*/*");
ModelAndView mv = new ModelAndView();
mv.addObject("path", "/*/*");
mv.setViewName("login");
return mv;
}
}
Look at the ways in which different request addresses arrive:
0 notes
Photo

14 Tips for Writing Spring MVC Controllers ☞ http://bit.ly/2MWW7dw #SpringMVC #Java #Morioh
1 note
·
View note
Photo

Spring Boot vs. Spring MVC vs. Spring: How Do They Compare? ☞ http://on.geeklearn.net/3a6c6f1288 #SpringBoot #SpringMVC #Spring
#Spring Boot vs. Spring MVC vs. Spring#Spring Boot#Spring MVC#Spring#Spring Boot vs. Spring MVC#Spring Boot vs. Spring#Spring MVC vs. Spring
2 notes
·
View notes