Skip to content

Commit 04c2eaf

Browse files
committed
answer coder
0 parents  commit 04c2eaf

File tree

16 files changed

+576
-0
lines changed

16 files changed

+576
-0
lines changed

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
*.iml
2+
target/*
3+
.idea/*
4+
mvnw.cmd
5+
mvnw
6+
.mvn/*
7+
8+
/target/
9+
!.mvn/wrapper/maven-wrapper.jar
10+
11+
### STS ###
12+
.apt_generated
13+
.classpath
14+
.factorypath
15+
.project
16+
.settings
17+
.springBeans
18+
.sts4-cache
19+
20+
### IntelliJ IDEA ###
21+
.idea
22+
*.iws
23+
*.iml
24+
*.ipr
25+
26+
### NetBeans ###
27+
/nbproject/private/
28+
/build/
29+
/nbbuild/
30+
/dist/
31+
/nbdist/
32+
/.nb-gradle/

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SpringBoot-Mybatis-Web
2+
- SpringBoot实现基础Web框架
3+
4+
### 新建项目步骤(以IDEA为例)
5+
1. File -> New -> Project -> Spring Initializr -> Next(选择JDK版本)
6+
2. 设置 Group 和 Artifact 值
7+
- Group: com.answer 域.公司名称
8+
- 域: com(商业组织) org(非营利组织)
9+
- Artifact: springboot-mybatis-web 项目名称
10+
11+
### 启动服务
12+
```bash
13+
nohup java -jar springboot-mybatis-web-0.0.1-SNAPSHOT.jar >> smw.log 2>&1 &
14+
```

pom.xml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.answer</groupId>
7+
<artifactId>springboot-mybatis-web</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>springboot-mybatis-web</name>
12+
<description>Demo project for Spring Boot</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>2.0.5.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-web</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.mybatis.spring.boot</groupId>
34+
<artifactId>mybatis-spring-boot-starter</artifactId>
35+
<version>1.3.2</version>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>mysql</groupId>
40+
<artifactId>mysql-connector-java</artifactId>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter-test</artifactId>
45+
<scope>test</scope>
46+
</dependency>
47+
48+
<!-- Web for Jsp need start -->
49+
<dependency>
50+
<groupId>javax.servlet</groupId>
51+
<artifactId>jstl</artifactId>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.springframework.boot</groupId>
55+
<artifactId>spring-boot-starter-tomcat</artifactId>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.apache.tomcat.embed</groupId>
59+
<artifactId>tomcat-embed-jasper</artifactId>
60+
</dependency>
61+
<dependency>
62+
<groupId>javax.servlet</groupId>
63+
<artifactId>javax.servlet-api</artifactId>
64+
</dependency>
65+
<!-- Web for Jsp need end -->
66+
67+
</dependencies>
68+
69+
<build>
70+
<plugins>
71+
<plugin>
72+
<groupId>org.springframework.boot</groupId>
73+
<artifactId>spring-boot-maven-plugin</artifactId>
74+
<version>1.4.2.RELEASE</version>
75+
</plugin>
76+
</plugins>
77+
78+
<!-- 解决打包时访问不了JSP问题 -->
79+
<resources>
80+
<!-- 打包时将jsp文件拷贝到META-INF目录下-->
81+
<resource>
82+
<!-- 指定resources插件处理哪个目录下的资源文件 -->
83+
<directory>src/main/webapp</directory>
84+
<!--注意此次必须要放在此目录下才能被访问到-->
85+
<targetPath>META-INF/resources</targetPath>
86+
<includes>
87+
<include>**/**</include>
88+
</includes>
89+
</resource>
90+
<resource>
91+
<directory>src/main/resources</directory>
92+
<includes>
93+
<include>**/**</include>
94+
</includes>
95+
<filtering>false</filtering>
96+
</resource>
97+
<resource>
98+
<directory>src/main/java</directory>
99+
<excludes>
100+
<exclude>**/*.java</exclude>
101+
</excludes>
102+
</resource>
103+
</resources>
104+
</build>
105+
106+
107+
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.answer.springboot;
2+
3+
import org.mybatis.spring.annotation.MapperScan;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.context.annotation.ComponentScan;
7+
8+
@SpringBootApplication
9+
@ComponentScan(basePackages = {"com.answer.springboot.mybatis.web.service", "com.answer.springboot.mybatis.web.controller"})
10+
@MapperScan(basePackages = {"com.answer.springboot.mybatis.web.dao"})
11+
public class SpringbootMybatisWebApplication {
12+
13+
public static void main(String[] args) {
14+
SpringApplication.run(SpringbootMybatisWebApplication.class, args);
15+
}
16+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.answer.springboot.mybatis.web.controller;
2+
3+
import com.answer.springboot.mybatis.web.entity.User;
4+
import com.answer.springboot.mybatis.web.service.IUserService;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.stereotype.Controller;
9+
import org.springframework.ui.Model;
10+
import org.springframework.web.bind.annotation.RequestMapping;
11+
import org.springframework.web.bind.annotation.ResponseBody;
12+
import org.springframework.web.servlet.ModelAndView;
13+
14+
import java.util.List;
15+
16+
/**
17+
* Created by L.Answer on 2018-10-16 10:53
18+
*/
19+
20+
@Controller
21+
@RequestMapping("/user")
22+
public class UserController {
23+
24+
private static final Logger logger = LoggerFactory.getLogger(UserController.class);
25+
26+
@Autowired
27+
private IUserService userService;
28+
29+
30+
@RequestMapping("index")
31+
public String index(Model model) {
32+
logger.info("enter index.jsp.");
33+
User user = new User();
34+
user.setUserName("answerCoder");
35+
model.addAttribute("user", user);
36+
model.addAttribute("age", "7");
37+
return "index";
38+
}
39+
40+
41+
@RequestMapping("findUsers")
42+
@ResponseBody
43+
public List<User> findUsers() {
44+
logger.info("find users start.");
45+
List<User> users = userService.findUsers();
46+
logger.info("users size: " + users.size());
47+
return users;
48+
}
49+
50+
51+
52+
53+
54+
55+
56+
57+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.answer.springboot.mybatis.web.dao;
2+
3+
import com.answer.springboot.mybatis.web.entity.User;
4+
5+
import java.util.List;
6+
7+
/**
8+
* Created by L.Answer on 2018-10-16 10:25
9+
*/
10+
public interface UserDao {
11+
12+
int insertUser(User user);
13+
14+
int deleteUser(Long id);
15+
16+
int updateUser(User user);
17+
18+
List<User> findUsers();
19+
20+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.answer.springboot.mybatis.web.entity;
2+
3+
/**
4+
* Created by L.Answer on 2018-10-16 10:13
5+
*/
6+
public class User {
7+
8+
private Long id;
9+
private String userName;
10+
private Integer sex;
11+
private String password;
12+
private String email;
13+
private String address;
14+
private String createTime;
15+
private String updateTime;
16+
17+
18+
public Long getId() {
19+
return id;
20+
}
21+
22+
public void setId(Long id) {
23+
this.id = id;
24+
}
25+
26+
public String getUserName() {
27+
return userName;
28+
}
29+
30+
public void setUserName(String userName) {
31+
this.userName = userName;
32+
}
33+
34+
public Integer getSex() {
35+
return sex;
36+
}
37+
38+
public void setSex(Integer sex) {
39+
this.sex = sex;
40+
}
41+
42+
public String getPassword() {
43+
return password;
44+
}
45+
46+
public void setPassword(String password) {
47+
this.password = password;
48+
}
49+
50+
public String getEmail() {
51+
return email;
52+
}
53+
54+
public void setEmail(String email) {
55+
this.email = email;
56+
}
57+
58+
public String getAddress() {
59+
return address;
60+
}
61+
62+
public void setAddress(String address) {
63+
this.address = address;
64+
}
65+
66+
public String getCreateTime() {
67+
return createTime;
68+
}
69+
70+
public void setCreateTime(String createTime) {
71+
this.createTime = createTime;
72+
}
73+
74+
public String getUpdateTime() {
75+
return updateTime;
76+
}
77+
78+
public void setUpdateTime(String updateTime) {
79+
this.updateTime = updateTime;
80+
}
81+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.answer.springboot.mybatis.web.service;
2+
3+
import com.answer.springboot.mybatis.web.entity.User;
4+
5+
import java.util.List;
6+
7+
/**
8+
* Created by L.Answer on 2018-10-16 10:27
9+
*/
10+
public interface IUserService {
11+
12+
int insertUser(User user);
13+
14+
int deleteUser(Long id);
15+
16+
int updateUser(User user);
17+
18+
List<User> findUsers();
19+
20+
}

0 commit comments

Comments
 (0)