侧边栏壁纸
  • 累计撰写 110 篇文章
  • 累计创建 67 个标签
  • 累计收到 6 条评论
隐藏侧边栏

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

Polar.
2017-12-14 / 0 评论 / 0 点赞 / 121 阅读 / 1,805 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2021-06-06,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

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

0

评论区