Browse Source

第一次修改

DESKTOP-725ARQ8\17262 6 years ago
commit
c9631d9dd6

+ 25 - 0
.gitignore

@@ -0,0 +1,25 @@
+/target/
+!.mvn/wrapper/maven-wrapper.jar
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/build/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/

BIN
.mvn/wrapper/maven-wrapper.jar


+ 1 - 0
.mvn/wrapper/maven-wrapper.properties

@@ -0,0 +1 @@
+distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip

+ 225 - 0
mvnw

@@ -0,0 +1,225 @@
+#!/bin/sh
+# ----------------------------------------------------------------------------
+# 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://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# ----------------------------------------------------------------------------
+
+# ----------------------------------------------------------------------------
+# Maven2 Start Up Batch script
+#
+# Required ENV vars:
+# ------------------
+#   JAVA_HOME - location of a JDK home dir
+#
+# Optional ENV vars
+# -----------------
+#   M2_HOME - location of maven2's installed home dir
+#   MAVEN_OPTS - parameters passed to the Java VM when running Maven
+#     e.g. to debug Maven itself, use
+#       set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+#   MAVEN_SKIP_RC - flag to disable loading of mavenrc files
+# ----------------------------------------------------------------------------
+
+if [ -z "$MAVEN_SKIP_RC" ] ; then
+
+  if [ -f /etc/mavenrc ] ; then
+    . /etc/mavenrc
+  fi
+
+  if [ -f "$HOME/.mavenrc" ] ; then
+    . "$HOME/.mavenrc"
+  fi
+
+fi
+
+# OS specific support.  $var _must_ be set to either true or false.
+cygwin=false;
+darwin=false;
+mingw=false
+case "`uname`" in
+  CYGWIN*) cygwin=true ;;
+  MINGW*) mingw=true;;
+  Darwin*) darwin=true
+    # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
+    # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
+    if [ -z "$JAVA_HOME" ]; then
+      if [ -x "/usr/libexec/java_home" ]; then
+        export JAVA_HOME="`/usr/libexec/java_home`"
+      else
+        export JAVA_HOME="/Library/Java/Home"
+      fi
+    fi
+    ;;
+esac
+
+if [ -z "$JAVA_HOME" ] ; then
+  if [ -r /etc/gentoo-release ] ; then
+    JAVA_HOME=`java-config --jre-home`
+  fi
+fi
+
+if [ -z "$M2_HOME" ] ; then
+  ## resolve links - $0 may be a link to maven's home
+  PRG="$0"
+
+  # need this for relative symlinks
+  while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+      PRG="$link"
+    else
+      PRG="`dirname "$PRG"`/$link"
+    fi
+  done
+
+  saveddir=`pwd`
+
+  M2_HOME=`dirname "$PRG"`/..
+
+  # make it fully qualified
+  M2_HOME=`cd "$M2_HOME" && pwd`
+
+  cd "$saveddir"
+  # echo Using m2 at $M2_HOME
+fi
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched
+if $cygwin ; then
+  [ -n "$M2_HOME" ] &&
+    M2_HOME=`cygpath --unix "$M2_HOME"`
+  [ -n "$JAVA_HOME" ] &&
+    JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+  [ -n "$CLASSPATH" ] &&
+    CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
+fi
+
+# For Migwn, ensure paths are in UNIX format before anything is touched
+if $mingw ; then
+  [ -n "$M2_HOME" ] &&
+    M2_HOME="`(cd "$M2_HOME"; pwd)`"
+  [ -n "$JAVA_HOME" ] &&
+    JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
+  # TODO classpath?
+fi
+
+if [ -z "$JAVA_HOME" ]; then
+  javaExecutable="`which javac`"
+  if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
+    # readlink(1) is not available as standard on Solaris 10.
+    readLink=`which readlink`
+    if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
+      if $darwin ; then
+        javaHome="`dirname \"$javaExecutable\"`"
+        javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
+      else
+        javaExecutable="`readlink -f \"$javaExecutable\"`"
+      fi
+      javaHome="`dirname \"$javaExecutable\"`"
+      javaHome=`expr "$javaHome" : '\(.*\)/bin'`
+      JAVA_HOME="$javaHome"
+      export JAVA_HOME
+    fi
+  fi
+fi
+
+if [ -z "$JAVACMD" ] ; then
+  if [ -n "$JAVA_HOME"  ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+      # IBM's JDK on AIX uses strange locations for the executables
+      JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+      JAVACMD="$JAVA_HOME/bin/java"
+    fi
+  else
+    JAVACMD="`which java`"
+  fi
+fi
+
+if [ ! -x "$JAVACMD" ] ; then
+  echo "Error: JAVA_HOME is not defined correctly." >&2
+  echo "  We cannot execute $JAVACMD" >&2
+  exit 1
+fi
+
+if [ -z "$JAVA_HOME" ] ; then
+  echo "Warning: JAVA_HOME environment variable is not set."
+fi
+
+CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
+
+# traverses directory structure from process work directory to filesystem root
+# first directory with .mvn subdirectory is considered project base directory
+find_maven_basedir() {
+
+  if [ -z "$1" ]
+  then
+    echo "Path not specified to find_maven_basedir"
+    return 1
+  fi
+
+  basedir="$1"
+  wdir="$1"
+  while [ "$wdir" != '/' ] ; do
+    if [ -d "$wdir"/.mvn ] ; then
+      basedir=$wdir
+      break
+    fi
+    # workaround for JBEAP-8937 (on Solaris 10/Sparc)
+    if [ -d "${wdir}" ]; then
+      wdir=`cd "$wdir/.."; pwd`
+    fi
+    # end of workaround
+  done
+  echo "${basedir}"
+}
+
+# concatenates all lines of a file
+concat_lines() {
+  if [ -f "$1" ]; then
+    echo "$(tr -s '\n' ' ' < "$1")"
+  fi
+}
+
+BASE_DIR=`find_maven_basedir "$(pwd)"`
+if [ -z "$BASE_DIR" ]; then
+  exit 1;
+fi
+
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
+echo $MAVEN_PROJECTBASEDIR
+MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin; then
+  [ -n "$M2_HOME" ] &&
+    M2_HOME=`cygpath --path --windows "$M2_HOME"`
+  [ -n "$JAVA_HOME" ] &&
+    JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
+  [ -n "$CLASSPATH" ] &&
+    CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
+  [ -n "$MAVEN_PROJECTBASEDIR" ] &&
+    MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
+fi
+
+WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+
+exec "$JAVACMD" \
+  $MAVEN_OPTS \
+  -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
+  "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
+  ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"

+ 143 - 0
mvnw.cmd

@@ -0,0 +1,143 @@
+@REM ----------------------------------------------------------------------------
+@REM Licensed to the Apache Software Foundation (ASF) under one
+@REM or more contributor license agreements.  See the NOTICE file
+@REM distributed with this work for additional information
+@REM regarding copyright ownership.  The ASF licenses this file
+@REM to you under the Apache License, Version 2.0 (the
+@REM "License"); you may not use this file except in compliance
+@REM with the License.  You may obtain a copy of the License at
+@REM
+@REM    http://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM Unless required by applicable law or agreed to in writing,
+@REM software distributed under the License is distributed on an
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@REM KIND, either express or implied.  See the License for the
+@REM specific language governing permissions and limitations
+@REM under the License.
+@REM ----------------------------------------------------------------------------
+
+@REM ----------------------------------------------------------------------------
+@REM Maven2 Start Up Batch script
+@REM
+@REM Required ENV vars:
+@REM JAVA_HOME - location of a JDK home dir
+@REM
+@REM Optional ENV vars
+@REM M2_HOME - location of maven2's installed home dir
+@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
+@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
+@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
+@REM     e.g. to debug Maven itself, use
+@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
+@REM ----------------------------------------------------------------------------
+
+@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
+@echo off
+@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
+@if "%MAVEN_BATCH_ECHO%" == "on"  echo %MAVEN_BATCH_ECHO%
+
+@REM set %HOME% to equivalent of $HOME
+if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
+
+@REM Execute a user defined script before this one
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
+@REM check for pre script, once with legacy .bat ending and once with .cmd ending
+if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
+if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
+:skipRcPre
+
+@setlocal
+
+set ERROR_CODE=0
+
+@REM To isolate internal variables from possible post scripts, we use another setlocal
+@setlocal
+
+@REM ==== START VALIDATION ====
+if not "%JAVA_HOME%" == "" goto OkJHome
+
+echo.
+echo Error: JAVA_HOME not found in your environment. >&2
+echo Please set the JAVA_HOME variable in your environment to match the >&2
+echo location of your Java installation. >&2
+echo.
+goto error
+
+:OkJHome
+if exist "%JAVA_HOME%\bin\java.exe" goto init
+
+echo.
+echo Error: JAVA_HOME is set to an invalid directory. >&2
+echo JAVA_HOME = "%JAVA_HOME%" >&2
+echo Please set the JAVA_HOME variable in your environment to match the >&2
+echo location of your Java installation. >&2
+echo.
+goto error
+
+@REM ==== END VALIDATION ====
+
+:init
+
+@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
+@REM Fallback to current working directory if not found.
+
+set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
+IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
+
+set EXEC_DIR=%CD%
+set WDIR=%EXEC_DIR%
+:findBaseDir
+IF EXIST "%WDIR%"\.mvn goto baseDirFound
+cd ..
+IF "%WDIR%"=="%CD%" goto baseDirNotFound
+set WDIR=%CD%
+goto findBaseDir
+
+:baseDirFound
+set MAVEN_PROJECTBASEDIR=%WDIR%
+cd "%EXEC_DIR%"
+goto endDetectBaseDir
+
+:baseDirNotFound
+set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
+cd "%EXEC_DIR%"
+
+:endDetectBaseDir
+
+IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
+
+@setlocal EnableExtensions EnableDelayedExpansion
+for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
+@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
+
+:endReadAdditionalConfig
+
+SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
+
+set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
+set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+
+%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
+if ERRORLEVEL 1 goto error
+goto end
+
+:error
+set ERROR_CODE=1
+
+:end
+@endlocal & set ERROR_CODE=%ERROR_CODE%
+
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
+@REM check for post script, once with legacy .bat ending and once with .cmd ending
+if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
+if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
+:skipRcPost
+
+@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
+if "%MAVEN_BATCH_PAUSE%" == "on" pause
+
+if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
+
+exit /B %ERROR_CODE%

+ 67 - 0
pom.xml

@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+
+	<groupId>com.imooc</groupId>
+	<artifactId>demo</artifactId>
+	<version>0.0.1-SNAPSHOT</version>
+	<packaging>jar</packaging>
+
+	<name>demo</name>
+	<description>Demo project for Spring Boot</description>
+
+	<parent>
+		<groupId>org.springframework.boot</groupId>
+		<artifactId>spring-boot-starter-parent</artifactId>
+		<version>2.0.1.RELEASE</version>
+		<relativePath/> <!-- lookup parent from repository -->
+	</parent>
+
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+		<java.version>1.8</java.version>
+	</properties>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-web</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.mybatis.spring.boot</groupId>
+			<artifactId>mybatis-spring-boot-starter</artifactId>
+			<version>1.3.2</version>
+		</dependency>
+
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-test</artifactId>
+			<scope>test</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>mysql</groupId>
+			<artifactId>mysql-connector-java</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>com.alibaba</groupId>
+			<artifactId>druid</artifactId>
+			<version>1.1.8</version>
+		</dependency>
+
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.springframework.boot</groupId>
+				<artifactId>spring-boot-maven-plugin</artifactId>
+			</plugin>
+		</plugins>
+	</build>
+
+
+</project>

+ 12 - 0
src/main/java/com/imooc/demo/DemoApplication.java

@@ -0,0 +1,12 @@
+package com.imooc.demo;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class DemoApplication {
+
+	public static void main(String[] args) {
+		SpringApplication.run(DemoApplication.class, args);
+	}
+}

+ 42 - 0
src/main/java/com/imooc/demo/config/dao/DataSourceConfiguration.java

@@ -0,0 +1,42 @@
+package com.imooc.demo.config.dao;
+
+import com.alibaba.druid.pool.DruidDataSource;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+
+
+/**
+ *
+ */
+
+@Configuration
+//配置mapper的扫描路径
+@MapperScan("com.imooc.demo.dao")
+public class DataSourceConfiguration {
+
+
+    @Value("${jdbc.url}")
+    private String jdbcUrl;
+    @Value("${jdbc.driver}")
+    private String jdbcDriver;
+    @Value("${jdbc.username}")
+    private String jdbcUsername;
+    @Value("${jdbc.password}")
+    private String jdbcPassword;
+
+    @Bean(name="dataSource")
+    public DruidDataSource createDateSource(){
+        DruidDataSource dataSource = new DruidDataSource();
+        dataSource.setDriverClassName(jdbcDriver);
+        dataSource.setUrl(jdbcUrl);
+        dataSource.setUsername(jdbcUsername);
+        dataSource.setPassword(jdbcPassword);
+
+        dataSource.setDefaultAutoCommit(false);
+
+        return dataSource;
+    }
+}

+ 44 - 0
src/main/java/com/imooc/demo/config/dao/SessionFactoryConfiguration.java

@@ -0,0 +1,44 @@
+package com.imooc.demo.config.dao;
+
+
+import org.mybatis.spring.SqlSessionFactoryBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+
+import javax.sql.DataSource;
+import java.io.IOException;
+
+@Configuration
+public class SessionFactoryConfiguration {
+
+    @Value("${mybatis_config_file}")
+    private String mybatisConfigFilePath;
+    @Value("${mapper_path}")
+    private String mapperPath;
+    @Autowired
+    @Qualifier("dataSource")
+    private DataSource dataSource;
+    @Value("${entity_package}")
+    private String entityPackage;
+
+
+    @Bean(name = "sqlSessionFactory")
+    public SqlSessionFactoryBean createSqlSessionFactoryBean() throws IOException {
+        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
+        sqlSessionFactoryBean.setConfigLocation(new ClassPathResource(mybatisConfigFilePath));
+
+        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
+        String packageSearchPath = PathMatchingResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX +mapperPath;
+
+        sqlSessionFactoryBean.setMapperLocations(resolver.getResources(packageSearchPath));
+        sqlSessionFactoryBean.setDataSource(dataSource);
+
+        sqlSessionFactoryBean.setTypeAliasesPackage(entityPackage);
+
+        return sqlSessionFactoryBean;
+    }}

+ 24 - 0
src/main/java/com/imooc/demo/config/service/TransactionManagementConfiguration.java

@@ -0,0 +1,24 @@
+package com.imooc.demo.config.service;
+
+import javax.sql.DataSource;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+import org.springframework.transaction.annotation.TransactionManagementConfigurer;
+
+@Configuration
+@EnableTransactionManagement
+public class TransactionManagementConfiguration implements TransactionManagementConfigurer{
+
+	@Autowired
+	private DataSource dataSource;
+
+	@Override
+	public PlatformTransactionManager annotationDrivenTransactionManager() {
+		// TODO Auto-generated method stub
+		return new DataSourceTransactionManager(dataSource);
+	}
+}

+ 13 - 0
src/main/java/com/imooc/demo/dao/AreaDao.java

@@ -0,0 +1,13 @@
+package com.imooc.demo.dao;
+
+import com.imooc.demo.entity.Area;
+
+import java.util.List;
+
+public interface AreaDao {
+    List<Area> queryArea();
+    Area queryAreaById(int areaId);
+    int insertArea(Area area);
+    int updateArea(Area area);
+    int deleteArea(int areaId);
+}

+ 58 - 0
src/main/java/com/imooc/demo/dao/AreaDaoTest.java

@@ -0,0 +1,58 @@
+package com.imooc.demo.dao;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Date;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import com.imooc.demo.entity.Area;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class AreaDaoTest {
+	
+	@Autowired
+	private AreaDao areaDao;
+	
+	@Test
+	public void queryArea() {
+		List<Area> arealiat = areaDao.queryArea();
+		
+	}
+	
+	@Test
+	public void queryAreaById() {
+		Area area = areaDao.queryAreaById(1);
+		assertEquals("东苑", area.getAreaName());
+		
+	}
+	
+	@Test
+	public void insertArea() {
+		Area area = new Area();
+		area.setAreaName("南苑");
+		area.setPriority(1);
+		int insertArea = areaDao.insertArea(area);
+		
+		
+	}
+	@Test
+	public void updateArea() {
+		Area area = new Area();
+		area.setAreaName("西苑");
+		area.setAreaId(3);
+		area.setLastEditTime(new Date());
+		areaDao.updateArea(area);
+		
+	}
+	@Test
+	public void deleteArea() {
+		areaDao.deleteArea(5);
+	}
+}

+ 64 - 0
src/main/java/com/imooc/demo/entity/Area.java

@@ -0,0 +1,64 @@
+package com.imooc.demo.entity;
+
+import java.util.Date;
+
+public class Area {
+    private Integer areaId;
+
+    private String areaName;
+
+    private Integer priority;
+
+    private Date createTime;
+
+    private Date lastEditTime;
+
+    public Integer getAreaId() {
+        return areaId;
+    }
+
+    public void setAreaId(Integer areaId) {
+        this.areaId = areaId;
+    }
+
+    public String getAreaName() {
+        return areaName;
+    }
+
+    public void setAreaName(String areaName) {
+        this.areaName = areaName;
+    }
+
+    public Integer getPriority() {
+        return priority;
+    }
+
+    public void setPriority(Integer priority) {
+        this.priority = priority;
+    }
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+    public Date getLastEditTime() {
+        return lastEditTime;
+    }
+
+    public void setLastEditTime(Date lastEditTime) {
+        this.lastEditTime = lastEditTime;
+    }
+
+	@Override
+	public String toString() {
+		return "Area [areaId=" + areaId + ", areaName=" + areaName + ", priority=" + priority + ", createTime="
+				+ createTime + ", lastEditTime=" + lastEditTime + "]";
+	}
+    
+    
+    
+}

+ 23 - 0
src/main/java/com/imooc/demo/handler/GlobalExceptionHandler.java

@@ -0,0 +1,23 @@
+package com.imooc.demo.handler;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+@ControllerAdvice
+public class GlobalExceptionHandler {
+	@ExceptionHandler(value = Exception.class)
+	@ResponseBody
+	private Map<String, Object> exceptionHandler(HttpServletRequest req,Exception e){
+	Map<String, Object> modelMap = new HashMap<>();
+	modelMap.put("success", false);
+	modelMap.put("errMsg", e.getMessage());
+	return modelMap;
+	}
+}

+ 14 - 0
src/main/java/com/imooc/demo/hello.java

@@ -0,0 +1,14 @@
+package com.imooc.demo;
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class hello {
+    @RequestMapping(value = "/hello",method = RequestMethod.GET)
+    public String hello(){
+        return "Hello SpringBoot";
+    }
+
+}

+ 21 - 0
src/main/java/com/imooc/demo/service/AreaService.java

@@ -0,0 +1,21 @@
+/**
+ * 
+ */
+/**
+ * @author 17262
+ *
+ */
+package com.imooc.demo.service;
+
+import java.util.List;
+
+import com.imooc.demo.entity.Area;
+
+public interface AreaService{
+	
+	List<Area> getAreaList();
+    Area getAreaById(int areaId);
+    boolean addArea(Area area);
+    Boolean modifyArea(Area area);
+    Boolean deleteArea(int areaId);
+}

+ 97 - 0
src/main/java/com/imooc/demo/service/impl/AreaServiceImpl.java

@@ -0,0 +1,97 @@
+package com.imooc.demo.service.impl;
+
+import java.util.Date;
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.imooc.demo.dao.AreaDao;
+import com.imooc.demo.entity.Area;
+import com.imooc.demo.service.AreaService;
+
+
+@Service
+public class AreaServiceImpl implements AreaService {
+
+	
+	@Autowired
+	private AreaDao areaDao;
+	@Override
+	public List<Area> getAreaList() {
+		
+		return areaDao.queryArea();
+	}
+
+	@Override
+	public Area getAreaById(int areaId) {
+		
+		return areaDao.queryAreaById(areaId);
+	}
+
+	@Transactional
+	@Override
+	public boolean addArea(Area area) {
+		
+		if(area.getAreaName()!=null && !"".equals(area.getAreaName())) {
+			area.setCreateTime(new Date());
+			area.setLastEditTime(new Date());
+			try {
+				int insertArea = areaDao.insertArea(area);
+				if(insertArea>0) {
+					return true;
+				}else {
+					throw new RuntimeException("插入区域信息失败!");
+				}
+			}catch (Exception e) {
+				throw new RuntimeException("插入区域信息失败:"+e.getMessage());
+			}
+		}else {
+			throw new RuntimeException("区域信息不能为空!");
+		}
+	}
+
+	@Override
+	public Boolean modifyArea(Area area) {
+	
+		if(area.getAreaId()!=null && area.getAreaId()>0) {
+
+			area.setLastEditTime(new Date());
+			try {
+				int updateArea = areaDao.updateArea(area);
+				if(updateArea>0) {
+					return true;
+				}else {
+					throw new RuntimeException("插入区域信息失败!");
+				}
+			}catch (Exception e) {
+				throw new RuntimeException("插入区域信息失败:"+e.getMessage());
+			}
+		}else {
+			throw new RuntimeException("区域信息不能为空!");
+		}
+	}
+
+	@Override
+	public Boolean deleteArea(int areaId) {
+		
+		if(areaId>0) {
+
+			
+			try {
+				int deleteArea = areaDao.deleteArea(areaId);
+				if(deleteArea>0) {
+					return true;
+				}else {
+					throw new RuntimeException("插入区域信息失败!");
+				}
+			}catch (Exception e) {
+				throw new RuntimeException("插入区域信息失败:"+e.getMessage());
+			}
+		}else {
+			throw new RuntimeException("区域信息不能为空!");
+		}
+	}
+
+}

+ 66 - 0
src/main/java/com/imooc/demo/web/AreaController.java

@@ -0,0 +1,66 @@
+package com.imooc.demo.web;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.imooc.demo.entity.Area;
+import com.imooc.demo.service.AreaService;
+
+@RestController
+@RequestMapping("/superadmin")
+public class AreaController {
+	
+	@Autowired
+	private AreaService areaService;
+	
+	@RequestMapping(value = "/listarea" , method = RequestMethod.GET)
+	private Map<String,Object> listArea(){
+		Map<String, Object> modelMap = new HashMap<>();
+		List<Area> list = areaService.getAreaList();
+		modelMap.put("areaList", list);
+		return modelMap;
+	}
+	
+	@RequestMapping(value = "/getareabyid",method = RequestMethod.GET)
+	private Map<String, Object> getAreaById(Integer areaId){
+		Map<String, Object> modelMap = new HashMap<>();
+		Area areaById = areaService.getAreaById(areaId);
+		modelMap.put("area", areaById);
+		return modelMap;
+	}
+	
+	@RequestMapping(value="/addarea",method = RequestMethod.POST)
+	private Map<String, Object> addarea (@RequestBody Area area){
+		Map<String, Object> modelMap = new HashMap<>();
+		modelMap.put("success", areaService.addArea(area));
+		return modelMap;
+	}
+	
+	@RequestMapping(value="/modifyarea",method = RequestMethod.POST)
+	private Map<String, Object> modifyArea (@RequestBody Area area){
+		Map<String, Object> modelMap = new HashMap<>();
+		modelMap.put("success", areaService.modifyArea(area));
+		return modelMap;
+	}
+	
+	
+	@RequestMapping(value="/removearea",method = RequestMethod.GET)
+	private Map<String, Object> removeArea (Integer areaId){
+		Map<String, Object> modelMap = new HashMap<>();
+		modelMap.put("success", areaService.deleteArea(areaId));
+		return modelMap;
+	}
+	
+	
+	
+	
+	
+
+}

+ 9 - 0
src/main/resources/application.properties

@@ -0,0 +1,9 @@
+jdbc.driver=com.mysql.jdbc.Driver
+jdbc.url=jdbc:mysql://localhost:3306/demo?characterEncoding=utf-8
+jdbc.username=root
+jdbc.password=123456
+
+#mybatis
+mybatis_config_file=mybatis-config.xml
+mapper_path=/mapper/**.xml
+entity_package=com.imooc.demo.entity

+ 57 - 0
src/main/resources/mapper/AreaDao.xml

@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.imooc.demo.dao.AreaDao">
+
+<select id="queryArea" resultType="com.imooc.demo.entity.Area">
+	select 
+	area_id,
+	area_name,
+	priority,
+	create_time,
+	last_edit_time
+	from tb_area
+	order by priority desc
+</select>
+<select id="queryAreaById" resultType="com.imooc.demo.entity.Area">
+	select 
+	area_id,
+	area_name,
+	priority,
+	create_time,
+	last_edit_time
+	from tb_area
+	where
+	area_id=#{areaId}
+</select>
+
+<insert id="insertArea" useGeneratedKeys="true" keyProperty="areaId"
+	keyColumn="area_id" parameterType="com.imooc.demo.entity.Area">
+	insert into
+	tb_area(area_name,priority,
+	create_time,last_edit_time)
+	values
+	(#{areaName},#{priority},#{createTime},#{lastEditTime})
+	
+</insert>
+
+<update id="updateArea" parameterType="com.imooc.demo.entity.Area">
+	update tb_area
+	<set>
+		<if test="areaName !=null">area_name=#{areaName},</if>
+		<if test="priority !=null">priority=#{priority},</if>
+		<if test="lastEditTime !=null">last_edit_time=#{lastEditTime}</if>
+	</set>
+	where area_id=#{areaId}
+</update>
+
+
+<delete id="deleteArea" parameterType="Integer">
+	delete from
+	tb_area
+	where
+	area_id = #{areaId}
+</delete>
+</mapper>

+ 12 - 0
src/main/resources/mybatis-config.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-config.dtd">
+
+<configuration>
+    
+    <settings>
+        <setting name="useGeneratedKeys" value="true"/>
+        <setting name="mapUnderscoreToCamelCase" value="true"></setting>
+    </settings>
+
+</configuration>

+ 16 - 0
src/test/java/com/example/demo/DemoApplicationTests.java

@@ -0,0 +1,16 @@
+package com.example.demo;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class DemoApplicationTests {
+
+	@Test
+	public void contextLoads() {
+	}
+
+}