本文介绍了Maven构建自己的第一个Java后台的方法,分享给大家,具体如下:
1.知识后顾
关于如何运用Maven构建自己的第一个项目,上期我已经详细的讲解过了,上篇链接;今天我以SpringMvc,Mybatis框架搭建一个属于你自己的Java后台。
2.必要准备
①IntelliJ IDEA,Maven环境搭好
②熟悉掌握MyBatis,SpringMVC等框架
③mysql数据库的创建
3.整体架构布局
4.具体步骤
①在pom.xml中配置工程要使用的jar包
<?xml version="1.0" encoding="UTF-8"?><!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://.dajiu.service.UserService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;import java.util.HashMap;import java.util.List;import java.util.Map;/** * Created by zhangxing on 2017/4/7. */@Controller@RequestMapping("/blog")public class UserController { @Autowired UserService userService; @RequestMapping("/getUser") @ResponseBody public Map<String,Object> getUser(){ Map map = new HashMap(); List<User> list = userService.getAll(); map.put("user",list); map.put("status",1); map.put("success",true); return map; } @RequestMapping("getLogin") @ResponseBody public Map<String,Object> getLogin(String name,String password){ Map map = new HashMap(); User user = userService.getLogin(name,password); map.put("user",user); map.put("isLogin",true); map.put("status",1); return map; }}这里的@RequestMapping("")表示访问的映射路径,@ResponseBody表示请求结果以json数据格式打印出来,@Controller表示只要访问了上面的根映射路径,就直接调用controller;
现在帮大家理理思路:先请求UserController---->UserService---->UserServiceImpl---->UserDao---->user.xml(mapper)---->bean(user)
6.配置Tomcat服务器
①点击右上角的绿色三角形按钮,点击Edit Configuration
②点击+号,选择Tomcat
③选择local
④填写相关配置
⑤点击Deployment,点击+号,选择Artifact
接着选择第一项,一直enter
这样你的整个工程也就完成了,接下来就是访问了
好了,今天就springMvc,mybatis搭建Java后台的讲解就告一段落了。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。