Dao接口、实体类、sql都已经生成好了,我们只需要编写Service、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)
}
@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,"")
}
这里只截取了部分代码做演示,完成源码已上传
效果图
详细的日志
GitHub源码地址:https://github.com/kecikeci/springboot4kt
Gitee码云地址:https://gitee.com/kecikeci/springboot4kt