由于基础差本笔记只能做一点点参考,我也是第一次接触也是跟着老师步伐总结的不好见谅
由于基础部分不太重要从今天起开始记录
这俩个目录就是今天学习的主要内容
1、controller 层 个人理解类似于flask框架的app.py的路由在这里面呢我定义了一个
TextController的类,
package com.example.demo.controller;
import com.example.demo.entity.User;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/ai")
public class TextController {
// @GetMapping("/01")
// public String home(){
// return "你好";1
// }
//@GetMapping("/{id}")
//public String text( @PathVariable String id){
// return id;
//}
//
// @GetMapping("/{third}")
// public String third(HttpServletRequest request){
//
// String id = request.getParameter("id");
//
// return id ;
// }
@PostMapping(value = "/loginjson")
public String longinjson(@Validated @RequestBody User user) {
if(user.getUsername()!=null && user.getPassword() != null){
return String.format("账号:%s, 密码:%s", user.getUsername(), user.getPassword());
}else {
return "账号密码不能为空";
}
}
}
这个类主要定义接口层;
2、这个类还需要一个实体User这个类就是定义了一个get、set方法,这里本来可以用@data的注解我自己试着用有问题老报错找不到User get方法,这应该是我的问题,基础差的缘由,不过慢慢来;
package com.example.demo.entity;
import lombok.Data;
//@Data 正常情况可以用
public class User {
private String username;
private String password;
public String getUsername() {
return this.username ;
}
public String getPassword() {
return this.password;
}
}
好这就是今天的小记录吧哈哈,欢迎指正,我虚心接受