当前位置: 首页 > news >正文

百度 移动网站优化建设公司网站大概需要多少钱?

百度 移动网站优化,建设公司网站大概需要多少钱?,本田汽车网站建设,网页设计工资2019Controller 是SpringMVC注解,标记一个类作为Web控制器(Controller),负责处理HTTP请求并返回响应结果 在SpringMVC中,控制器类的主要职责是: 1、接收来自客户端的HTTP请求 2、调用服务层或其他业务逻辑组件…

@ControllerSpringMVC注解,标记一个类作为Web控制器(Controller),负责处理HTTP请求并返回响应结果

SpringMVC中,控制器类的主要职责是:
1、接收来自客户端的HTTP请求
2、调用服务层或其他业务逻辑组件
3、根据操作结果准备视图模型数据(Model),将控制权转移给视图解析器(View Resolver)渲染视图
4、操作结果直接返回HTTP响应(例如JSON、XML等)。

使用样例

简单页面渲染

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;@Controller
public class SimplePageController {@GetMapping("/hello")public String displayHelloPage() {// ...return "hello"; // 假设有一个名为"hello.html"的模板文件在视图解析器配置的路径下}
}

结合ModelAndView对象使用

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;@Controller
public class UserViewController {@GetMapping("/users/{id}")public ModelAndView showUser(@PathVariable Long id, Model model) {// 假设userService.find(id)获取用户信息User user = userService.find(id);// 将用户信息添加到模型中供视图模板使用model.addAttribute("user", user);// 返回包含视图名称和模型数据的ModelAndView对象return new ModelAndView("user-profile", model.asMap());}
}

处理POST请求并返回重定向

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;@Controller
@RequestMapping("/login")
public class LoginController {@GetMappingpublic String showLoginForm() {// 显示登录表单页面return "login";}@PostMappingpublic String processLogin(@RequestParam("username") String username,@RequestParam("password") String password,RedirectAttributes redirectAttrs) {// 假设userService.authenticate(username, password)进行身份验证if (userService.authenticate(username, password)) {// 登录成功,重定向到主页redirectAttrs.addFlashAttribute("successMessage", "Welcome, you have successfully logged in!");return "redirect:/home";} else {// 登录失败,将错误信息添加到模型中以便在重定向后的页面显示redirectAttrs.addFlashAttribute("errorMessage", "Invalid credentials. Please try again.");return "redirect:/login";}}
}

结合@RequestBody处理JSON数据

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;@RestController
public class UserController {@PostMapping("/users")public ResponseEntity<User> createUser(@RequestBody CreateUserRequest request) {User user = userService.createUser(request.getName(), request.getEmail());return ResponseEntity.ok(user);}static class CreateUserRequest {private String name;private String email;// getters and setters}
}
http://www.hkea.cn/news/756576/

相关文章:

  • 品牌建设浅谈seo网络营销外包
  • 昆山网站建设兼职千锋教育的官网
  • cm域名做网站盘古百晋广告营销是干嘛
  • 网站栏目策划企业网络营销方案
  • 网站自动采集指标sem广告投放是做什么的
  • 想做一个个人网站怎么做培训学校
  • 网站开发ipv6升级如何创建自己的小程序
  • 做网站需要备案吗外贸网站推广与优化
  • 独立网站建设流程b站视频推广网站动漫
  • 泰安诚信的网站建设b站推广入口2023年
  • 高校网站建设资料库东莞seo推广公司
  • 电子印章手机在线制作软件四川seo整站优化费用
  • 个人风采网站制作外贸网站平台哪个好
  • 沈阳企业建站谷歌推广和seo
  • .la域名做的网站如何快速推广app
  • 广州优化网站建设怎么用手机制作网站
  • 做微网站的第三方学网络营销
  • 湖南做网站的公司有哪些搜索引擎是什么
  • flash网站管理系统seo优化排名易下拉用法
  • 永年网站建设友链互换平台推荐
  • 企业网站的设计公司网络广告营销的典型案例
  • 高校思政主题网站建设的意义关键词歌词任然
  • 哪里做网站比较快2345网址导航下载桌面
  • 广州建设委员会官方网站凡科建站下载
  • 全球做网站的公司排名百度一下你就知道官网
  • 小企业网站价格免费发链接的网站
  • 买了空间和域名 怎么做网站哪家公司网站做得好
  • 网站备案是否关闭衡阳网站建设公司
  • 遂昌建设局网站个人怎么做网站
  • 软件开发和网站建设网络营销的未来6个发展趋势