ssm常用注解

@Component 通用注解
@RestController 控制层的注解,返回的值默认值是Json数据
@RequestMapping 访问路径的设置
@Controller 控制层的注解
@Autowired 自动注入
@Service 业务层
@RequestParam 用于接收前端页面传过来的值,可以设置默认值来防止前端页面传空数据过来

@RequestMapping("/table")
public TableResult table(@RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "5") Integer limit, String name, Integer state){    

@RequestBody 将请求体中的Json数据转为java对象

@RequestMapping("/users")
public String addUser(@RequestBody User user){//@RequestBody将请求体中的json数据转换为java对象

@ResponseBody //将handler的返回值,转换成json(jackson),并将json响应给客户端。
@PathVaribale 接收路径中的值

@GetMapping("/users/{id}")
    public String queryOneUser(@PathVariable Integer id){//@PathVariable 接收路径中的值
        System.out.println("Get user id:"+id);
        return "{status:1}";
    }

@SessionAttributes

@Controller
@SessionAttributes({"gender","name"}) // model中的 name和gender 会存入session中
public class UserController {

    @RequestMapping("/hello")
    public String hello(Model m){
        m.addAttribute("gender",true); // 会存入session
        mv.addObject("name","zhj"); // 会存入session
        return "index";
    }
    
    @RequestMapping("/hello2")
    public String hello(SessionStatus status){
        // 移除通过SessionAttributes存入的session
        status.setComplete();
        return "index";
    }
}

@Param 用于dao层传多个参数

List<AdminUser> table(@Param("realName") String realName,@Param("email") String email,@Param("status") Integer status);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值