第一个SpringBoot+MyBatis+JSR303项目
来源:互联网 发布:淘宝设计团队 编辑:程序博客网 时间:2024/06/08 03:29
Maven的包基本就这些,现在大多数使用springboot的项目应该都是使用jdk1.8的吧,所以项目的jdk设置成1.8
POM.xml
<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>springboot</groupId> <artifactId>hellowold</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>hellowold Maven Webapp</name> <url>http://maven.apache.org</url> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.RELEASE</version> </parent> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter --> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok-maven-plugin --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok-maven-plugin</artifactId> <version>1.16.18.1</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.18</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> </dependency> </dependencies> <properties> <java.version>1.8</java.version> </properties> <build> <finalName>hellowold</finalName> </build></project>
server: port: 80spring: datasource: name: test url: jdbc:mysql://192.168.1.105:3306/test username: root password: 123456 # 使用druid数据源 type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver filters: stat maxActive: 20 initialSize: 1 maxWait: 60000 minIdle: 1 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: select 'x' testWhileIdle: true testOnBorrow: false testOnReturn: false poolPreparedStatements: true maxOpenPreparedStatements: 20mybatis: mapperLocations: classpath:app/com/kenho/mapper/*Mapper.xml
SpringBoot的启动文件放的位置比较讲究,基本上把启动文件放在一个包下,然后项目的需要的各种累放在启动文件下的下级目录,这样启动的时候才能被扫描的到,所以控制类,服务类,dao类。就要添加上@RestController @Service @Repository注解,SpringBoot现在用REST风格比较多,所以使用的注解式@RestController他等于@ResponseBody+@Controller,其次就是控制类的bean注入最好是引用@Resource,因为@Resource是按照名字进行匹配,找不到匹配的bean才进行类型的匹配
package app.com.kenho.web.controller;import app.com.kenho.domain.Logininfo;import app.com.kenho.service.ILoginService;import app.com.kenho.service.impl.LoginServiceImpl;import org.springframework.validation.BindingResult;import org.springframework.validation.ObjectError;import org.springframework.validation.annotation.Validated;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RestController;import javax.annotation.Resource;import javax.naming.Binding;import javax.validation.Valid;import java.util.List;/** * Created by Stephanie on 2017/8/19. */@RestControllerpublic class indexController { @Resource private ILoginService loginServiceImpl; @RequestMapping(value = "logininfo/{username}/{password}",method = RequestMethod.GET) public Logininfo getlogininfo(@PathVariable("username")String username,@PathVariable("password")String password) { //loginServiceImpl.getLoginInfo("stephanie","81DC9BDB52D04DC20036DBD8313ED055"); return loginServiceImpl.getLoginInfo(username,password); } @RequestMapping(value = "logininfo",method = RequestMethod.POST) public void valid(@Validated Logininfo logininfo, BindingResult bindingResult) { if(bindingResult.hasErrors()) { List<ObjectError> list = bindingResult.getAllErrors(); StringBuilder stringBuilder = new StringBuilder(); for(ObjectError error:list){ System.out.println("\n"+error.getDefaultMessage()); } } else { loginServiceImpl.insert(logininfo); } }}
获取数据
jsr303校验
阅读全文
0 0
- 第一个SpringBoot+MyBatis+JSR303项目
- SpringBoot 第一个项目
- 第一个SpringBoot项目
- springboot+mybatis+swagger+redis+mysql搭建的第一个项目
- 创建第一个SpringBoot项目
- springboot(一) 创建第一个springboot项目
- 002_第一个SpringBoot项目
- 使用springboot创建第一个helloworld项目
- 第一个springBoot项目,使用模板渲染
- 人生的第一个springboot入门项目
- 01:搭建第一个springboot项目
- SpringBoot学习00-第一个项目
- MyBatis(二)第一个Mybatis项目
- java鬼混笔记:springboot 1、第一个springboot项目例子
- springboot学习(一)认识springboot及创建第一个springboot项目
- 创建第一个SpringBoot
- 第一个springboot
- 第一个SpringBoot工程
- 项目实训涉及的获取数据库数据,导出生成Excel表格(使用Nutz框架)
- ReactNative基础---JSX
- 编写第一个Hibernate应用程序
- 谈谈对架构师的理解
- H5和Node.js快速搭建WebSocket
- 第一个SpringBoot+MyBatis+JSR303项目
- 暑期第二阶段集训总结(附数论总结和计算几何总结)
- HDU 3315 My Brute(二分图最优匹配:优先用原匹配边)
- jenkins+svn+jenkins环境搭建并用到tomcat8
- 设计模式在各编程语言类库及框架上的应用
- 数字游戏
- JVM系列一:JVM内存组成及分配
- 记录开博
- 【Linux学习笔记】3:目录与文件处理命令