首页 > 其他分享 >Controller使用模板

Controller使用模板

时间:2024-04-18 17:11:41浏览次数:24  
标签:name License Controller user 使用 org public 模板 String

/*
 * Copyright 2013-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.exam.demos.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author <a href="mailto:[email protected]">theonefx</a>
 */
@Controller
public class BasicController {

    // http://127.0.0.1:8080/hello?name=lisi
    @RequestMapping("/hello")
    @ResponseBody
    public String hello(@RequestParam(name = "name", defaultValue = "unknown user") String name) {
        return "Hello " + name;
    }

    // http://127.0.0.1:8080/user
    @RequestMapping("/user")
    @ResponseBody
    public User user() {
        User user = new User();
        user.setName("theonefx");
        user.setAge(666);
        return user;
    }

    // http://127.0.0.1:8080/save_user?name=newName&age=11
    @RequestMapping("/save_user")
    @ResponseBody
    public String saveUser(User u) {
        return "user will save: name=" + u.getName() + ", age=" + u.getAge();
    }

    // http://127.0.0.1:8080/html
    @RequestMapping("/html")
    public String html() {
        return "index.html";
    }

    @ModelAttribute
    public void parseUser(@RequestParam(name = "name", defaultValue = "unknown user") String name
            , @RequestParam(name = "age", defaultValue = "12") Integer age, User user) {
        user.setName("zhangsan");
        user.setAge(18);
    }
}
/*
 * Copyright 2013-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.exam.demos.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author <a href="mailto:[email protected]">theonefx</a>
 */
@Controller
public class PathVariableController {

    // http://127.0.0.1:8080/user/123/roles/222
    @RequestMapping(value = "/user/{userId}/roles/{roleId}", method = RequestMethod.GET)
    @ResponseBody
    public String getLogin(@PathVariable("userId") String userId, @PathVariable("roleId") String roleId) {
        return "User Id : " + userId + " Role Id : " + roleId;
    }

    // http://127.0.0.1:8080/javabeat/somewords
    @RequestMapping(value = "/javabeat/{regexp1:[a-z-]+}", method = RequestMethod.GET)
    @ResponseBody
    public String getRegExp(@PathVariable("regexp1") String regexp1) {
        return "URI Part : " + regexp1;
    }
}
/*
 * Copyright 2013-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.exam.demos.web;

/**
 * @author <a href="mailto:[email protected]">theonefx</a>
 */
public class User {

    private String name;

    private Integer age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}

标签:name,License,Controller,user,使用,org,public,模板,String
From: https://www.cnblogs.com/xiaoovo/p/18143953

相关文章

  • C#反射使用
    usingSystem.Reflection;namespaceTestReflection{internalclassProgram{staticvoidMain(string[]args){Console.WriteLine("TestReflection");Console.WriteLine("************************......
  • GPG4win 使用笔记
    简介:Gpg4win是一套文件或email加密解密的安全方案。Gpg4win-asecuresolutionforfileandemailencryption.Gpg4win(GNUPrivacyGuardforWindows)isFreeSoftwareandcanbeinstalledwithjustafewmouseclicks安装:首先,从GPG4win官方网站下载安装程序 ht......
  • v-for 一定要绑定key值吗?为什么不建议使用index?
    在vue进行循环的数组或者对象中,使用了v-for进行dom元素的渲染。当数组或对象中的值发生变化时,可能会使dom元素重新渲染。是否会重新渲染和我们设置的key属性对应的值有关合理的设置key属性的值可以有效的提高页面的的更新效率首先,vue使用了diff算法来进行dom元素的更新,diff算......
  • JS 中 reduce()方法及使用详解
    reduce()方法可以搞定的东西特别多,就是循环遍历能做的,reduce都可以做,比如数组求和、数组求积、统计数组中元素出现的次数、数组去重等等。reduce()方法对数组中的每个元素执行一个由您提供的reduce函数(依次执行),将其结果汇总为单个返回值。1、语法介绍//arr.reduce(callbac......
  • 如何在HTML中使用JavaScript:从基础到高级的全面指南!
    JavaScript是一种轻量级的编程语言,通常用于网页开发,以增强用户界面的交互性和动态性。然而在HTML中,有多种方法可以嵌入和使用JavaScript代码。本文就带大家深入了解如何在HTML中使用JavaScript。一、使用script标签要在HTML中使用JavaScript,我们需要使用<script>标签。这个标......
  • blender python api 使用脚本修改动画关键帧的属性值
    1.代码1-将动画关键帧中的所有Y轴都设置为1.0,代码:importbpy#设置重置到的Y坐标值reset_to=1.0#遍历所有当前选中的对象forobjectinbpy.context.selected_objects:#如果对象没有动画,我们也应该重置其Y坐标object.location.y=reset_to#检......
  • 使用Maps SDK添加本地slpk
    SceneViewm_sceneView;publicvoidLoadSceneLayerFromSLPK(SceneViewsceneView,stringslpkPath){ if(!File.Exists(slpkPath)) thrownewException("文件不存在"); if(null==sceneView.Scene) CreateScene(sceneView); Uritreespk=newSystem.Uri......
  • react 的拖动面板SplitPane的使用
    1、我刚开始,是准备使用npminstallreact-split-pane来引入的。但是引入的过程报错了npmERR!codeERESOLVEnpmERR!ERESOLVEunabletoresolvedependencytreenpmERR!npmERR!Whileresolving:[email protected]!Found:[email protected]!n......
  • 开源在线表单工具 HeyForm 使用教程
    HeyForm是一个非常出色的开源在线表单工具,可以通过直观的拖拽式编辑器,快速构建出美观实用的表单。HeyForm的功能非常丰富:支持丰富的输入类型,从基础的文本、数字到高级的图片选择、日期选择、文件上传等,一应俱全。通过条件逻辑和URL重定向实现动态、可适应的表单。提供了......
  • Perforce (P4)版本控制使用指南
    转载自:https://blog.csdn.net/zyhse/article/details/119083666以下为P4常规和一些必要操作如何达到同步?本质就是需要告诉P4你干了什么,然后P4再别人的机器上模拟你所做的操作操作的宗旨如果想让别人知道你的操作,就需要去主动通知✘31、登录账号密码相关信息会在入职......