SpringMVC(干货)

Spring mvc代码实例 spring mvc代码运用1、maven引入相关依赖2、spring配置文件2.1、spring-mvc.xml2.2、spring-dao.xml2.3、spring-service.xml3、mybatis配置文件3.1、mybatis-config.xml3.2、table1mapper.xml4、web.xml5、Table1实体类和Table1Dao6、Controller7、spring mvc拦截器8、项目结构图 spring mvc + mybatis 1、maven引入相关依赖 pom. 阅读详情

一、SpringMVC基础入门,创建一个HelloWorld程序

  1.首先,导入SpringMVC需要的jar包。

  2.添加Web.xml配置文件中关于SpringMVC的配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!--configure the setting of springmvcDispatcherServlet and configure the mapping-->
< servlet >
     < servlet-name >springmvc</ servlet-name >
     < servlet-class >org.springframework.web.servlet.DispatcherServlet</ servlet-class >
     < init-param >
           < param-name >contextConfigLocation</ param-name >
           < param-value >classpath:springmvc-servlet.xml</ param-value >
       </ init-param >
       <!-- <load-on-startup>1</load-on-startup> -->
</ servlet >
 
< servlet-mapping >
     < servlet-name >springmvc</ servlet-name >
     < url-pattern >/</ url-pattern >
</ servlet-mapping >

  3.在src下添加springmvc-servlet.xml配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<? xml version = "1.0" encoding = "UTF-8" ?>
 
     <!-- scan the package and the sub package -->
     < context:component-scan base-package = "test.SpringMVC" />
 
     <!-- don't handle the static resource -->
     < mvc:default-servlet-handler />
 
     <!-- if you use annotation you must configure following setting -->
     < mvc:annotation-driven />
     
     <!-- configure the InternalResourceViewResolver -->
     < bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver"
             id = "internalResourceViewResolver" >
         <!-- 前缀 -->
         < property name = "prefix" value = "/WEB-INF/jsp/" />
         <!-- 后缀 -->
         < property name = "suffix" value = ".jsp" />
     </ bean >
</ beans >

  4.在WEB-INF文件夹下创建名为jsp的文件夹,用来存放jsp视图。创建一个hello.jsp,在body中添加“Hello World”。

  5.建立包及Controller,如下所示

  6.编写Controller代码

1
2
3
4
5
6
7
8
9
@Controller
@RequestMapping ( "/mvc" )
public class mvcController {
 
     @RequestMapping ( "/hello" )
     public String hello(){       
         return "hello" ;
     }
}

  7.启动服务器,键入 http://localhost:8080/项目名/mvc/hello

 二、配置解析

  1.Dispatcherservlet

  DispatcherServlet是前置控制器,配置在web.xml文件中的。拦截匹配的请求,Servlet拦截匹配规则要自已定义,把拦截下来的请求,依据相应的规则分发到目标Controller来处理,是配置spring MVC的第一步。

  2.InternalResourceViewResolver

  视图名称解析器

  3.以上出现的注解

  @Controller 负责注册一个bean 到spring 上下文中

  @RequestMapping 注解为控制器指定可以处理哪些 URL 请求

 三、SpringMVC常用注解

  @Controller

  负责注册一个bean 到spring 上下文中

  @RequestMapping

  注解为控制器指定可以处理哪些 URL 请求

  @RequestBody

  该注解用于读取Request请求的body部分数据,使用系统默认配置的HttpMessageConverter进行解析,然后把相应的数据绑定到要返回的对象上 ,再把HttpMessageConverter返回的对象数据绑定到 controller中方法的参数上

  @ResponseBody

  该注解用于将Controller的方法返回的对象,通过适当的HttpMessageConverter转换为指定格式后,写入到Response对象的body数据区

  @ModelAttribute    

  在方法定义上使用 @ModelAttribute 注解:Spring MVC 在调用目标处理方法前,会先逐个调用在方法级上标注了@ModelAttribute 的方法

  在方法的入参前使用 @ModelAttribute 注解:可以从隐含对象中获取隐含的模型数据中获取对象,再将请求参数 –绑定到对象中,再传入入参将方法入参对象添加到模型中 

  @RequestParam 

  在处理方法入参处使用 @RequestParam 可以把请求参 数传递给请求方法

  @PathVariable

  绑定 URL 占位符到入参

  @ExceptionHandler

  注解到方法上,出现异常时会执行该方法

  @ControllerAdvice

  使一个Contoller成为全局的异常处理类,类中用@ExceptionHandler方法注解的方法可以处理所有Controller发生的异常

 四、自动匹配参数

1
2
3
4
5
6
//match automatically
@RequestMapping ( "/person" )
public String toPerson(String name, double age){
     System.out.println(name+ " " +age);
     return "hello" ;
}

 五、自动装箱

  1.编写一个Person实体类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package test.SpringMVC.model;
 
public class Person {
     public String getName() {
         return name;
     }
     public void setName(String name) {
         this .name = name;
     }
     public int getAge() {
         return age;
     }
     public void setAge( int age) {
         this .age = age;
     }
     private String name;
     private int age;
     
}

  2.在Controller里编写方法

1
2
3
4
5
6
//boxing automatically
@RequestMapping ( "/person1" )
public String toPerson(Person p){
     System.out.println(p.getName()+ " " +p.getAge());
     return "hello" ;
}

 六、使用InitBinder来处理Date类型的参数

1
2
3
4
5
6
7
8
9
10
11
12
13
//the parameter was converted in initBinder
@RequestMapping ( "/date" )
public String date(Date date){
     System.out.println(date);
     return "hello" ;
}
    
//At the time of initialization,convert the type "String" to type "date"
@InitBinder
public void initBinder(ServletRequestDataBinder binder){
     binder.registerCustomEditor(Date. class , new CustomDateEditor( new SimpleDateFormat( "yyyy-MM-dd" ),
             true ));
}

 七、向前台传递参数

1
2
3
4
5
6
7
8
9
//pass the parameters to front-end
@RequestMapping ( "/show" )
public String showPerson(Map<String,Object> map){
     Person p = new Person();
     map.put( "p" , p);
     p.setAge( 20 );
     p.setName( "jayjay" );
     return "show" ;
}

  前台可在Request域中取到"p"

 八、使用Ajax调用

1
2
3
4
5
6
7
8
9
//pass the parameters to front-end using ajax
@RequestMapping ( "/getPerson" )
public void getPerson(String name,PrintWriter pw){
     pw.write( "hello," +name);       
}
@RequestMapping ( "/name" )
public String sayHello(){
     return "name" ;
}

  前台用下面的Jquery代码调用

1
2
3
4
5
6
7
$( function (){
     $( "#btn" ).click( function (){
        $.post( "mvc/getPerson" ,{name:$( "#name" ).val()}, function (data){
             alert(data);
         });
     });
});

 九、在Controller中使用redirect方式处理请求

1
2
3
4
5
//redirect
@RequestMapping ( "/redirect" )
public String redirect(){
     return "redirect:hello" ;
}

 十、文件上传

  1.需要导入两个jar包

  2.在SpringMVC配置文件中加入

1
2
3
4
<!-- upload settings -->
< bean id = "multipartResolver"  class = "org.springframework.web.multipart.commons.CommonsMultipartResolver" >
     < property name = "maxUploadSize" value = "102400000" ></ property >
</ bean >

  3.方法代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
@RequestMapping (value= "/upload" ,method=RequestMethod.POST)
public String upload(HttpServletRequest req) throws Exception{
     MultipartHttpServletRequest mreq = (MultipartHttpServletRequest)req;
     MultipartFile file = mreq.getFile( "file" );
     String fileName = file.getOriginalFilename();
     SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMddHHmmss" );       
     FileOutputStream fos = new FileOutputStream(req.getSession().getServletContext().getRealPath( "/" )+
             "upload/" +sdf.format( new Date())+fileName.substring(fileName.lastIndexOf( '.' )));
     fos.write(file.getBytes());
     fos.flush();
     fos.close();
     
     return "hello" ;
}

  4.前台form表单

1
2
3
4
< form action = "mvc/upload" method = "post" enctype = "multipart/form-data" >
     < input type = "file" name = "file" >< br >
     < input type = "submit" value = "submit" >
</ form >

 十一、使用@RequestParam注解指定参数的name

1
2
3
4
5
6
7
8
9
10
@Controller
@RequestMapping ( "/test" )
public class mvcController1 {
     @RequestMapping (value= "/param" )
     public String testRequestParam( @RequestParam (value= "id" ) Integer id,
             @RequestParam (value= "name" )String name){
         System.out.println(id+ " " +name);
         return "/hello" ;
     }   
}

 十二、RESTFul风格的SringMVC

  1.RestController

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
@Controller
@RequestMapping ( "/rest" )
public class RestController {
     @RequestMapping (value= "/user/{id}" ,method=RequestMethod.GET)
     public String get( @PathVariable ( "id" ) Integer id){
         System.out.println( "get" +id);
         return "/hello" ;
     }
     
     @RequestMapping (value= "/user/{id}" ,method=RequestMethod.POST)
     public String post( @PathVariable ( "id" ) Integer id){
         System.out.println( "post" +id);
         return "/hello" ;
     }
     
     @RequestMapping (value= "/user/{id}" ,method=RequestMethod.PUT)
     public String put( @PathVariable ( "id" ) Integer id){
         System.out.println( "put" +id);
         return "/hello" ;
     }
     
     @RequestMapping (value= "/user/{id}" ,method=RequestMethod.DELETE)
     public String delete( @PathVariable ( "id" ) Integer id){
         System.out.println( "delete" +id);
         return "/hello" ;
     }
     
}

  2.form表单发送put和delete请求

  在web.xml中配置

1
2
3
4
5
6
7
8
9
<!-- configure the HiddenHttpMethodFilter,convert the post method to put or delete -->
< filter >
     < filter-name >HiddenHttpMethodFilter</ filter-name >
     < filter-class >org.springframework.web.filter.HiddenHttpMethodFilter</ filter-class >
</ filter >
< filter-mapping >
     < filter-name >HiddenHttpMethodFilter</ filter-name >
     < url-pattern >/*</ url-pattern >
</ filter-mapping >

  在前台可以用以下代码产生请求

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
< form action = "rest/user/1" method = "post" >
     < input type = "hidden" name = "_method" value = "PUT" >
     < input type = "submit" value = "put" >
</ form >
 
< form action = "rest/user/1" method = "post" >
     < input type = "submit" value = "post" >
</ form >
 
< form action = "rest/user/1" method = "get" >
     < input type = "submit" value = "get" >
</ form >
 
< form action = "rest/user/1" method = "post" >
     < input type = "hidden" name = "_method" value = "DELETE" >
     < input type = "submit" value = "delete" >
</ form >

 十三、返回json格式的字符串

  1.导入以下jar包

  2.方法代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
@Controller
@RequestMapping ( "/json" )
public class jsonController {
     
     @ResponseBody
     @RequestMapping ( "/user" )
     public  User get(){
         User u = new User();
         u.setId( 1 );
         u.setName( "jayjay" );
         u.setBirth( new Date());
         return u;
     }
}

 十四、异常的处理

  1.处理局部异常(Controller内)

1
2
3
4
5
6
7
8
9
10
11
12
13
@ExceptionHandler
public ModelAndView exceptionHandler(Exception ex){
     ModelAndView mv = new ModelAndView( "error" );
     mv.addObject( "exception" , ex);
     System.out.println( "in testExceptionHandler" );
     return mv;
}
    
@RequestMapping ( "/error" )
public String error(){
     int i = 5 / 0 ;
     return "hello" ;
}

  2.处理全局异常(所有Controller)

1
2
3
4
5
6
7
8
9
10
@ControllerAdvice
public class testControllerAdvice {
     @ExceptionHandler
     public ModelAndView exceptionHandler(Exception ex){
         ModelAndView mv = new ModelAndView( "error" );
         mv.addObject( "exception" , ex);
         System.out.println( "in testControllerAdvice" );
         return mv;
     }
}

  3.另一种处理全局异常的方法

  在SpringMVC配置文件中配置

1
2
3
4
5
6
7
8
<!-- configure SimpleMappingExceptionResolver -->
< bean class = "org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" >
     < property name = "exceptionMappings" >
         < props >
             < prop key = "java.lang.ArithmeticException" >error</ prop >
         </ props >
     </ property >
</ bean >

  error是出错页面

 十五、设置一个自定义拦截器

  1.创建一个MyInterceptor类,并实现HandlerInterceptor接口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class MyInterceptor implements HandlerInterceptor {
 
     @Override
     public void afterCompletion(HttpServletRequest arg0,
             HttpServletResponse arg1, Object arg2, Exception arg3)
             throws Exception {
         System.out.println( "afterCompletion" );
     }
 
     @Override
     public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
             Object arg2, ModelAndView arg3) throws Exception {
         System.out.println( "postHandle" );
     }
 
     @Override
     public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1,
             Object arg2) throws Exception {
         System.out.println( "preHandle" );
         return true ;
     }
 
}

  2.在SpringMVC的配置文件中配置

1
2
3
4
5
6
7
<!-- interceptor setting -->
< mvc:interceptors >
     < mvc:interceptor >
         < mvc:mapping path = "/mvc/**" />
         < bean class = "test.SpringMVC.Interceptor.MyInterceptor" ></ bean >
     </ mvc:interceptor >       
</ mvc:interceptors >

  3.拦截器执行顺序

 十六、表单的验证(使用Hibernate-validate)及国际化

  1.导入Hibernate-validate需要的jar包

(未选中不用导入)

  2.编写实体类User并加上验证注解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class User {
     public int getId() {
         return id;
     }
     public void setId( int id) {
         this .id = id;
     }
     public String getName() {
         return name;
     }
     public void setName(String name) {
         this .name = name;
     }
     public Date getBirth() {
         return birth;
     }
     public void setBirth(Date birth) {
         this .birth = birth;
     }
     @Override
     public String toString() {
         return "User [id=" + id + ", name=" + name + ", birth=" + birth + "]" ;
     }   
     private int id;
     @NotEmpty
     private String name;
 
     @Past
     @DateTimeFormat (pattern= "yyyy-MM-dd" )
     private Date birth;
}

  ps:@Past表示时间必须是一个过去值

  3.在jsp中使用SpringMVC的form表单

1
2
3
4
5
6
< form:form action = "form/add" method = "post" modelAttribute = "user" >
     id:< form:input path = "id" />< form:errors path = "id" />< br >
     name:< form:input path = "name" />< form:errors path = "name" />< br >
     birth:< form:input path = "birth" />< form:errors path = "birth" />
     < input type = "submit" value = "submit" >
</ form:form >

  ps:path对应name

  4.Controller中代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@Controller
@RequestMapping ( "/form" )
public class formController {
     @RequestMapping (value= "/add" ,method=RequestMethod.POST)   
     public String add( @Valid User u,BindingResult br){
         if (br.getErrorCount()> 0 ){           
             return "addUser" ;
         }
         return "showUser" ;
     }
     
     @RequestMapping (value= "/add" ,method=RequestMethod.GET)
     public String add(Map<String,Object> map){
         map.put( "user" , new User());
         return "addUser" ;
     }
}

  ps:

  1.因为jsp中使用了modelAttribute属性,所以必须在request域中有一个"user".

  2.@Valid 表示按照在实体上标记的注解验证参数

  3.返回到原页面错误信息回回显,表单也会回显

  5.错误信息自定义

  在src目录下添加locale.properties

NotEmpty.user.name=name can't not be empty
Past.user.birth=birth should be a past value
DateTimeFormat.user.birth=the format of input is wrong
typeMismatch.user.birth=the format of input is wrong
typeMismatch.user.id=the format of input is wrong

  在SpringMVC配置文件中配置

1
2
3
4
<!-- configure the locale resource -->
< bean id = "messageSource" class = "org.springframework.context.support.ResourceBundleMessageSource" >
     < property name = "basename" value = "locale" ></ property >
</ bean >

  6.国际化显示

  在src下添加locale_zh_CN.properties

username=账号
password=密码

  locale.properties中添加

username=user name
password=password

  创建一个locale.jsp

1
2
3
4
< body >
   < fmt:message key = "username" ></ fmt:message >
   < fmt:message key = "password" ></ fmt:message >
</ body >

  在SpringMVC中配置

1
2
<!-- make the jsp page can be visited -->
< mvc:view-controller path = "/locale" view-name = "locale" />

  让locale.jsp在WEB-INF下也能直接访问

  最后,访问locale.jsp,切换浏览器语言,能看到账号和密码的语言也切换了

 十七、压轴大戏--整合SpringIOC和SpringMVC

  1.创建一个test.SpringMVC.integrate的包用来演示整合,并创建各类

  2.User实体类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class User {
     public int getId() {
         return id;
     }
     public void setId( int id) {
         this .id = id;
     }
     public String getName() {
         return name;
     }
     public void setName(String name) {
         this .name = name;
     }
     public Date getBirth() {
         return birth;
     }
     public void setBirth(Date birth) {
         this .birth = birth;
     }
     @Override
     public String toString() {
         return "User [id=" + id + ", name=" + name + ", birth=" + birth + "]" ;
     }   
     private int id;
     @NotEmpty
     private String name;
 
     @Past
     @DateTimeFormat (pattern= "yyyy-MM-dd" )
     private Date birth;
}

  3.UserService类

1
2
3
4
5
6
7
8
9
10
@Component
public class UserService {
     public UserService(){
         System.out.println( "UserService Constructor...\n\n\n\n\n\n" );
     }
     
     public void save(){
         System.out.println( "save" );
     }
}

  4.UserController

1
2
3
4
5
6
7
8
9
10
11
12
13
@Controller
@RequestMapping ( "/integrate" )
public class UserController {
     @Autowired
     private UserService userService;
     
     @RequestMapping ( "/user" )
     public String saveUser( @RequestBody @ModelAttribute User u){
         System.out.println(u);
         userService.save();
         return "hello" ;
     }
}

  5.Spring配置文件

  在src目录下创建SpringIOC的配置文件applicationContext.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<? xml version = "1.0" encoding = "UTF-8" ?>
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
         "
         xmlns:util = "http://www.springframework.org/schema/util"
         xmlns:p = "http://www.springframework.org/schema/p"
         xmlns:context = "http://www.springframework.org/schema/context"   
         >
     < context:component-scan base-package = "test.SpringMVC.integrate" >
         < context:exclude-filter type = "annotation"
             expression = "org.springframework.stereotype.Controller" />
         < context:exclude-filter type = "annotation"
             expression = "org.springframework.web.bind.annotation.ControllerAdvice" />       
     </ context:component-scan >
     
</ beans >

  在Web.xml中添加配置

1
2
3
4
5
6
7
8
<!-- configure the springIOC -->
< listener >
     < listener-class >org.springframework.web.context.ContextLoaderListener</ listener-class >
</ listener >
< context-param > 
   < param-name >contextConfigLocation</ param-name > 
   < param-value >classpath:applicationContext.xml</ param-value >
</ context-param >

  6.在SpringMVC中进行一些配置,防止SpringMVC和SpringIOC对同一个对象的管理重合

1
2
3
4
5
6
7
<!-- scan the package and the sub package -->
     < context:component-scan base-package = "test.SpringMVC.integrate" >
         < context:include-filter type = "annotation"
             expression = "org.springframework.stereotype.Controller" />
         < context:include-filter type = "annotation"
             expression = "org.springframework.web.bind.annotation.ControllerAdvice" />
     </ context:component-scan >

 十八、SpringMVC详细运行流程图

 十九、SpringMVC与struts2的区别

  1、springmvc基于方法开发的,struts2基于类开发的。springmvc将url和controller里的方法映射。映射成功后springmvc生成一个Handler对象,对象中只包括了一个method。方法执行结束,形参数据销毁。springmvc的controller开发类似web service开发。

  2、springmvc可以进行单例开发,并且建议使用单例开发,struts2通过类的成员变量接收参数,无法使用单例,只能使用多例。

  3、经过实际测试,struts2速度慢,在于使用struts标签,如果使用struts建议使用jstl。


本文转自--http://www.admin10000.com/document/6436.html

【Spring MVC】这一篇,带你从入门到进阶(附 Restful) Spring MVC教学详解,从入门到进阶! 阅读详情

相关推荐

SpringMvc项目实例

这段时间在学习javaweb的一些知识,然后接触到了springmvc框架。框架的创建和配置一直是新手入门的一个难题,所以我就写一下我的配置过程,以供参考,另外因为spring4的新特性可以用java来配置,网上相关资料较少,所以我参考了很多博文后,把xml和java两种配置方式都试了一下。

SpringBoot版本升级引起的FileNotFoundException——WebMvcConfigurerAdapter.class

就是这了,Jar里面没法排掉某个特定的类,只能在当前项目中创建一个和这个类一模一样的类,代码改成自己想要的。因为Java中,某个类(同一个classloader+全限定名)已经被加载了,就不会再次被加载,项目中的类加载优先于Jar包中的,又都是同一个类加载器加载,所以会优先加载到项目中类,Jar中的则不会被加载了,曲线救国。这TM和大海捞针没区别啊,这项目光依赖自己的包就几十个,大部分都是公司内部包,我都没有源码,这可怎么找啊,只能去报异常的地方碰碰运气了。里面翻找了一下,感觉最有价值的就是里面的。

BLF2 2583

海思Hi3061M MCU:为高速吹风筒市场注入智能动力

此外,海思还提供了丰富的软件开发工具和生态环境组件,帮助开发者快速实现复杂功能。高速吹风筒因其高效的风力和快速的干燥效果,近年来在市场上越来越受欢迎。然而,传统的高速吹风筒在性能、噪音和使用寿命等方面仍有改进的空间。凭借其高性能、低功耗、低噪声和易用的开发工具,为高速吹风筒市场带来了全新的解决方案。这不仅提高了用户的使用体验,还延长了电机的使用寿命。这不仅减少了电机的电磁噪声,还提高了电机的运行效率。还支持风机顺逆风启动适配多种电阻范围的电机,进一步提高了吹风筒的适用性和灵活性。

2401_83448585的博客 2016

WebMvcConfigurer.class (does not exist)

报错信息 Failed to process import candidates for configuration class [com.mw.coinquote.server.CoinQuoteServerApplication]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/web/servlet/config/annotation/WebMvcConfigur

weixin_45429720的博客 1万+

利用Matlab绘制非线性系统相图:从理论到实践

本文详细介绍了如何利用Matlab进行非线性系统的相图绘制与相平面分析。从理论基础的状态空间转换出发,通过无阻尼线性谐振子和范德波尔振荡器等实例,手把手演示了使用ode45求解器绘制相图、分析平衡点与极限环的完整流程,并分享了方向场绘制、参数分岔探索及常见错误解决方案等高级技巧,为动力学系统分析与控制设计提供了直观强大的可视化工具。

yhn456789的博客 905

无人机频谱侦测与智能识别技术实战解析

本文深入解析无人机频谱侦测与智能识别技术实战应用,涵盖无线电侦测、信号处理和定位技术等核心内容。通过频谱分析、特征提取和机器学习算法优化,实现高精度无人机识别与定位,并分享复杂环境下的应对策略和系统集成经验。

weixin_28419039的博客 488

【干货】springmvc架构

框架结构 【流程图说明】 1.用户发送请求至 前端控制器DispatcherServlet。 2.前端控制器DispatcherServlet收到请求后调用处理器映射器HandlerMapping。 3.处理器映射器HandlerMapping根据请求的Url找到具体的处理器,生成处理器对象Handler及处理器拦截器HandlerIntercepter(如果有则生成)一并返回给前端控制器Dis...

sunwenxu的博客 198

华为2021年天线工程师笔试题目回忆总结(持续更新)

1. 判定长线和短线 所谓长线是指传输线的几何长度和线上传输电磁波的波长的比值(即电长度)大于或接近于1。反之称为短线。是相对于波长而言的。 1000m的传输线,对于频率为50hz(即波长为6000km)的交流电来说,仍远小于波长,应视为短线。长线和短线的区别还在于:长线为分布参数电路,而短线是集总参数电路。 2. 判定传输线的容性和感性 传输线上的输入阻抗具有以下特点: 1/4波长变换性:感性负载与容性负载变换,开路与短路变换; 1/2波长重复性:相距1/2波长的整数倍的两个点输入阻抗都相等。1/4开路传

ludashi3的博客 9530

SpringMVC干货系列(一)【入门篇】

文章目录一、什么是SpringMVC二、为什么要学习SpringMVC三、SpringMVC的入门3.1开发环境3.2开发步骤3.2.1创建Dynamic web项目3.2.2导入springmvc的jar包3.2.3编写TestController类3.2.4创建hello.jsp页面3.2.5创建与配置springmvc.xml核心配置文件3.2.6在web.xml中配置前端控制器3.2.7启...

凌枫ozo的博客 278

StarRocks FE启动异常

服务器断电,StarRocks FE 启动失败。

qq_15138049的博客 1112

C#上位机+国产PLC+AI:构建自主可控的智能生产线解决方案

全栈国产化智能产线方案并非遥不可及,基于成熟的国产硬件、丰富的.NET生态、快速发展的国产大模型,完全可以搭建出稳定可靠且具备智能能力的生产系统。落地建议采用三步走策略:基础国产化阶段:替换PLC与上位机,实现基础监控与控制功能,解决卡脖子问题,快速验证国产化方案稳定性数据沉淀阶段:完善数据采集与存储,建立设备台账、故障库、工艺库,积累高质量领域数据智能升级阶段:引入国产大模型与知识库,落地故障诊断、工艺优化、预测性维护等智能应用,持续提升产线效率。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 517

SpringMVC干货

Spring MVC 是 MVC(Model-View-Controller)设计模式的 Web 框架实现:① 发起请求② 更新数据③ 返回数据④ 选择视图 + 填充模型⑤ 响应用户浏览器Controller 控制器接收请求、参数解析调用业务逻辑Model 模型Service/DAO 层承载业务数据View 视图渲染 HTML / 输出 JSON返回响应MVC 的核心价值是关注点分离(Separation of Concerns):业务逻辑(Model)、界面呈现(View)、请求编排(Controller

zhzhxian的博客 221

LVGL 9Text Area 控件 (lv_textarea) 使用指南

是一个可编辑的文本输入控件,通常用于在用户界面中输入和编辑多行或单行文本。该控件支持文本插入、删除、光标控制、文本选择、密码输入等功能。它的文本内容可以通过键盘、API 或事件进行修改,还可以设置最大文本长度、占位符文本和密码模式等。是一个强大且灵活的文本输入控件,适用于多种用户输入场景,支持文本插入、删除、光标控制、密码输入等功能。通过 LittlevGL 提供的丰富 API,开发者可以自定义文本区域的外观和行为,实现复杂的文本输入需求。

m0_62599305的博客 1673

干货!从上帝视角来看SpringMVC

SpringMVC核心流程图 简单总结 首先请求进入DispatcherServlet 由DispatcherServlet 从HandlerMappings中提取对应的Handler 此时只是获取到了对应的Handle,然后得去寻找对应的适配器,即:HandlerAdapter 拿到对应HandlerAdapter时,这时候开始调用对应的Handler处理业务逻辑了(这时候实际上已经执行完了我...

T_LJAVA的博客 277

基于传感器数据实现火灾报警预测分析

火警 系统当检测到烟雾、火灾、一氧化碳或其他与火灾有关或一般通知的紧急情况时,向人们发出警告

DT程序员的博客 721

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

干货| SpringMVC框架是干什么的?有哪些优点?

目前企业当中有80%的项目使用的都是SpringMVC框架,这么多公司都使用SpringMVC框架来开发项目,SpringMVC框架必然有他的过人之处。今天让我们一起来看看SpringM...

传智播客的专栏 4551

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Java最全SpringMVC的搭建及入门,干货精讲

虽然面试套路众多,但对于技术面试来说,主要还是考察一个人的技术能力和沟通能力。不同类型的面试官根据自身的理解问的问题也不尽相同,没有规律可循。上面提到的关于这些JAVA基础、三大框架、项目经验、并发编程、JVM及调优、网络、设计模式、spring+mybatis源码解读、Mysql调优、分布式监控、消息队列、分布式存储等等面试题笔记及资料。

2401_84003839的博客 794

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

idea tomcat springmvc 无法注入bean_SpringMVC干货系列:从零搭建SpringMVC+mybatis

作者:嘟爷MD链接:https://www.jianshu.com/p/7bed8cb98144前言上篇文章介绍了maven WEB 项目的搭建,基本的配置文件也都贴出来了,今天就来介绍下SpringMVC的工作原理以及工作中常用的注解。为以后开发打下坚实的基础。正文SpringMVC框架介绍SpringMVC就是通过DispatcherServlet将一堆组件串联起来的Web框架。Spring ...

weixin_39942318的博客 190

SSM系列6 Spring SpringMVC Mybatis 整合干货

前面学习了很多在SSM中要使用的东西,Mybatis,Freemarker等,今天终于到了要整合一整个可用框架的时候了 Spring SpringMVC Mybatis整合Spring SpringMVC 整合创建项目与整体目录与所需文件pom.xml配置打包方式改为war增加jetty插件导入jetty的webdefault.xml增加SpringMVC配置加入json序列化支持包加入Freem...

星夜 330

SpringMVC 干货:@RequestMapping 注解的核心用法

是实现 URL 路径与控制器方法映射的核心注解。以上述代码为例,通过这个路径映射我们可以找到UserController这个类,以及该类中的m1方法。可标注在类和方法上,两者的路径会自动拼接形成类上的定义了方法上的定义了最终完整访问路径为:类路径+方法路径这个路径有方法路径和类路径,通常我们会在这两个地方都进行声明。这是为了提高可读性。需要注意的是当资源路径=方法路径+类路径。

wxy963的博客 498

springmvc面试问题,,干货满满

(1)自增主键,数据在物理结构上是顺序存储,性能好,占用空间小。比如:tom 年龄为 22,事务 A 修改 tom 年龄为 30,此时还未提交到数据库,此时事务 B 获取 tom 年龄,得到的是 30,事务 A 回滚数据,数据库的数据依旧是 22,但事务 B 拿到的数据是 30,这就是脏读,读错了数据。(1)脏读:脏读 指的是当一个事务正在访问某数据,并对这个数据进行的修改,且这条数据还未提交到数据库中,此时若另一个事务也访问到这条数据,获取到的是这条被修改的数据,此时得到的数据不对,即脏读。

F1520080的博客 850

SpringMVC框架中的常用注解(全是干货,干的要死!)

SpringMVC框架中的常用注解(全是干货,干的要死!)

qq_46138492的博客 3954

SpringMVC(一) 构建项目 (干货,超详细)

idea创建SpringMVC项目

qq_19286785的博客 1579

springmvc不返回视图_这套SpringMvc面试题你懂多少(干货)

1、什么是 SpringMvc?SpringMvc 是 spring 的一个模块,基于 MVC 的一个框架,无需中间整合层来整2、Spring MVC 的优点:1)它是基于组件技术的.全部的应用对象,无论控制器和视图,还是业务对象之类的都是 组件.并且和 Spring 提供的其他基础结构紧密集成.2)不依赖于 Servlet API(目标虽是如此,但是在实现的时候确实是依赖于 Servlet 的)...

weixin_39877504的博客 122

springmvc拦截器及源码分析【技术点干货】

拦截器常用于初始化资源,权限监控,会话设置,资源清理等的功能设置,就需要我们对它的执行顺序完全掌握,我们通过源码可以看到,拦截器类似于对我们业务方法的环绕通知效果,并且是通过循环收集好的拦截器集合来控制每个拦截器方法的执行顺序,进而可以真正做到深入掌握拦截器的执行机制!

zy1992As的博客 385

springMVC干货系列:从零搭建springMVC+mybatis(二):springMVC原理解析及常用注解(转)

前言 上篇文章介绍了maven WEB 项目的搭建,基本的配置文件也都贴出来了,今天就来介绍下SpringMVC的工作原理以及工作中常用的注解。为以后开发打下坚实的基础。 正文 SpringMVC框架介绍 SpringMVC就是通过DispatcherServlet将一堆组件串联起来的Web框架。 Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring ...

hahavslinb的专栏 226
上一篇: IOS知识点总结
下一篇: ASP.NET MVC路由配置详解
Footloose_
博客等级 码龄10年 254粉丝 11原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值