当前位置: 首页> 财经> 创投人物 > 党支部品牌建设方案_免费公网服务器_电脑培训班零基础_太原网站建设方案优化

党支部品牌建设方案_免费公网服务器_电脑培训班零基础_太原网站建设方案优化

时间:2025/8/12 5:33:17来源:https://blog.csdn.net/qq_52973916/article/details/143134430 浏览次数:0次
党支部品牌建设方案_免费公网服务器_电脑培训班零基础_太原网站建设方案优化

Springboot主流的 ----------------------- 简略写法

package com.dx.wlmq.controller;import com.dx.wlmq.domain.Address;
import com.dx.wlmq.service.AddresssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;@RestController                // 相当于 @Controller+@ResponseBody
@CrossOrigin(origins = "*")    // 取消跨域
@RequestMapping("/address") // 访问路径
public class AddresssController {@Autowired  // 自动装配AddresssService addresssService;/*** 查询方法* *///相当于 @RequestMapping(value = "/list", method = RequestMethod.GET,produces = "text/html;charset=UTF-8" )@GetMapping(value = "/list")public Object index11() {return addresssService.Addresslist();}//    @RequestMapping(value = "/add", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")@PostMapping("/add")public Object index12(@RequestBody Address address) {return addresssService.Addressadd(address);}//    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")@DeleteMapping("/delete")public Object index13(Integer id) {return addresssService.Addressdelete(id);}//    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")@PutMapping(value = "/update")public Object index14(@RequestBody Address address) {return addresssService.Addressupdate(address);}}

原Mybits主流写法(案例)

package com.dx.wlmq.controller;import com.alibaba.fastjson.JSON;
import com.dx.wlmq.domain.Role;
import com.dx.wlmq.service.RolesService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;@Controller
@RequestMapping("/roles")
public class RolesController {@Resource(name = "rolesService")RolesService rolesService;@RequestMapping(value = "/list", method = RequestMethod.GET, produces = "text/html;charset=UTF-8")@ResponseBodypublic Object index11(HttpServletResponse response) {response.setContentType("text/html;charset=UTF-8");return JSON.toJSONString(rolesService.Rolelist());}@RequestMapping(value = "/add", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")@ResponseBodypublic Object index12(HttpServletResponse response,@RequestBody Role role) {response.setContentType("text/html;charset=UTF-8");return JSON.toJSONString(rolesService.Roleadd(role));}@RequestMapping(value = "/delete", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")@ResponseBodypublic Object index13(HttpServletResponse response, Integer id) {response.setContentType("text/html;charset=UTF-8");return JSON.toJSONString(rolesService.Roledelete(id));}@RequestMapping(value = "/update", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")@ResponseBodypublic Object index14(HttpServletResponse response,@RequestBody Role role) {response.setContentType("text/html;charset=UTF-8");return JSON.toJSONString(rolesService.Roleupdate(role));}}

Springboot主流的 ----------------------- 简略写法(优点:写法更简略,更直接)

简单写法的笔记:

《《《《《《《《《------   springboot@注释解析最简写法    ------》》》》》》》》》


在控制层开头:

书写@RestController                // 相当于 @Controller+@ResponseBody
添加取消跨域注释 @CrossOrigin(origins = "*")

书写类,然后在第一行添加 @Autowired  //作用是自动装配 ,装配了业务层的调用实例   
    private SysEmpService sysEmpService;

然后增删改查都有不同的Mapping注释,当这样写注解的时候,return的值直接为JSON格式,详细如下:
    /**
     * 查询方法注解写法
     * */
    @GetMapping(value = "/list")    //相当于 @RequestMapping(value = "/list", method = RequestMethod.GET,produces = "text/html;charset=UTF-8" )
    public Object index11() {
        return addresssService.Addresslist();
    }

     /**
     * 增加方法注解写法
     * */
    @PostMapping("/add")           // 相当于   @RequestMapping(value = "/add", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")
    public Object index12(@RequestBody Address address) {
        return addresssService.Addressadd(address);
    }

    /**
     * 删除方法注解写法
     * */
    @DeleteMapping("/delete")   //相当于    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")
    public Object index13(Integer id) {
        return addresssService.Addressdelete(id);
    }

    /**
     * 修改方法注解写法
     * */
    @PutMapping(value = "/update")   //相当于 @RequestMapping(value="/update", method=RequestMethod.POST, produces = "text/html;charset=UTF-8")
    public Object index14(@RequestBody Address address) {
        return addresssService.Addressupdate(address);
    }


在服务层,将调用Dao层的时用装配注入的注解@Autowired,但服务层实现类里的@Service("rolesService")不能省略

在Dao层的mapper里面添加注解:@Mapper

关键字:党支部品牌建设方案_免费公网服务器_电脑培训班零基础_太原网站建设方案优化

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: