1.添加model层,在model层创建User类
包名:com.huinongtx.demospringboot.model
类名:User
类内容:
package com.huinongtx.demospringboot.model;
/**
* Created by dengdashuai on 2018/12/6.
*/
public class User {
private String userName;
private String passWord;
public String getUserName() {
return userName;
}
public String getPassWord() {
return passWord;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
}
2.修改HelloWorldControl这个类
包名:com.huinongtx.demospringboot.web
类名:HelloWorldControl
类内容:
package com.huinongtx.demospringboot.web;
import com.huinongtx.demospringboot.model.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by dengdashuai on 2018/12/6.
*/
// 类的方法以json格式输出
@RestController
public class HelloWorldControl {
// http://localhost:8080/getuser请求映射到getUser方法
@RequestMapping("/getuser")
public User getUser() {
User user = new User();
user.setUserName("daji");
user.setPassWord("daji1206");
return user;
}
}
3.运行DemospringbootApplication中的Main方法
package com.huinongtx.demospringboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemospringbootApplication {
public static void main(String[] args) {
SpringApplication.run(DemospringbootApplication.class, args);
}
}
3.png
4.在浏览器输入http://localhost:8080/getuser
4.png
QQ截图20181206131239.png
©著作权归作者所有:来自51CTO博客作者素颜猪的原创作品,如需转载,请注明出处,否则将追究法律责任
@RestControllerspring boot Spring
共同学习,写下你的评论
评论加载中...
作者其他优质文章