Spring入门

创建Action,使用@Controller注释

@RequestMapping(“hello”) 指定请求地址
@ResponseBody 向前端页面输出内容

spring直接将前台创递过来的数据,包装成一个JavaBean.

基本实例
先创建一个javaBean

package edu.hue.jk.bean;

import java.sql.Date;

public class pojo {
    private Integer id;
    private String  post;
    private Date hiredate;


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getPost() {
        return post;
    }

    public void setPost(String post) {
        this.post = post;
    }

    public Date getHiredate() {
        return hiredate;
    }

    public void setHiredate(Date hiredate) {
        this.hiredate = hiredate;
    }

    @Override
    public String toString() {
        return "pojo{" +
                "id=" + id +
                ", post='" + post + '\'' +
                ", hiredate=" + hiredate +
                '}';
    }
}

MainApp
用SpringApplication

package edu.hue.jk;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication

public class MainApp {
    public static void main(String[] args) {
        SpringApplication.run(MainApp.class);
    }
}

Action

package edu.hue.jk.action;

import edu.hue.jk.bean.pojo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class TestAction {
    @RequestMapping("hello")
    @ResponseBody
    public String hello(pojo p){

        return "Hello World! you are a bad "+p.getPost()+"id="+p.getId()+"hiredate="+ p.getHiredate();
    }
}

效果
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值