基于注解的spring MVC程序详解编程语言
2023-06-13 09:20:23 时间
beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
!-- 配置处理器映射器 -- !-- 使用RequestMappingHandlerMapping需要在Handler [email protected],[email protected] -- bean /bean !-- 配置处理器适配器 -- !-- RequestMappingHandlerAdapter,不要求Handler实现任何接口,它需要和RequestMappingHandlerMapping注解映射器配对使用,主要解析Handler方法中的形参 -- bean
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; @Controller public class HelloController { @RequestMapping("/queryItems") public ModelAndView queryItems(){ //商品列表 List Item itemsList = new ArrayList Item Item items_1 = new Item(); items_1.setName("联想笔记本"); items_1.setPrice(6000f); items_1.setDetail("ThinkPad T430 联想笔记本电脑!"); Item items_2 = new Item(); items_2.setName("苹果手机"); items_2.setPrice(5000f); items_2.setDetail("iphone6苹果手机!"); itemsList.add(items_1); itemsList.add(items_2); //创建modelAndView准备填充数据、设置视图 ModelAndView modelAndView = new ModelAndView(); //填充数据 modelAndView.addObject("itemsList", itemsList); //视图 modelAndView.setViewName("helloController"); return modelAndView;
!-- 配置处理器映射器 -- !-- 使用RequestMappingHandlerMapping需要在Handler [email protected],[email protected] -- bean /bean !-- 配置处理器适配器 -- !-- RequestMappingHandlerAdapter,不要求Handler实现任何接口,它需要和RequestMappingHandlerMapping注解映射器配对使用,主要解析Handler方法中的形参 -- bean
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; @Controller public class HelloController { @RequestMapping("/queryItems") public ModelAndView queryItems(){ //商品列表 List Item itemsList = new ArrayList Item Item items_1 = new Item(); items_1.setName("联想笔记本"); items_1.setPrice(6000f); items_1.setDetail("ThinkPad T430 联想笔记本电脑!"); Item items_2 = new Item(); items_2.setName("苹果手机"); items_2.setPrice(5000f); items_2.setDetail("iphone6苹果手机!"); itemsList.add(items_1); itemsList.add(items_2); //创建modelAndView准备填充数据、设置视图 ModelAndView modelAndView = new ModelAndView(); //填充数据 modelAndView.addObject("itemsList", itemsList); //视图 modelAndView.setViewName("helloController"); return modelAndView;
相关文章
- spring boot自动配置原理面试题_Spring boot面试
- Spring Boot+微信小程序_保存微信登录者的个人信息
- Spring MVC 框架学习(三)---- 我的第一个 Spring MVC 程序
- 创建Spring Boot应用
- spring注解有哪些_Spring 注解
- Spring StoredProcedure调用ORACLE存储过程或函数
- spring boot整合shiro_Spring框架介绍及使用
- 如何阅读 Spring Cloud OpenFein 源码
- 开源!一款基于Spring Boot的二维码生成和解析工具
- spring官方文档 中文_Spring软件
- Spring Boot Version Compatibility
- 【愚公系列】2023年04月 Java教学课程 142-Spring MVC框架的(文件上传下载、Restful风格API)
- Spring AOP详解编程语言
- spring中JdbcTemplate详解编程语言
- Redis集群集成Spring在Java中的使用详解编程语言
- Spring Cloud 入门教程(六): 用声明式REST客户端Feign调用远端HTTP服务详解编程语言
- spring-boot 访问时,加与不加项目名分析详解编程语言
- Spring Boot(二十):使用spring-boot-admin对spring-boot服务进行监控详解编程语言
- java spring boot 写入日志详解编程语言
- Spring整合Redis简单实现高效缓存(spring集成redis)
- spring架构利器:JFinal MySQL Spring(jfinalmysql)
- Spring Boot 2.x :通过 spring-boot-starter-hbase 集成 HBase
- Spring框架致力于搭建基于MSSQL的稳健开发体系(spring mssql)