'init'
parent
f99cd1517c
commit
fce1982050
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>SpringBoot2</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
|
@ -0,0 +1,2 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding/<project>=UTF-8
|
|
@ -0,0 +1,4 @@
|
||||||
|
activeProfiles=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
resolveWorkspaceProjects=true
|
||||||
|
version=1
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
|
</classpath>
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>SpringBootBasic</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.springframework.ide.eclipse.core.springbuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.springframework.ide.eclipse.core.springnature</nature>
|
||||||
|
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||||
|
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
|
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||||
|
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src/main/webapp"/>
|
||||||
|
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="target/m2e-wtp/web-resources"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="hide" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
|
||||||
|
<classpathentry kind="output" path=""/>
|
||||||
|
</classpath>
|
|
@ -0,0 +1,7 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding//src/main/java=UTF-8
|
||||||
|
encoding//src/main/resources=UTF-8
|
||||||
|
encoding//src/main/resources/application.properties=UTF-8
|
||||||
|
encoding//src/test/java=UTF-8
|
||||||
|
encoding//src/test/resources=UTF-8
|
||||||
|
encoding/<project>=UTF-8
|
|
@ -0,0 +1,13 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.source=1.8
|
|
@ -0,0 +1,4 @@
|
||||||
|
activeProfiles=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
resolveWorkspaceProjects=true
|
||||||
|
version=1
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||||
|
<wb-module deploy-name="SpringBootBasic-0.0.1-SNAPSHOT">
|
||||||
|
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
|
||||||
|
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||||
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||||
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
||||||
|
<property name="context-root" value="SpringBootBasic"/>
|
||||||
|
<property name="java-output-path" value="/SpringBootBasic/target/classes"/>
|
||||||
|
</wb-module>
|
||||||
|
</project-modules>
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<faceted-project>
|
||||||
|
<fixed facet="wst.jsdt.web"/>
|
||||||
|
<installed facet="wst.jsdt.web" version="1.0"/>
|
||||||
|
<installed facet="java" version="1.8"/>
|
||||||
|
<installed facet="jst.web" version="3.1"/>
|
||||||
|
</faceted-project>
|
|
@ -0,0 +1 @@
|
||||||
|
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
|
|
@ -0,0 +1 @@
|
||||||
|
Window
|
|
@ -0,0 +1,2 @@
|
||||||
|
disabled=06target
|
||||||
|
eclipse.preferences.version=1
|
|
@ -0,0 +1,47 @@
|
||||||
|
<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>
|
||||||
|
<parent>
|
||||||
|
<groupId>zz</groupId>
|
||||||
|
<artifactId>SpringBoot2</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>SpringBootBasic</artifactId>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
|
||||||
|
<!-- Add typical dependencies for a web application -->
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--目的:《可选》引入springboot 热启动,每次修改以后,会自动把改动加载,不需要重启服务了-->
|
||||||
|
<dependency> <groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>8.0.15</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>alimaven</id>
|
||||||
|
<name>aliyun maven</name>
|
||||||
|
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.zz;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
/**
|
||||||
|
* 右键--》run as application 运行正启动类的main方法,就可以启动这个springboot项目。
|
||||||
|
SpringBoot 自带了 tomcat, 运行这个main方法 的时候,会同时启动tomcat
|
||||||
|
* @author jiyu
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
public class App {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
SpringApplication.run(App.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.zz.controller;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 两种controller
|
||||||
|
* 1 @RestController 返回的数据,自动转成了json格式数据。
|
||||||
|
* 2, @Controller 专门用来跳转页面。 返回一个路径
|
||||||
|
* @author jiyu
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
public class IndexController {
|
||||||
|
@RequestMapping("ddd")
|
||||||
|
public String toIndex(){
|
||||||
|
return "index.html";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.zz.controller;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class TestController {
|
||||||
|
|
||||||
|
@RequestMapping("hello")
|
||||||
|
public String t1(){
|
||||||
|
return "hello SpringBoot";
|
||||||
|
}
|
||||||
|
@RequestMapping("test2")
|
||||||
|
public Map t2(){
|
||||||
|
// 多态
|
||||||
|
//变量类型是父类,构造方法是子类
|
||||||
|
Map map=new HashMap();
|
||||||
|
map.put("key1", "你好");
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.zz.controller;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.zz.entity.User;
|
||||||
|
import com.zz.service.UserService;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
@RequestMapping("all")
|
||||||
|
public List<User> getAll(){
|
||||||
|
UserService us=new UserService();
|
||||||
|
List<User> userlist=us.selectAll();
|
||||||
|
return userlist;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("delete")
|
||||||
|
public Map remove(HttpServletRequest request){
|
||||||
|
UserService us=new UserService();
|
||||||
|
String id=request.getParameter("uid");
|
||||||
|
boolean rs=us.deleteById(id);
|
||||||
|
Map map=new HashMap();
|
||||||
|
map.put("result", rs);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.zz.controller;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.zz.entity.User;
|
||||||
|
import com.zz.service.UserService;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
//在类的上面,配置一个拦截路径,那么这个类里面所有方法的
|
||||||
|
//路径前面,必须加上这个us2. 避免和其他类的路径重复
|
||||||
|
@RequestMapping("us2")
|
||||||
|
public class UserController2 {
|
||||||
|
//使用spring的ioc 控制反转。让spring容器帮我们创建对象
|
||||||
|
@Resource
|
||||||
|
UserService us;
|
||||||
|
|
||||||
|
//拦截路径是:http://localhost:9080/a/us2/all
|
||||||
|
@RequestMapping("all")
|
||||||
|
public List<User> getAll(){
|
||||||
|
List<User> userlist=us.selectAll();
|
||||||
|
return userlist;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("delete")
|
||||||
|
public Map remove(HttpServletRequest request){
|
||||||
|
String id=request.getParameter("uid");
|
||||||
|
boolean rs=us.deleteById(id);
|
||||||
|
Map map=new HashMap();
|
||||||
|
map.put("result", rs);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.zz.entity;
|
||||||
|
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private String pwd;
|
||||||
|
private String sex;
|
||||||
|
private int age;
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
public String getPwd() {
|
||||||
|
return pwd;
|
||||||
|
}
|
||||||
|
public void setPwd(String pwd) {
|
||||||
|
this.pwd = pwd;
|
||||||
|
}
|
||||||
|
public String getSex() {
|
||||||
|
return sex;
|
||||||
|
}
|
||||||
|
public void setSex(String sex) {
|
||||||
|
this.sex = sex;
|
||||||
|
}
|
||||||
|
public int getAge() {
|
||||||
|
return age;
|
||||||
|
}
|
||||||
|
public void setAge(int age) {
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,134 @@
|
||||||
|
package com.zz.service;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.zz.entity.User;
|
||||||
|
import com.zz.util.JDBCComon;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UserService {
|
||||||
|
JDBCComon jdbc=new JDBCComon();
|
||||||
|
//登录
|
||||||
|
public User login(String name,String pwd){
|
||||||
|
User user=null;
|
||||||
|
try {
|
||||||
|
Connection conn=jdbc.getConnection();
|
||||||
|
Statement st=conn.createStatement();
|
||||||
|
String sql="select * from user where name='"+name+"' and pwd='"+pwd+"'";
|
||||||
|
System.out.println("sql--->"+sql);
|
||||||
|
ResultSet rss=st.executeQuery(sql);
|
||||||
|
//rss.next()只要 结果集合里,至少有一条记录,next方法就会返回true
|
||||||
|
if(rss.next()){
|
||||||
|
user=new User();
|
||||||
|
user.setId(rss.getString("id"));
|
||||||
|
user.setName(rss.getString("name"));
|
||||||
|
}
|
||||||
|
//从下往上关
|
||||||
|
rss.close();
|
||||||
|
st.close();
|
||||||
|
conn.close();
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
//验证用户名是否存在
|
||||||
|
public User checkName(String name){
|
||||||
|
User user=null;
|
||||||
|
try {
|
||||||
|
Connection conn=jdbc.getConnection();
|
||||||
|
Statement st=conn.createStatement();
|
||||||
|
String sql="select * from user where name='"+name+"' ";
|
||||||
|
System.out.println("sql--->"+sql);
|
||||||
|
ResultSet rss=st.executeQuery(sql);
|
||||||
|
//rss.next()只要 结果集合里,至少有一条记录,next方法就会返回true
|
||||||
|
if(rss.next()){
|
||||||
|
user=new User();
|
||||||
|
user.setId(rss.getString("id"));
|
||||||
|
user.setName(rss.getString("name"));
|
||||||
|
}
|
||||||
|
//从下往上关
|
||||||
|
rss.close();
|
||||||
|
st.close();
|
||||||
|
conn.close();
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<User> selectAll(){
|
||||||
|
List<User> ulist=new ArrayList();
|
||||||
|
try {
|
||||||
|
Connection conn=jdbc.getConnection();
|
||||||
|
Statement st=conn.createStatement();
|
||||||
|
String sql="select * from user ";
|
||||||
|
System.out.println("sql--->"+sql);
|
||||||
|
ResultSet rss=st.executeQuery(sql);
|
||||||
|
//rss.next()只要 结果集合里,至少有一条记录,next方法就会返回true
|
||||||
|
while(rss.next()){
|
||||||
|
User user=new User();
|
||||||
|
user.setId(rss.getString("id"));
|
||||||
|
user.setName(rss.getString("name"));
|
||||||
|
user.setAge(rss.getInt("age"));
|
||||||
|
ulist.add(user);
|
||||||
|
}
|
||||||
|
//从下往上关
|
||||||
|
rss.close();
|
||||||
|
st.close();
|
||||||
|
conn.close();
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ulist;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean deleteById(String id){
|
||||||
|
Connection conn;
|
||||||
|
boolean flag=false;
|
||||||
|
try {
|
||||||
|
conn = jdbc.getConnection();
|
||||||
|
String sql="delete from user where id=?";
|
||||||
|
PreparedStatement st=conn.prepareStatement(sql);
|
||||||
|
st.setString(1, id);
|
||||||
|
if(st.executeUpdate()>0){
|
||||||
|
flag=true;
|
||||||
|
};
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.zz.util;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class JDBCComon {
|
||||||
|
|
||||||
|
public Connection getConnection() throws ClassNotFoundException, SQLException{
|
||||||
|
|
||||||
|
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||||
|
//java10是数据库的名字
|
||||||
|
String url="jdbc:mysql://localhost:3306/java10?useSSL=false&serverTimezone=Asia/Shanghai";
|
||||||
|
//登录数据库用户名
|
||||||
|
String username="root";
|
||||||
|
//登录数据库密码
|
||||||
|
String pwd="Java20190713*yy";
|
||||||
|
Connection conn = DriverManager.getConnection(url,username,pwd);
|
||||||
|
return conn;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
//设置项目的端口号
|
||||||
|
server.port=9080
|
||||||
|
//设置工程名字
|
||||||
|
// 所有路径都需要加a. http:localhost:9080/a/all
|
||||||
|
server.servlet.context-path=/a
|
|
@ -0,0 +1,10 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Insert title here</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
hello controller
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,84 @@
|
||||||
|
$(document).ready(function(){
|
||||||
|
// 在这里写你的代码...
|
||||||
|
$.getJSON("all", function(json){
|
||||||
|
console.log(json);
|
||||||
|
$("#tbodymainbtn").empty();
|
||||||
|
for(var i=0;i<json.length;i++){
|
||||||
|
$("#tbodymainbtn").append(
|
||||||
|
"<tr id='tridval"+i+"'>"
|
||||||
|
+"<td>"+ json[i].id
|
||||||
|
+"</td>"
|
||||||
|
+"<td>"+ json[i].name
|
||||||
|
+"</td>"
|
||||||
|
+"<td>"+ json[i].age
|
||||||
|
+"</td>"
|
||||||
|
+"<td><button type='button' name='btn001' class='btn btn-info btn-sm' id='btn1"+i+"'>修改</button>" +"   <button type='button' name='btn003' class='btn btn-danger btn-sm' id='btn3"+json[i].id +"'>删除</button>"
|
||||||
|
+"</td></tr>"
|
||||||
|
);
|
||||||
|
$("#tbodymainbtn").append(
|
||||||
|
"<tr style='display:none' id='tridval2"+i+"'><form>"
|
||||||
|
+"<td><input type='text' value='"+ json[i].id
|
||||||
|
+"'/></td>"
|
||||||
|
+"<td><input type='text' id='name2"+i+"' value='"+ json[i].name
|
||||||
|
+"'/></td>"
|
||||||
|
+"<td><input type='text' id='age2"+i+"' value='"+ json[i].age
|
||||||
|
+"'/></td>"
|
||||||
|
+"<td><button type='button' name='btn002' class='btn btn-primary btn-sm' id='btn2"+i+"'>保存</button>"
|
||||||
|
+"</td></form></tr>"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//jquery 样式查找 “点+样式名字”
|
||||||
|
$("button[name='btn001']").click(function(){
|
||||||
|
var id=this.id;
|
||||||
|
//截取剩余
|
||||||
|
var numb = id.slice(4);
|
||||||
|
console.log("****************"+id);
|
||||||
|
$("#tridval"+numb).hide();
|
||||||
|
$("#tridval2"+numb).show();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$("button[name='btn002']").click(function(){
|
||||||
|
var id=this.id;
|
||||||
|
//截取剩余
|
||||||
|
var numb = id.slice(4);
|
||||||
|
console.log("****************"+id);
|
||||||
|
var nval=$("#name2"+numb).val();
|
||||||
|
var aval=$("#age2"+numb).val();
|
||||||
|
console.log("********name2********"+nval);
|
||||||
|
console.log("********age2********"+aval);
|
||||||
|
|
||||||
|
$("#tridval"+numb).show();
|
||||||
|
$("#tridval2"+numb).hide();
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$("button[name='btn003']").click(function(){
|
||||||
|
var id=this.id;
|
||||||
|
//截取剩余
|
||||||
|
var numb = id.slice(4);
|
||||||
|
console.log("****************"+id);
|
||||||
|
console.log("****************"+numb);
|
||||||
|
|
||||||
|
$.getJSON("delete", { uid: numb}, function(json){
|
||||||
|
console.log("******delete**********"+numb,json);
|
||||||
|
window.location.href="table.html"
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});//$.getJSON("UserServlet", function(json){
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>用户管理</title>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
|
||||||
|
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
|
||||||
|
<script src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script>
|
||||||
|
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<h2>用户管理</h2>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>学号</th>
|
||||||
|
<th>姓名</th>
|
||||||
|
<th>年龄</th>
|
||||||
|
<th>操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="tbodymainbtn">
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script type="text/javascript" src="js/table.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,5 @@
|
||||||
|
//设置项目的端口号
|
||||||
|
server.port=9080
|
||||||
|
//设置工程名字
|
||||||
|
// 所有路径都需要加a. http:localhost:9080/a/all
|
||||||
|
server.servlet.context-path=/a
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,10 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Insert title here</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
hello controller
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,84 @@
|
||||||
|
$(document).ready(function(){
|
||||||
|
// 在这里写你的代码...
|
||||||
|
$.getJSON("all", function(json){
|
||||||
|
console.log(json);
|
||||||
|
$("#tbodymainbtn").empty();
|
||||||
|
for(var i=0;i<json.length;i++){
|
||||||
|
$("#tbodymainbtn").append(
|
||||||
|
"<tr id='tridval"+i+"'>"
|
||||||
|
+"<td>"+ json[i].id
|
||||||
|
+"</td>"
|
||||||
|
+"<td>"+ json[i].name
|
||||||
|
+"</td>"
|
||||||
|
+"<td>"+ json[i].age
|
||||||
|
+"</td>"
|
||||||
|
+"<td><button type='button' name='btn001' class='btn btn-info btn-sm' id='btn1"+i+"'>修改</button>" +"   <button type='button' name='btn003' class='btn btn-danger btn-sm' id='btn3"+json[i].id +"'>删除</button>"
|
||||||
|
+"</td></tr>"
|
||||||
|
);
|
||||||
|
$("#tbodymainbtn").append(
|
||||||
|
"<tr style='display:none' id='tridval2"+i+"'><form>"
|
||||||
|
+"<td><input type='text' value='"+ json[i].id
|
||||||
|
+"'/></td>"
|
||||||
|
+"<td><input type='text' id='name2"+i+"' value='"+ json[i].name
|
||||||
|
+"'/></td>"
|
||||||
|
+"<td><input type='text' id='age2"+i+"' value='"+ json[i].age
|
||||||
|
+"'/></td>"
|
||||||
|
+"<td><button type='button' name='btn002' class='btn btn-primary btn-sm' id='btn2"+i+"'>保存</button>"
|
||||||
|
+"</td></form></tr>"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//jquery 样式查找 “点+样式名字”
|
||||||
|
$("button[name='btn001']").click(function(){
|
||||||
|
var id=this.id;
|
||||||
|
//截取剩余
|
||||||
|
var numb = id.slice(4);
|
||||||
|
console.log("****************"+id);
|
||||||
|
$("#tridval"+numb).hide();
|
||||||
|
$("#tridval2"+numb).show();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$("button[name='btn002']").click(function(){
|
||||||
|
var id=this.id;
|
||||||
|
//截取剩余
|
||||||
|
var numb = id.slice(4);
|
||||||
|
console.log("****************"+id);
|
||||||
|
var nval=$("#name2"+numb).val();
|
||||||
|
var aval=$("#age2"+numb).val();
|
||||||
|
console.log("********name2********"+nval);
|
||||||
|
console.log("********age2********"+aval);
|
||||||
|
|
||||||
|
$("#tridval"+numb).show();
|
||||||
|
$("#tridval2"+numb).hide();
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$("button[name='btn003']").click(function(){
|
||||||
|
var id=this.id;
|
||||||
|
//截取剩余
|
||||||
|
var numb = id.slice(4);
|
||||||
|
console.log("****************"+id);
|
||||||
|
console.log("****************"+numb);
|
||||||
|
|
||||||
|
$.getJSON("delete", { uid: numb}, function(json){
|
||||||
|
console.log("******delete**********"+numb,json);
|
||||||
|
window.location.href="table.html"
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});//$.getJSON("UserServlet", function(json){
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>用户管理</title>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
|
||||||
|
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
|
||||||
|
<script src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script>
|
||||||
|
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<h2>用户管理</h2>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>学号</th>
|
||||||
|
<th>姓名</th>
|
||||||
|
<th>年龄</th>
|
||||||
|
<th>操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="tbodymainbtn">
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script type="text/javascript" src="js/table.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,6 @@
|
||||||
|
Manifest-Version: 1.0
|
||||||
|
Implementation-Title: SpringBootBasic
|
||||||
|
Implementation-Version: 0.0.1-SNAPSHOT
|
||||||
|
Build-Jdk-Spec: 1.8
|
||||||
|
Created-By: Maven Integration for Eclipse
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#Generated by Maven Integration for Eclipse
|
||||||
|
#Fri Aug 16 12:03:08 CST 2019
|
||||||
|
version=0.0.1-SNAPSHOT
|
||||||
|
groupId=zz
|
||||||
|
m2e.projectName=SpringBootBasic
|
||||||
|
m2e.projectLocation=C\:\\bsea\\wp\\2019\\07\\02\\SpringBoot2\\SpringBootBasic
|
||||||
|
artifactId=SpringBootBasic
|
|
@ -0,0 +1,47 @@
|
||||||
|
<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>
|
||||||
|
<parent>
|
||||||
|
<groupId>zz</groupId>
|
||||||
|
<artifactId>SpringBoot2</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>SpringBootBasic</artifactId>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
|
||||||
|
<!-- Add typical dependencies for a web application -->
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--目的:《可选》引入springboot 热启动,每次修改以后,会自动把改动加载,不需要重启服务了-->
|
||||||
|
<dependency> <groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>8.0.15</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>alimaven</id>
|
||||||
|
<name>aliyun maven</name>
|
||||||
|
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,3 @@
|
||||||
|
version=0.0.1-SNAPSHOT
|
||||||
|
groupId=zz
|
||||||
|
artifactId=SpringBootBasic
|
|
@ -0,0 +1,2 @@
|
||||||
|
com\zz\App.class
|
||||||
|
com\zz\controller\TestController.class
|
|
@ -0,0 +1,2 @@
|
||||||
|
C:\bsea\wp\2019\07\02\SpringBoot2\SpringBootBasic\src\main\java\com\zz\App.java
|
||||||
|
C:\bsea\wp\2019\07\02\SpringBoot2\SpringBootBasic\src\main\java\com\zz\controller\TestController.java
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
|
</classpath>
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>SpringBootFile</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
|
@ -0,0 +1,7 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding//src/main/java=UTF-8
|
||||||
|
encoding//src/main/resources=UTF-8
|
||||||
|
encoding//src/main/resources/application.properties=UTF-8
|
||||||
|
encoding//src/test/java=UTF-8
|
||||||
|
encoding//src/test/resources=UTF-8
|
||||||
|
encoding/<project>=UTF-8
|
|
@ -0,0 +1,5 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||||
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.source=1.8
|
|
@ -0,0 +1,4 @@
|
||||||
|
activeProfiles=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
resolveWorkspaceProjects=true
|
||||||
|
version=1
|
|
@ -0,0 +1,45 @@
|
||||||
|
<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>
|
||||||
|
<parent>
|
||||||
|
<groupId>zz</groupId>
|
||||||
|
<artifactId>SpringBoot2</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>SpringBootFile</artifactId>
|
||||||
|
<!-- Add typical dependencies for a web application -->
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--目的:《可选》引入springboot 热启动,每次修改以后,会自动把改动加载,不需要重启服务了-->
|
||||||
|
<dependency> <groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>8.0.15</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>alimaven</id>
|
||||||
|
<name>aliyun maven</name>
|
||||||
|
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.zz;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
/**
|
||||||
|
* 右键--》run as application 运行正启动类的main方法,就可以启动这个springboot项目。
|
||||||
|
SpringBoot 自带了 tomcat, 运行这个main方法 的时候,会同时启动tomcat
|
||||||
|
* @author jiyu
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
public class App {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
SpringApplication.run(App.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.zz.controller;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
@RestController
|
||||||
|
public class FileController {
|
||||||
|
//@Value 获取配置文件里面的属性值,并且赋值给下面的属性
|
||||||
|
|
||||||
|
@Value("${fileUpLoadPath}")
|
||||||
|
String filePath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @RequestMapping 表示同时支持接收post和get请求。
|
||||||
|
* 如果加上method=RequestMethod.POST, 表示只接收post请求
|
||||||
|
* 其实有一个注解可以直接指定,只接收post请求---@PostMapping
|
||||||
|
* @param req
|
||||||
|
* @param multiReq
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@PostMapping("/testUpload3")
|
||||||
|
// @RequestMapping(value="/testUpload3",method=RequestMethod.POST)
|
||||||
|
public void testUploadFile(HttpServletRequest req,MultipartHttpServletRequest multiReq) throws IOException{
|
||||||
|
MultipartFile multipartFile= multiReq.getFile("file");
|
||||||
|
String filename=multipartFile.getOriginalFilename();
|
||||||
|
System.out.println("文件名字:"+multipartFile.getOriginalFilename());
|
||||||
|
File file=new File(filePath+filename);
|
||||||
|
multipartFile.transferTo(file);
|
||||||
|
String username=req.getParameter("username");
|
||||||
|
System.out.println("用户名字:"+username);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
server.port=9083
|
||||||
|
server.servlet.context-path=/d
|
||||||
|
spring.servlet.multipart.max-file-size=100MB
|
||||||
|
spring.servlet.multipart.max-request-size=100MB
|
||||||
|
fileUpLoadPath=C://tmp//
|
|
@ -0,0 +1,25 @@
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
|
<title>Insert title here</title>
|
||||||
|
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form id="formId" action="/d/testUpload3" target="frame1" method="POST" enctype="multipart/form-data">
|
||||||
|
<input type="text" name="username"></input>
|
||||||
|
<input type="file" name="file"/>
|
||||||
|
<input type="button" value="提交" onclick="upload()">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<iframe name="frame1" frameborder="0" height="40"></iframe>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
function upload() {
|
||||||
|
$("#formId").submit();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,7 @@
|
||||||
|
#Generated by Maven Integration for Eclipse
|
||||||
|
#Wed Aug 14 20:43:23 CST 2019
|
||||||
|
version=0.0.1-SNAPSHOT
|
||||||
|
groupId=zz
|
||||||
|
m2e.projectName=SpringBootFile
|
||||||
|
m2e.projectLocation=C\:\\bsea\\wp\\2019\\07\\02\\SpringBoot2\\SpringBootFile
|
||||||
|
artifactId=SpringBootFile
|
|
@ -0,0 +1,45 @@
|
||||||
|
<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>
|
||||||
|
<parent>
|
||||||
|
<groupId>zz</groupId>
|
||||||
|
<artifactId>SpringBoot2</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>SpringBootFile</artifactId>
|
||||||
|
<!-- Add typical dependencies for a web application -->
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--目的:《可选》引入springboot 热启动,每次修改以后,会自动把改动加载,不需要重启服务了-->
|
||||||
|
<dependency> <groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>8.0.15</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>alimaven</id>
|
||||||
|
<name>aliyun maven</name>
|
||||||
|
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,5 @@
|
||||||
|
server.port=9083
|
||||||
|
server.servlet.context-path=/d
|
||||||
|
spring.servlet.multipart.max-file-size=100MB
|
||||||
|
spring.servlet.multipart.max-request-size=100MB
|
||||||
|
fileUpLoadPath=C://tmp//
|
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue