当前位置 主页 > 服务器问题 > Linux/apache问题 >
有意思的是,在scala中依赖注入是写在类名上的
六、Controller层
import cn.gjing.tools.common.annotation.NotEmpty import cn.gjing.tools.common.result.PageResult import com.gjing.project.scala.entity.Customer import com.gjing.project.scala.service.CustomerService import io.swagger.annotations.{Api, ApiImplicitParam, ApiImplicitParams, ApiOperation} import javax.annotation.Resource import org.springframework.data.domain.PageRequest import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation._ /** * @author Gjing **/ @RestController @Api(tags = Array("用户的相关功能")) class CustomerController @Resource()(customerService:CustomerService){ @PostMapping(Array("/customer")) @ApiOperation("添加用户") @ApiImplicitParam(name = "customerName",value = "用户名",dataType = "String",required = true,paramType = "query") @NotEmpty def saveCustomer(customerName:String): ResponseEntity[String] ={ customerService.saveCustomer(customerName) ResponseEntity.ok("添加成功") } @GetMapping(Array("/customer_page")) @ApiOperation("分页查询") @ApiImplicitParams(Array( new ApiImplicitParam(name = "page",value = "页数",required = true,dataType = "int",paramType = "query"), new ApiImplicitParam(name = "size",value = "条数",required = true,dataType = "int",paramType = "query"), )) def pageCustomer(page:Integer,size:Integer): ResponseEntity[PageResult[java.util.List[Customer]]]={ ResponseEntity.ok(customerService.pageCustomer(PageRequest.of(page, size))) } @NotEmpty @PutMapping(Array("/customer")) @ApiOperation("更新用户") @ApiImplicitParams(Array( new ApiImplicitParam(name = "id",value = "用户ID",required = true,dataType = "int",paramType = "query"), new ApiImplicitParam(name = "name",value = "用户名",required = true,dataType = "String",paramType = "query") )) def updateCustomer(id:Integer,name:String): ResponseEntity[String] = { customerService.updateCustomer(id, name) ResponseEntity.ok("修改成功") } @DeleteMapping(Array("/customer/{id}")) @ApiOperation("删除用户") def deleteCustomer(id:Integer): ResponseEntity[String] = { customerService.deleteCustomer(id) ResponseEntity.ok("删除成功") } }
这样我们一个简单的Scala版本的Web项目就写好啦,只需要启动就可以试着运行啦,本文的源代码地址:scala-demo,有任何不清楚的可以在评论区回复哈
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持IIS7站长之家。