spring mvc

  • G5_370050
    了解作者
  • 25MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-13 10:12
    上传日期
spring mvc
SpringMvcT.rar
内容介绍
package com.mvc.rest; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import javax.servlet.http.HttpSession; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import com.tool.MyException; @Controller @RequestMapping("/helloworld") public class HelloWorldController { @RequestMapping(value = "/index", method = RequestMethod.GET) public String hello() throws MyException { // if (1 == 1) { // throw new MyException("我是自定义异常", "001"); // } return "/index"; // return "/welcome"; } @RequestMapping(value = "/myhello", method = RequestMethod.GET) public ModelAndView myhello() { ModelMap modelMap = new ModelMap(); modelMap.put("name", "吴继芳"); modelMap.put("age", 20); List<String> list = new ArrayList<String>(); list.add("code"); list.add("game"); list.add("read"); list.add("study"); modelMap.put("list", list); Map<String, String> map = new HashMap<String, String>(); map.put("1", "a1"); map.put("2", "a2"); map.put("3", "a3"); map.put("4", "a4"); modelMap.put("myMap", map); return new ModelAndView("/myhello", modelMap); } /** * session操作 * * @param httpSession * @return */ @RequestMapping(value = "/mysession", method = RequestMethod.GET) public ModelAndView mySession(HttpSession httpSession) { ModelMap modelMap = new ModelMap(); UUID uuid = UUID.randomUUID(); String a = uuid.toString(); httpSession.setAttribute("si", a); modelMap.put("si", httpSession.getAttribute("si")); return new ModelAndView("/mysession", modelMap); } @RequestMapping(value = "/rest", produces = "text/plain;charset=UTF-8") public @ResponseBody String rest() { return "你好!rest"; } @RequestMapping(value = "/rest{id}", produces = "text/plain;charset=UTF-8") public @ResponseBody String restT(@PathVariable int id) { return "你好!rest" + id; } /** * @return json */ @RequestMapping(value = "/rt") public @ResponseBody Person rt(@RequestBody Person p) { // Person rt() { System.out.println(p.getName()); UUID uuid = UUID.randomUUID(); Person person = new Person(); person.setName("吴继芳后台返回" + uuid.toString()); person.setSex("男"); person.setAge(30); person.setId(11); return person; } @RequestMapping(value = "/rtid{id}") public @ResponseBody Person rtid(@PathVariable int id) { System.out.println(id); UUID uuid = UUID.randomUUID(); Person person = new Person(); person.setName("吴继芳后台返回" + uuid.toString()); person.setSex("男"); person.setAge(30); person.setId(id); return person; } @RequestMapping(value = "/rtpost") public @ResponseBody Person rtpost(@RequestParam int id, @RequestParam String name) { System.out.println(id + name); UUID uuid = UUID.randomUUID(); Person person = new Person(); person.setName("吴继芳后台返回" + uuid.toString()); person.setSex("男"); person.setAge(30); person.setId(id); return person; } }
评论
    相关推荐
    • spring mvc
      spring mvc简单实例
    • Spring MVC
      Spring MVC使用注解配置。。。。。。。。。。。。。。。。。。。。。
    • spring mvc
      本代码是spring mvc的一个小demo 只是完成mvc的一个实例。没有复杂的业务逻辑 本demo只是适合刚学习Spring mvc的同行
    • spring mvc
      spring mvc spring mvcspring mvc
    • Spring MVC
      一个简单的spring mvc登录案例,采用的是annotation方式。
    • spring mvc
      spring mvc框架代码实例,测试可用。
    • spring mvc
      spring mvc 开发所需要的全部工具、jar包
    • spring mvc
      这是一个spring mvc3.04例子。这个例子简单,弹性好,易于扩展。好理解。是我在开发时项目例子。
    • spring mvc
      spring mvc最小代码。spring mvc最小代码。spring mvc最小代码。spring mvc最小代码。
    • SIM800C_MQTT.rar
      使用SIM800C模块,使用MQTT协议,连接中国移动onenet平台,能实现数据的订阅、发布、存储等