Commit 44c0de47edbf25e308499abdfa52a33d1361349d

Authored by 陶汉栋
1 parent 9e0d66b1
Exists in master

no message

springboot/pom.xml
@@ -26,6 +26,11 @@ @@ -26,6 +26,11 @@
26 26
27 <dependency> 27 <dependency>
28 <groupId>org.springframework.boot</groupId> 28 <groupId>org.springframework.boot</groupId>
  29 + <artifactId>spring-boot-starter-jdbc</artifactId>
  30 + </dependency>
  31 +
  32 + <dependency>
  33 + <groupId>org.springframework.boot</groupId>
29 <artifactId>spring-boot-starter-test</artifactId> 34 <artifactId>spring-boot-starter-test</artifactId>
30 <scope>test</scope> 35 <scope>test</scope>
31 </dependency> 36 </dependency>
@@ -46,8 +51,7 @@ @@ -46,8 +51,7 @@
46 <dependency> 51 <dependency>
47 <groupId>com.microsoft.sqlserver</groupId> 52 <groupId>com.microsoft.sqlserver</groupId>
48 <artifactId>mssql-jdbc</artifactId> 53 <artifactId>mssql-jdbc</artifactId>
49 - <version>7.2.1.jre8</version>  
50 - <scope>test</scope> 54 + <scope>runtime</scope>
51 </dependency> 55 </dependency>
52 56
53 <dependency> 57 <dependency>
springboot/src/main/java/com/sincre/springboot/SpringbootApplication.java
@@ -10,24 +10,24 @@ import java.awt.*; @@ -10,24 +10,24 @@ import java.awt.*;
10 10
11 @MapperScan("com.sincre.springboot.mapper") 11 @MapperScan("com.sincre.springboot.mapper")
12 @SpringBootApplication 12 @SpringBootApplication
13 -public class SpringbootApplication{ 13 +public class SpringbootApplication {
14 14
15 public static void main(String[] args) { 15 public static void main(String[] args) {
16 16
17 SpringApplication.run(SpringbootApplication.class, args); 17 SpringApplication.run(SpringbootApplication.class, args);
18 - System.out.println("classpath:"+new SpringbootApplication().getClass().getResource("")); 18 + System.out.println("classpath:" + new SpringbootApplication().getClass().getResource(""));
19 19
20 // new SpringbootApplication().initFrame(); 20 // new SpringbootApplication().initFrame();
21 } 21 }
22 22
23 - private void initFrame(){ 23 + private void initFrame() {
24 JFrame jFrame = new JFrame(); 24 JFrame jFrame = new JFrame();
25 //设置窗口是否可视 25 //设置窗口是否可视
26 jFrame.setVisible(true); 26 jFrame.setVisible(true);
27 //设置窗口的大小是否可以调节 27 //设置窗口的大小是否可以调节
28 jFrame.setResizable(false); 28 jFrame.setResizable(false);
29 //设置窗口大小和x,y位置 29 //设置窗口大小和x,y位置
30 - jFrame.setBounds(100,100, 600, 800); 30 + jFrame.setBounds(100, 100, 600, 800);
31 //设置窗口退出则程序退出 31 //设置窗口退出则程序退出
32 jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 32 jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
33 } 33 }
springboot/src/main/java/com/sincre/springboot/Swagger2.java
@@ -15,7 +15,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; @@ -15,7 +15,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
15 public class Swagger2 { 15 public class Swagger2 {
16 16
17 @Bean 17 @Bean
18 - public Docket createRestApi(){ 18 + public Docket createRestApi() {
19 return new Docket(DocumentationType.SWAGGER_2) 19 return new Docket(DocumentationType.SWAGGER_2)
20 .apiInfo(apiInfo()) 20 .apiInfo(apiInfo())
21 .select() 21 .select()
@@ -24,7 +24,7 @@ public class Swagger2 { @@ -24,7 +24,7 @@ public class Swagger2 {
24 .build(); 24 .build();
25 } 25 }
26 26
27 - private ApiInfo apiInfo(){ 27 + private ApiInfo apiInfo() {
28 return new ApiInfoBuilder() 28 return new ApiInfoBuilder()
29 .title("Spring Boot中使用Swagger2") 29 .title("Spring Boot中使用Swagger2")
30 .contact("Mr.Tao") 30 .contact("Mr.Tao")
springboot/src/main/java/com/sincre/springboot/controller/UserController.java
@@ -50,8 +50,8 @@ public class UserController { @@ -50,8 +50,8 @@ public class UserController {
50 return "登录成功"; 50 return "登录成功";
51 } 51 }
52 52
53 - @RequestMapping(method = RequestMethod.GET,value = "getImg")  
54 - public String getImg(){ 53 + @RequestMapping(method = RequestMethod.GET, value = "getImg")
  54 + public String getImg() {
55 return FileUtils.getImageStr("C:\\Users\\taohandong\\Desktop\\微耕.png"); 55 return FileUtils.getImageStr("C:\\Users\\taohandong\\Desktop\\微耕.png");
56 } 56 }
57 57
springboot/src/main/java/com/sincre/springboot/mapper/UserMapper.java
@@ -9,9 +9,9 @@ import org.springframework.stereotype.Repository; @@ -9,9 +9,9 @@ import org.springframework.stereotype.Repository;
9 @Repository 9 @Repository
10 public interface UserMapper { 10 public interface UserMapper {
11 11
12 - public User login(@Param("userName") String userName,@Param("password") String password); 12 + public User login(@Param("userName") String userName, @Param("password") String password);
13 13
14 - public boolean register(@Param("username") String username,@Param("password") String password); 14 + public boolean register(@Param("username") String username, @Param("password") String password);
15 15
16 - public User isExit(@Param("username")String username); 16 + public User isExit(@Param("username") String username);
17 } 17 }
springboot/src/main/java/com/sincre/springboot/server/UserServer.java
@@ -7,9 +7,9 @@ public interface UserServer { @@ -7,9 +7,9 @@ public interface UserServer {
7 7
8 public boolean insertUser(User user); 8 public boolean insertUser(User user);
9 9
10 - public User login(String loginname,String password); 10 + public User login(String loginname, String password);
11 11
12 - public boolean registr(String username,String password); 12 + public boolean registr(String username, String password);
13 13
14 public User isExit(String username); 14 public User isExit(String username);
15 } 15 }
springboot/src/main/java/com/sincre/springboot/server/UserServerImp.java
@@ -19,12 +19,12 @@ public class UserServerImp implements UserServer { @@ -19,12 +19,12 @@ public class UserServerImp implements UserServer {
19 19
20 @Override 20 @Override
21 public User login(String loginname, String password) { 21 public User login(String loginname, String password) {
22 - return userMapper.login(loginname,password); 22 + return userMapper.login(loginname, password);
23 } 23 }
24 24
25 @Override 25 @Override
26 public boolean registr(String username, String password) { 26 public boolean registr(String username, String password) {
27 - return userMapper.register(username,password); 27 + return userMapper.register(username, password);
28 } 28 }
29 29
30 @Override 30 @Override
springboot/src/main/java/com/sincre/springboot/utils/FileUtils.java
@@ -41,10 +41,10 @@ public class FileUtils { @@ -41,10 +41,10 @@ public class FileUtils {
41 } 41 }
42 42
43 /** 43 /**
  44 + * @return
44 * @Description: 根据图片地址转换为base64编码字符串 45 * @Description: 根据图片地址转换为base64编码字符串
45 * @Author: 46 * @Author:
46 * @CreateTime: 47 * @CreateTime:
47 - * @return  
48 */ 48 */
49 public static String getImageStr(String imgFile) { 49 public static String getImageStr(String imgFile) {
50 InputStream inputStream = null; 50 InputStream inputStream = null;
springboot/src/main/resources/application.properties
1 server.port=1111 1 server.port=1111
2 -  
3 # ÉèÖÃÊý¾Ý¿âÏà¹ØÊôÐÔ 2 # ÉèÖÃÊý¾Ý¿âÏà¹ØÊôÐÔ
4 spring.datasource.username=thd 3 spring.datasource.username=thd
5 spring.datasource.password=pmd19930415A 4 spring.datasource.password=pmd19930415A
6 spring.datasource.url=jdbc:sqlserver://60.190.202.57:14333;database=test 5 spring.datasource.url=jdbc:sqlserver://60.190.202.57:14333;database=test
7 spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver 6 spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
8 -  
9 mybatis.config-location=classpath:mybatis-config.xml 7 mybatis.config-location=classpath:mybatis-config.xml
10 mybatis.mapper-locations=classpath:/mapper/*.xml 8 mybatis.mapper-locations=classpath:/mapper/*.xml
11 mybatis.type-aliases-package=com.sincre.springboot.model 9 mybatis.type-aliases-package=com.sincre.springboot.model
12 \ No newline at end of file 10 \ No newline at end of file
springboot/src/main/resources/mapper/usermapper.xml
@@ -8,13 +8,13 @@ @@ -8,13 +8,13 @@
8 select * 8 select *
9 from "User" 9 from "User"
10 where username = #{userName} 10 where username = #{userName}
11 - and password = #{password} 11 + and password = #{password}
12 </select> 12 </select>
13 13
14 <insert id="register" parameterType="com.sincre.springboot.model.User" 14 <insert id="register" parameterType="com.sincre.springboot.model.User"
15 useGeneratedKeys="true"> 15 useGeneratedKeys="true">
16 <!--<selectKey keyProperty="id" resultType="int" order="BEFORE">--> 16 <!--<selectKey keyProperty="id" resultType="int" order="BEFORE">-->
17 --- SELECT LAST_INSERT_ID() AS ID 17 + -- SELECT LAST_INSERT_ID() AS ID
18 <!--</selectKey>--> 18 <!--</selectKey>-->
19 insert into "User"(username, password) VALUES (#{username},#{password}) 19 insert into "User"(username, password) VALUES (#{username},#{password})
20 </insert> 20 </insert>