项目开发环境准备

📚git使用

🍐 git安装

若右击鼠标出现下图的选项 ,则证明安装成功

在这里插入图片描述

🍐 git环境配置

Git配置

查看配置 git config -lgit config --list

请添加图片描述

设置用户名和邮箱 (必要)

git config --global user.name "marvintian"   
git config --global user.email "601494165@qq.com"

🍐 git基本理论

请添加图片描述
请添加图片描述

🍐 初始化本地库

git init

🍐本地仓库和远程仓库建立连接

git remote add origin 远程仓库地址

📚Eclipse

🍐 Eclipse使用

https://www.cnblogs.com/zz-newbie/p/13305487.html eclipse创建maven项目

https://www.cnblogs.com/zoro-zero/p/11607461.html eclipse创建springboot项目

智能提示设置

https://www.cnblogs.com/dongwenfei/p/8136601.html

Window→Preferences→Java→Editor→Content Assist
请添加图片描述

调整包结构

请添加图片描述

自动导包

请添加图片描述

🍎 HelloWord

🍍 方式一:使用maven手动创建

参考文档 https://www.cnblogs.com/LUA123/p/8110285.html

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.2.RELEASE</version>
  </parent>
  
  <groupId>com.marvin</groupId>
  <artifactId>test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
  
  
</project>
@SpringBootApplication
public class SpringBootTestApplication {
	public static void main(String[] args) {
		SpringApplication.run(SpringBootTestApplication.class,args);		
	}

}
@RestController
public class HellowController {
	@GetMapping("hello")
	public String   hello() {
		return "hello world";
	}
}

在浏览器访问http://localhost:8080/hello

请添加图片描述

🍍 方式二:使用插件创建

安装插件

请添加图片描述

搜索下面的插件
请添加图片描述

请添加图片描述

插件安装完成,重启

在newproject中看到下图,说明安装成功
请添加图片描述

点击Spring Starter Project

请添加图片描述
请添加图片描述

🍎 Git使用

🍍提交代码

请添加图片描述

?代表未提交

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

🍍拉取项目

请添加图片描述

🍍冲突解决

当修改了同一个class后,我们将自己修改的commit到自己本地仓库,在推到远程时先拉取远程最新的代码
请添加图片描述
若远程和本地有冲突,那么拉取是不成功的,并且代码有如下显示
请添加图片描述
项目图标也会变化,有标识的代表是有冲突的类
请添加图片描述
此时我们选择它,来为我们展示冲突并进行解决
请添加图片描述
会弹出如下界面,供我们选择到底要保留什么
请添加图片描述
把左边修改成我们最后要保留的样子并保存 保存完后要将这个弹框关掉,不然下次冲突后他依旧会在,并且误导你
若想要保留右边的东西,就把它粘贴过来,左边的东西不想要就删除掉
保存后,class上的>>>>>>标志就会消失,再将我们最后保留的样子进行commit
请添加图片描述
请添加图片描述
至此我们的冲突就解决完成了

🍎 Maven

很多IDE会自带maven,建议大家自行安装maven使用,不要使用自带的

🍍配置远程地址​

在maven的安装目录下,我们找到 conf 下的 settings.xml,下图就是配置远程地址的位置

请添加图片描述

🍍配置本地仓库

默认使用的是 C盘 .m2下的
请添加图片描述

🍍Eclipse使用

请添加图片描述
请添加图片描述

mvn的命令
请添加图片描述

🍐Eclipse常见设置

🍎设置workspace编码格式为UTF-8

window->preferences->general->workspace

请添加图片描述

🍎 formatter设置

在代码进行格式化时,会将代码注释也格式化
请添加图片描述
请添加图片描述
请添加图片描述

🍎Code Templates设置

设置Code Templates的目的主要是为了统一各种注释的格式以及代码的模板

请添加图片描述

<?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="false" context="gettercomment_context" deleted="false" description="Comment for getter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name="gettercomment">
/**  
  * ${bare_field_name}.  
  *  
  * @return  the ${bare_field_name}  
  * @since   JDK 1.6  
  */</template><template autoinsert="false" context="settercomment_context" deleted="false" description="Comment for setter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.settercomment" name="settercomment">
/**  
  * ${param}.  
  *  
  * @param   ${param}    the ${bare_field_name} to set  
  * @since   JDK 1.6  
  */</template><template autoinsert="false" context="constructorcomment_context" deleted="false" description="Comment for created constructors" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name="constructorcomment">
/**  
  * Creates a new instance of ${enclosing_type}.  
  *  
  * ${tags}  
  */  
 </template><template autoinsert="false" context="filecomment_context" deleted="false" description="Comment for created Java files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.filecomment" name="filecomment">
/**  
  * Project Name:${project_name}  
  * File Name:${file_name}   
  * Package Name:${package_name}  
  * Date:${date}${time}  
  * Copyright (c) ${year}, chenzhou1025@126.com All Rights Reserved.  
  *  
  */</template><template autoinsert="false" context="typecomment_context" deleted="false" description="Comment for created types" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.typecomment" name="typecomment">
/**  
  * ClassName: ${type_name} &lt;br/&gt;  
  * Function: ${todo} ADD FUNCTION. &lt;br/&gt;  
  * Reason: ${todo} ADD REASON(可选). &lt;br/&gt;  
  * date: ${date} ${time} &lt;br/&gt;  
  *  
  * @author ${user}  
  * @version ${enclosing_type}${tags}  
  * @since JDK 1.6  
  */</template><template autoinsert="false" context="fieldcomment_context" deleted="false" description="Comment for fields" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name="fieldcomment">
/**  
  * ${field}:${todo}(用一句话描述这个变量表示什么).  
  * @since JDK 1.6  
  */</template><template autoinsert="false" context="methodcomment_context" deleted="false" description="Comment for non-overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name="methodcomment">
/**  
  * ${enclosing_method}:(这里用一句话描述这个方法的作用). &lt;br/&gt;  
  * ${todo}(这里描述这个方法适用条件 – 可选).&lt;br/&gt;  
  * ${todo}(这里描述这个方法的执行流程 – 可选).&lt;br/&gt;  
  * ${todo}(这里描述这个方法的使用方法 – 可选).&lt;br/&gt;  
  * ${todo}(这里描述这个方法的注意事项 – 可选).&lt;br/&gt;  
  *  
  * @author ${user}  
  * ${tags}  
  * @since JDK 1.6  
  */</template><template autoinsert="false" context="overridecomment_context" deleted="false" description="Comment for overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name="overridecomment">
/**  
  * ${todo} 简单描述该方法的实现功能(可选).  
  * ${see_to_overridden}  
  */</template><template autoinsert="true" context="delegatecomment_context" deleted="false" description="Comment for delegate methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name="delegatecomment">
/**  
  * ${tags}  
  * ${see_to_target}  
  */</template><template autoinsert="false" context="newtype_context" deleted="false" description="Newly created files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.newtype" name="newtype">
/**  
  * Project Name:${project_name}  
  * File Name:${file_name}  
  * Package Name:${package_name}  
  * Date:${date}${time}  
  * Copyright (c) ${year}, chenzhou1025@126.com All Rights Reserved.  
  *  
  */  
${filecomment}  
      
${package_declaration}  
/**  
  * ClassName:${type_name} &lt;br/&gt;  
  * Function: ${todo} ADD FUNCTION. &lt;br/&gt;  
  * Reason:   ${todo} ADD REASON. &lt;br/&gt;  
  * Date:     ${date} ${time} &lt;br/&gt;  
  * @author   ${user}  
  * @version    
  * @since    JDK 1.6  
  * @see        
  */  
${typecomment}  
${type_declaration}  
</template><template autoinsert="true" context="classbody_context" deleted="false" description="Code in new class type bodies" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.classbody" name="classbody">  
    </template><template autoinsert="true" context="interfacebody_context" deleted="false" description="Code in new interface type bodies" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name="interfacebody">  
    </template><template autoinsert="true" context="enumbody_context" deleted="false" description="Code in new enum type bodies" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.enumbody" name="enumbody">  
    </template><template autoinsert="true" context="annotationbody_context" deleted="false" description="Code in new annotation type bodies" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name="annotationbody">  
    </template><template autoinsert="true" context="catchblock_context" deleted="false" description="Code in new catch blocks" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.catchblock" name="catchblock">  
    // ${todo} Auto-generated catch block  
    ${exception_var}.printStackTrace();  
    </template><template autoinsert="false" context="methodbody_context" deleted="false" description="Code in created method stubs" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.methodbody" name="methodbody">  
    // ${todo} Auto-generated method stub  
    ${body_statement}</template><template autoinsert="true" context="constructorbody_context" deleted="false" description="Code in created constructor stubs" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name="constructorbody">  
    ${body_statement}  
    // ${todo} Auto-generated constructor stub  
    </template><template autoinsert="true" context="getterbody_context" deleted="false" description="Code in created getters" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.getterbody" name="getterbody">return ${field};</template><template autoinsert="true" context="setterbody_context" deleted="false" description="Code in created setters" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.setterbody" name="setterbody">${field} = ${param};</template></templates>  

🍐 快捷键

代码助手:Ctrl+Space(简体中文操作系统是Alt+/)
快速修正:Ctrl+1
单词补全:Alt+/
打开外部Java文档:Shift+F2

显示搜索对话框:Ctrl+H
快速Outline:Ctrl+O
打开资源:Ctrl+Shift+R
打开类型:Ctrl+Shift+T
显示重构菜单:Alt+Shift+T

上一个/下一个光标的位置:Alt+Left/Right
上一个/下一个成员(成员对象或成员函数):Ctrl+Shift+Up/Down
选中闭合元素:Alt+Shift+Up/Down/Left/Right
删除行:Ctrl+D
在当前行上插入一行:Ctrl+Shift+Enter
在当前行下插入一行: Shift+Enter
上下移动选中的行:Alt+Up/Down

📚 SpringData

🍧 入门案例

🥝创建项目

​ 使用SpringBoot插件,或创建Maven项目均可

🥝依赖

基于SpringBoot创建

<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<scope>runtime</scope>
		</dependency>

        
        <!--Spring Data-->
       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
       </dependency>
        
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
</dependencies>

🥝 创建POJO

@Entity
@Table(name = "product")
public class Product {
	@Id
	private Long id;
	@Column(name = "productName")
	private String productName;
	@Column(name = "dir_id")
	private Long dirId;
	@Column(name = "salePrice")
	private BigDecimal salePrice;
	@Column(name = "supplier")
	private String supplier;
	@Column(name = "brand")
	private String brand;
	@Column(name = "cutoff")
	private Double cutoff;
	@Column(name = "costPrice")
	private BigDecimal costPrice;
    
    //get  set  构造器
}

🥝创建持久层

@Repository
public interface ProductJPA extends JpaRepository<Product, Long> {

}

🥝创建控制层

@RestController
@RequestMapping("product")
public class ProductController {
	@Autowired
	private ProductJPA productJPA;

	@GetMapping("list")
	public List<Product> getList() {
		return productJPA.findAll();
	}
}

🥝配置文件

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql:///jdbcdemo
    username: root
    password: admin
  
  jpa:
    show-sql: true
    hibernate:
      naming:   #驼峰命名不会自动转化  需配置该项
        physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

运行效果

请添加图片描述
请添加图片描述

image-20211212183741270

🍨 Repsitory接口

在上述案例中,我们除了可以使用JpaRepository接口外还可以使用Repository接口和CrudRepository接口

​ Repostory接口只支持查询语句 有两种查询方式

🌱Repository基于方法名称命名规则查询

public interface UserDaoRepository extends Repository<Users,Integer> {
    
    //IS 就是SQL中的is
    List<Users> findByUserNameIs(String string);
    //Like
    List<Users> findByUserNameLike(String username);
    //多条件
    List<Users> findByUserNameAndRealNameIs(String name , String realName);

}

测试代码

public void query1(){
    
    List<Users> list = this.dao.findByUserNameIs( string: "Tom");
    for (Users users : list) {
        system.out.println(users);
    }
}

public void query2(){
    List<Users> list = this.dao.findByUserNameLike(" Tom");
    for (Users users : list) {
        System.out.println(users);
    } 
}
public void query3(){
    List<Users> list = this.dao.findByUserNameAndRealNameIs( name:"Tom" ,realName:"张三丰");
        for (Users users : list) {
           system.out.println(users); 
        }
}

🌱 基于@Query查询

🍇 JPQL语句

@Query(value = " from Users where userName =?")
List<Users> queryUsersByNameUseJPQL(String name);

@Query(value = " from Users where userName like_?")
List<Users> queryUserLikeNameUseJPQL(String name);

@Query(value = " from Users where userName= ? and realName =?")
List<Users> queryUserByNameAndRealName(String userName ,String realName);

🍇SQL语句

//在使用@Query注解查询SQL语句的时候 nativeQuery默认是false,我们需要设置为true
@Query(value = "select * from t_user where user_name=? " , nativeQuery = true)
List<Users> queryUsersByNameUsesQL(String name);

@Query(value = "select * from t_user where user_name like ?" ,nativeQuery = true)
List<Users> queryUserLikeNameUsesQL(String name);

@Query(value = " from Users where userName= ? and realName = ?")
List<Users> queryUserByNameAndReaLName(String userName , string realName);

若要强行进行DML操作,那么需要加上 @Modifying 注解

🍨 CrudRepository

该接口继承于Repository接口,且又扩展了CRUD的相关操作

public interface UserDaoCrudRepository extends CrudRepository<Users,Integer>{
    
}
//添加
@Test
public void test1(){
   Users user = new Users();
   user.setRealName("成龙");
   user.setUserName ("chengnong");
   //接口中的方法,直接调用即可 
   dao.save(user);
}
//查询
public void test2(){
   User user =dao.findOne(25);
   
}
//查询多条
public void test3(){
   Iterable<Users> list = dao.findAll();
   Iterator<Users> iterator = list.iterator();
    while(iterator.hasNext()){
        Users user = iterator.next();
        System.out.println(user);
    }
}

🍨pageAndSorting

分页和排序的相关操作

请添加图片描述

🍰 JpaRepository

其中的方法
请添加图片描述

🍰JpaSpecificcation

JpaSpecificcationExecutor 可以实现带条件的分页和排序

请添加图片描述
案例:查询id大于5的记录
请添加图片描述

关联查询

https://zhuanlan.zhihu.com/p/108016975

JHipster

https://www.cnblogs.com/demingblog/p/13805484.html

📚 前后端分离

🎻前后分分离和不分离在代码方面的区别

🎻在业务上的区别 SEO

🎻@RestController

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值