Java

Java四舍五入保留1位小数、2位小数

方法一:使用字符串格式化实现四舍五入(支持float和double类型) double data = 3.02; //利用字符串格式化的方式实现四舍五入,保留1位小数 String result = String.format(“%.1f”,data); //1代表小数点后面的位数, 不足补0。f代表数据是浮点类型。保留2位小数就是“%.2f”,依此累推。 System.out.println(r...

service生命周期

//loadOnStartup默认值是-1,0或者正整数,服务器创建时启动serblet对象,数字越小优先级越高 package DemoServlet; import javax.jws.WebService; import javax.servlet.*; import javax.servlet.annotation.WebServlet; import java.io.IOExceptio...

Tomcat插件配置

<plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration>...

多线程

实现一个多线程的方法: 方式一: 创建MyThread类继承thread类 在MyThread类中重写run方法“ 创MyThread类的对象 启动线程 public class MultiThreading { static class MyThread extends Thread{ @Override public void run() { // TODO Auto-generated me...

IO流

读得懂的是字符流,读不懂的是字节流 字节流是万能的流,不知道使用那种流就可以使用字节流 //创建输出流 //FileOutputStream fi = new FileOutputStream(“F:\\SE\\dim.txt”); //创建字节输入流对象 FileInputStream fo = new FileInputStream(“F:\\SE\\dim.txt”); //一次读一个字节 ...

Map集合

Map<k,v>    k: 键 v: 值 Map的键是不能重复的 基本的功能: Map<String, String> map = new HashMap<String,String>(); //添加元素 map.put(“dim”, “001”); map.put(“di2”, “002”); map.put(“di3”, “001”); System.ou...

动态删除

<delete id=”del”> <!–删除一个 DELETE FROM tb_brand where id = #{id};–> DELETE FROM tb_brand where id in <foreach collection=”array” item=”id” separator=”,” open=”(” close=”)”> #{id} &l...

动态条件查询

多条件查询 第一种方法: <select id=”dim” resultType=”DimDyl.Demo05.Dio”> select * from tb_brand where 1 = 1 <if test=”id != null”> and id = #{id} </if> <if test=”Pp_ename != null and Pp_enam...

Mapper代理_多条件查询

<select id=”dim” resultType=”DimDyl.Demo05.Dio”> select * from tb_brand where id = #{id} and Pp_ename like #{Pp_ename} and Qy_ename like #{Qy_ename}; </select> //散装参数 //List<Dio> dim...

Mapper代理_查询详情

//加载mybatis核心文件 String resoures = “mybatis-config.xml”; InputStream resourceAsStream = Resources.getResourceAsStream(resoures); SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(...

Mapper代理开发

//加载mybatis核心文件 String resoures = “mybatis-config.xml”; InputStream resourceAsStream = Resources.getResourceAsStream(resoures); SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(...

MyBatis快速入门

//加载mybatis核心文件,获取SqlSessionFactory String resource = “mybatis-config.xml”; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFacto...

Maven依赖管理

Maven查找包:https://mvnrepository.com/ 多个导入项目只能在一个dependencies中创建,不然会报错 <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version...

Maven基本使用

配置阿里云仓库 //settings.xml <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> <mirrorOf>cen...

druid的使用

//获取连接 String url = “jdbc:mysql:///xuexi”; String user = “root”; String passwd = “123321”; Connection cnt = DriverManager.getConnection(url, user, passwd); //加载配置文件 Properties prop = new Properties();...

druid连接池配置文件(druid.properties)

driverClassName=com.mysql.cj.jdbc.Driver #URL连接数据库的URL,其中travel(以下面例子来说)为连接的数据库,后面的参数可不改但不删 url=jdbc:mysql://localhost:3306/travel?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC ...

preparedStatement防止SQL注入

String url = “jdbc:mysql:///xuexi”; String user = “root”; String passwd = “123321”; Connection connection = DriverManager.getConnection(url, user, passwd); Statement statement = connection.createState...

ResultSet

public static void main(String[] args) throws Exception{ dim(); } public static void dim() throws Exception{ String url = “jdbc:mysql:///xuexi”; String user = “root”; String passwd = “123321”; Connect...

connection&statement

//获取连接 String url = “jdbc:mysql:///xuexi”; String user = “root”; String passwd = “123321”; Connection connection = DriverManager.getConnection(url,user,passwd); Statement statement = connection.create...