For XXFor XX

作为一个高手
我习惯了孤独

Kotlin服务端Spring Boot系列干货教程3 - 代码编写

Dao接口、实体类、sql都已经生成好了,我们只需要编写Service、Controller即可!

timg (1).jpg

1. 编写Controller

    @RequestMapping("/")
    fun selectMessageList(pageNum: Int?,type: Int?,model: ModelMap): String {
        var pageNum = pageNum?:1
        var type = type?:1
        var pageSize = 10
        PageHelper.startPage<Any>(pageNum, pageSize)
        var para = HashMap<Any,Any>()
        if (type==1){
            para.put("sorts","time")
        }else{
            para.put("sorts","praise")
        }
        var messageList = messageMapper!!.selectListByMap(para)
        var pageInfo = PageInfo(messageList)
        model.put("type",type)
        model.put("page",pageInfo)
        return "/msg"
    }


    @RequestMapping("/addMessage.json")
    @ResponseBody
    fun addMessage(nick_name: String, content: String, face: String):R {
        return messageService!!.addMessage(nick_name, content, face)
    }

2. 编写Service代码

    @Autowired
    private val messageMapper: MessageMapper? = null

    @Transactional
    fun addMessage(nick_name: String, content: String, face: String): R{
        var msg = Message()
        msg.nick_name = nick_name
        msg.content = content
        msg.face = face
        msg.add_time = Date()
        messageMapper!!.insertSelective(msg)
        return R(1,"")
    }

这里只截取了部分代码做演示,完成源码已上传

效果图

QQ截图20171214202500.png

详细的日志

QQ截图20171214202916.png


GitHub源码地址:https://github.com/kecikeci/springboot4kt

Gitee码云地址:https://gitee.com/kecikeci/springboot4kt

系列教程:https://4xx.me/tag/Kotin-Spring-Boot/

转载请注明出处:For XX » Kotlin服务端Spring Boot系列干货教程3 - 代码编写
标签:Kotlin Kotin+Spring Boot
分享到: 更多